9.25. 系統資訊函數
Table 9.63 shows several functions that extract session and system information.
In addition to the functions listed in this section, there are a number of functions related to the statistics system that also provide system information. See Section 27.2.2 for more information.
Table 9.63. Session Information Functions
Name | Return Type | Description |
|
| name of current database (called “catalog” in the SQL standard) |
|
| name of current database |
|
| text of the currently executing query, as submitted by the client (might contain more than one statement) |
|
| equivalent to |
|
| name of current schema |
|
| names of schemas in search path, optionally including implicit schemas |
|
| user name of current execution context |
|
| address of the remote connection |
|
| port of the remote connection |
|
| address of the local connection |
|
| port of the local connection |
|
| Process ID of the server process attached to the current session |
|
| Process ID(s) that are blocking specified server process ID from acquiring a lock |
|
| configuration load time |
|
| Primary log file name, or log in the requested format, currently in use by the logging collector |
|
| OID of session's temporary schema, or 0 if none |
|
| is schema another session's temporary schema? |
|
| is a JIT compiler extension available (see Chapter 31) and the jit configuration parameter set to |
|
| channel names that the session is currently listening on |
|
| fraction of the asynchronous notification queue currently occupied (0-1) |
|
| server start time |
|
| Process ID(s) that are blocking specified server process ID from acquiring a safe snapshot |
|
| current nesting level of PostgreSQL triggers (0 if not called, directly or indirectly, from inside a trigger) |
|
| session user name |
|
| equivalent to |
|
| PostgreSQL version information. See also server_version_num for a machine-readable version. |
Note
current_catalog
, current_role
, current_schema
, current_user
, session_user
, and user
have special syntactic status in SQL: they must be called without trailing parentheses. (In PostgreSQL, parentheses can optionally be used with current_schema
, but not with the others.)
The session_user
is normally the user who initiated the current database connection; but superusers can change this setting with SET SESSION AUTHORIZATION. The current_user
is the user identifier that is applicable for permission checking. Normally it is equal to the session user, but it can be changed with SET ROLE. It also changes during the execution of functions with the attribute SECURITY DEFINER
. In Unix parlance, the session user is the “real user” and the current user is the “effective user”. current_role
and user
are synonyms for current_user
. (The SQL standard draws a distinction between current_role
and current_user
, but PostgreSQL does not, since it unifies users and roles into a single kind of entity.)
current_schema
returns the name of the schema that is first in the search path (or a null value if the search path is empty). This is the schema that will be used for any tables or other named objects that are created without specifying a target schema. current_schemas(boolean)
returns an array of the names of all schemas presently in the search path. The Boolean option determines whether or not implicitly included system schemas such as pg_catalog
are included in the returned search path.
Note
The search path can be altered at run time. The command is:
inet_client_addr
returns the IP address of the current client, and inet_client_port
returns the port number. inet_server_addr
returns the IP address on which the server accepted the current connection, and inet_server_port
returns the port number. All these functions return NULL if the current connection is via a Unix-domain socket.
pg_blocking_pids
returns an array of the process IDs of the sessions that are blocking the server process with the specified process ID, or an empty array if there is no such server process or it is not blocked. One server process blocks another if it either holds a lock that conflicts with the blocked process's lock request (hard block), or is waiting for a lock that would conflict with the blocked process's lock request and is ahead of it in the wait queue (soft block). When using parallel queries the result always lists client-visible process IDs (that is, pg_backend_pid
results) even if the actual lock is held or awaited by a child worker process. As a result of that, there may be duplicated PIDs in the result. Also note that when a prepared transaction holds a conflicting lock, it will be represented by a zero process ID in the result of this function. Frequent calls to this function could have some impact on database performance, because it needs exclusive access to the lock manager's shared state for a short time.
pg_conf_load_time
returns the timestamp with time zone
when the server configuration files were last loaded. (If the current session was alive at the time, this will be the time when the session itself re-read the configuration files, so the reading will vary a little in different sessions. Otherwise it is the time when the postmaster process re-read the configuration files.)
pg_current_logfile
returns, as text
, the path of the log file(s) currently in use by the logging collector. The path includes the log_directory directory and the log file name. Log collection must be enabled or the return value is NULL
. When multiple log files exist, each in a different format, pg_current_logfile
called without arguments returns the path of the file having the first format found in the ordered list: stderr, csvlog. NULL
is returned when no log file has any of these formats. To request a specific file format supply, as text
, either csvlog or stderr as the value of the optional parameter. The return value is NULL
when the log format requested is not a configured log_destination. The pg_current_logfile
reflects the contents of the current_logfiles
file.
pg_my_temp_schema
returns the OID of the current session's temporary schema, or zero if it has none (because it has not created any temporary tables). pg_is_other_temp_schema
returns true if the given OID is the OID of another session's temporary schema. (This can be useful, for example, to exclude other sessions' temporary tables from a catalog display.)
pg_listening_channels
returns a set of names of asynchronous notification channels that the current session is listening to. pg_notification_queue_usage
returns the fraction of the total available space for notifications currently occupied by notifications that are waiting to be processed, as a double
in the range 0-1. See LISTEN and NOTIFY for more information.
pg_postmaster_start_time
returns the timestamp with time zone
when the server started.
pg_safe_snapshot_blocking_pids
returns an array of the process IDs of the sessions that are blocking the server process with the specified process ID from acquiring a safe snapshot, or an empty array if there is no such server process or it is not blocked. A session running a SERIALIZABLE
transaction blocks a SERIALIZABLE READ ONLY DEFERRABLE
transaction from acquiring a snapshot until the latter determines that it is safe to avoid taking any predicate locks. See Section 13.2.3 for more information about serializable and deferrable transactions. Frequent calls to this function could have some impact on database performance, because it needs access to the predicate lock manager's shared state for a short time.
version
returns a string describing the PostgreSQL server's version. You can also get this information from server_version or for a machine-readable version, server_version_num. Software developers should use server_version_num
(available since 8.2) or PQserverVersion
instead of parsing the text version.
Table 9.64 lists functions that allow the user to query object access privileges programmatically. See Section 5.7 for more information about privileges.
Table 9.64. Access Privilege Inquiry Functions
Name | Return Type | Description |
|
| does user have privilege for any column of table |
|
| does current user have privilege for any column of table |
|
| does user have privilege for column |
|
| does current user have privilege for column |
|
| does user have privilege for database |
|
| does current user have privilege for database |
|
| does user have privilege for foreign-data wrapper |
|
| does current user have privilege for foreign-data wrapper |
|
| does user have privilege for function |
|
| does current user have privilege for function |
|
| does user have privilege for language |
|
| does current user have privilege for language |
|
| does user have privilege for schema |
|
| does current user have privilege for schema |
|
| does user have privilege for sequence |
|
| does current user have privilege for sequence |
|
| does user have privilege for foreign server |
|
| does current user have privilege for foreign server |
|
| does user have privilege for table |
|
| does current user have privilege for table |
|
| does user have privilege for tablespace |
|
| does current user have privilege for tablespace |
|
| does user have privilege for type |
|
| does current user have privilege for type |
|
| does user have privilege for role |
|
| does current user have privilege for role |
|
| does current user have row level security active for table |
has_table_privilege
checks whether a user can access a table in a particular way. The user can be specified by name, by OID (pg_authid.oid
), public
to indicate the PUBLIC pseudo-role, or if the argument is omitted current_user
is assumed. The table can be specified by name or by OID. (Thus, there are actually six variants of has_table_privilege
, which can be distinguished by the number and types of their arguments.) When specifying by name, the name can be schema-qualified if necessary. The desired access privilege type is specified by a text string, which must evaluate to one of the values SELECT
, INSERT
, UPDATE
, DELETE
, TRUNCATE
, REFERENCES
, or TRIGGER
. Optionally, WITH GRANT OPTION
can be added to a privilege type to test whether the privilege is held with grant option. Also, multiple privilege types can be listed separated by commas, in which case the result will be true
if any of the listed privileges is held. (Case of the privilege string is not significant, and extra whitespace is allowed between but not within privilege names.) Some examples:
has_sequence_privilege
checks whether a user can access a sequence in a particular way. The possibilities for its arguments are analogous to has_table_privilege
. The desired access privilege type must evaluate to one of USAGE
, SELECT
, or UPDATE
.
has_any_column_privilege
checks whether a user can access any column of a table in a particular way. Its argument possibilities are analogous to has_table_privilege
, except that the desired access privilege type must evaluate to some combination of SELECT
, INSERT
, UPDATE
, or REFERENCES
. Note that having any of these privileges at the table level implicitly grants it for each column of the table, so has_any_column_privilege
will always return true
if has_table_privilege
does for the same arguments. But has_any_column_privilege
also succeeds if there is a column-level grant of the privilege for at least one column.
has_column_privilege
checks whether a user can access a column in a particular way. Its argument possibilities are analogous to has_table_privilege
, with the addition that the column can be specified either by name or attribute number. The desired access privilege type must evaluate to some combination of SELECT
, INSERT
, UPDATE
, or REFERENCES
. Note that having any of these privileges at the table level implicitly grants it for each column of the table.
has_database_privilege
checks whether a user can access a database in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to some combination of CREATE
, CONNECT
, TEMPORARY
, or TEMP
(which is equivalent to TEMPORARY
).
has_function_privilege
checks whether a user can access a function in a particular way. Its argument possibilities are analogous to has_table_privilege
. When specifying a function by a text string rather than by OID, the allowed input is the same as for the regprocedure
data type (see Section 8.19). The desired access privilege type must evaluate to EXECUTE
. An example is:
has_foreign_data_wrapper_privilege
checks whether a user can access a foreign-data wrapper in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to USAGE
.
has_language_privilege
checks whether a user can access a procedural language in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to USAGE
.
has_schema_privilege
checks whether a user can access a schema in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to some combination of CREATE
or USAGE
.
has_server_privilege
checks whether a user can access a foreign server in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to USAGE
.
has_tablespace_privilege
checks whether a user can access a tablespace in a particular way. Its argument possibilities are analogous to has_table_privilege
. The desired access privilege type must evaluate to CREATE
.
has_type_privilege
checks whether a user can access a type in a particular way. Its argument possibilities are analogous to has_table_privilege
. When specifying a type by a text string rather than by OID, the allowed input is the same as for the regtype
data type (see Section 8.19). The desired access privilege type must evaluate to USAGE
.
pg_has_role
checks whether a user can access a role in a particular way. Its argument possibilities are analogous to has_table_privilege
, except that public
is not allowed as a user name. The desired access privilege type must evaluate to some combination of MEMBER
or USAGE
. MEMBER
denotes direct or indirect membership in the role (that is, the right to do SET ROLE
), while USAGE
denotes whether the privileges of the role are immediately available without doing SET ROLE
.
row_security_active
checks whether row level security is active for the specified table in the context of the current_user
and environment. The table can be specified by name or by OID.
Table 9.65 shows the operators available for the aclitem
type, which is the catalog representation of access privileges. See Section 5.7 for information about how to read access privilege values.
Table 9.65. aclitem
Operators
aclitem
OperatorsOperator | Description | Example | Result |
| equal |
|
|
| contains element |
|
|
| contains element |
|
|
Table 9.66 shows some additional functions to manage the aclitem
type.
Table 9.66. aclitem
Functions
aclitem
FunctionsName | Return Type | Description |
|
| get the default access privileges for an object belonging to |
|
| get |
|
| build an |
acldefault
returns the built-in default access privileges for an object of type type
belonging to role ownerId
. These represent the access privileges that will be assumed when an object's ACL entry is null. (The default access privileges are described in Section 5.7.) The type
parameter is a CHAR
: write 'c' for COLUMN
, 'r' for TABLE
and table-like objects, 's' for SEQUENCE
, 'd' for DATABASE
, 'f' for FUNCTION
or PROCEDURE
, 'l' for LANGUAGE
, 'L' for LARGE OBJECT
, 'n' for SCHEMA
, 't' for TABLESPACE
, 'F' for FOREIGN DATA WRAPPER
, 'S' for FOREIGN SERVER
, or 'T' for TYPE
or DOMAIN
.
aclexplode
returns an aclitem
array as a set of rows. Output columns are grantor oid
, grantee oid
(0
for PUBLIC
), granted privilege as text
(SELECT
, ...) and whether the privilege is grantable as boolean
. makeaclitem
performs the inverse operation.
Table 9.67 shows functions that determine whether a certain object is visible in the current schema search path. For example, a table is said to be visible if its containing schema is in the search path and no table of the same name appears earlier in the search path. This is equivalent to the statement that the table can be referenced by name without explicit schema qualification. To list the names of all visible tables:
Table 9.67. Schema Visibility Inquiry Functions
Name | Return Type | Description |
|
| is collation visible in search path |
|
| is conversion visible in search path |
|
| is function visible in search path |
|
| is operator class visible in search path |
|
| is operator visible in search path |
|
| is operator family visible in search path |
|
| is statistics object visible in search path |
|
| is table visible in search path |
|
| is text search configuration visible in search path |
|
| is text search dictionary visible in search path |
|
| is text search parser visible in search path |
|
| is text search template visible in search path |
|
| is type (or domain) visible in search path |
Each function performs the visibility check for one type of database object. Note that pg_table_is_visible
can also be used with views, materialized views, indexes, sequences and foreign tables; pg_function_is_visible
can also be used with procedures and aggregates; pg_type_is_visible
can also be used with domains. For functions and operators, an object in the search path is visible if there is no object of the same name and argument data type(s) earlier in the path. For operator classes, both name and associated index access method are considered.
All these functions require object OIDs to identify the object to be checked. If you want to test an object by name, it is convenient to use the OID alias types (regclass
, regtype
, regprocedure
, regoperator
, regconfig
, or regdictionary
), for example:
Note that it would not make much sense to test a non-schema-qualified type name in this way — if the name can be recognized at all, it must be visible.
Table 9.68 lists functions that extract information from the system catalogs.
Table 9.68. System Catalog Information Functions
Name | Return Type | Description |
|
| get SQL name of a data type |
|
| get definition of a constraint |
|
| get definition of a constraint |
|
| decompile internal form of an expression, assuming that any Vars in it refer to the relation indicated by the second parameter |
|
| decompile internal form of an expression, assuming that any Vars in it refer to the relation indicated by the second parameter |
|
| get definition of a function or procedure |
|
| get argument list of function's or procedure's definition (with default values) |
|
| get argument list to identify a function or procedure (without default values) |
|
| get |
|
| get |
|
| get |
|
| get list of SQL keywords and their categories |
|
| get |
|
| get |
|
| get name of the sequence that a serial or identity column uses |
|
| get |
|
| get |
|
| get |
|
| get role name with given OID |
|
| get underlying |
|
| get underlying |
|
| get underlying |
|
| get underlying |
|
| get underlying |
|
| test whether an index column has a specified property |
|
| test whether an index has a specified property |
|
| test whether an index access method has a specified property |
|
| get the set of storage option name/value pairs |
|
| get the set of database OIDs that have objects in the tablespace |
|
| get the path in the file system that this tablespace is located in |
|
| get the data type of any value |
|
| get the collation of the argument |
|
| get the OID of the named relation |
|
| get the OID of the named function |
|
| get the OID of the named function |
|
| get the OID of the named operator |
|
| get the OID of the named operator |
|
| get the OID of the named type |
|
| get the OID of the named schema |
|
| get the OID of the named role |
format_type
returns the SQL name of a data type that is identified by its type OID and possibly a type modifier. Pass NULL for the type modifier if no specific modifier is known.
pg_get_keywords
returns a set of records describing the SQL keywords recognized by the server. The word
column contains the keyword. The catcode
column contains a category code: U
for unreserved, C
for column name, T
for type or function name, or R
for reserved. The catdesc
column contains a possibly-localized string describing the category.
pg_get_constraintdef
, pg_get_indexdef
, pg_get_ruledef
, pg_get_statisticsobjdef
, and pg_get_triggerdef
, respectively reconstruct the creating command for a constraint, index, rule, extended statistics object, or trigger. (Note that this is a decompiled reconstruction, not the original text of the command.) pg_get_expr
decompiles the internal form of an individual expression, such as the default value for a column. It can be useful when examining the contents of system catalogs. If the expression might contain Vars, specify the OID of the relation they refer to as the second parameter; if no Vars are expected, zero is sufficient. pg_get_viewdef
reconstructs the SELECT
query that defines a view. Most of these functions come in two variants, one of which can optionally “pretty-print” the result. The pretty-printed format is more readable, but the default format is more likely to be interpreted the same way by future versions of PostgreSQL; avoid using pretty-printed output for dump purposes. Passing false
for the pretty-print parameter yields the same result as the variant that does not have the parameter at all.
pg_get_functiondef
returns a complete CREATE OR REPLACE FUNCTION
statement for a function. pg_get_function_arguments
returns the argument list of a function, in the form it would need to appear in within CREATE FUNCTION
. pg_get_function_result
similarly returns the appropriate RETURNS
clause for the function. pg_get_function_identity_arguments
returns the argument list necessary to identify a function, in the form it would need to appear in within ALTER FUNCTION
, for instance. This form omits default values.
pg_get_serial_sequence
returns the name of the sequence associated with a column, or NULL if no sequence is associated with the column. If the column is an identity column, the associated sequence is the sequence internally created for the identity column. For columns created using one of the serial types (serial
, smallserial
, bigserial
), it is the sequence created for that serial column definition. In the latter case, this association can be modified or removed with ALTER SEQUENCE OWNED BY
. (The function probably should have been called pg_get_owned_sequence
; its current name reflects the fact that it has typically been used with serial
or bigserial
columns.) The first input parameter is a table name with optional schema, and the second parameter is a column name. Because the first parameter is potentially a schema and table, it is not treated as a double-quoted identifier, meaning it is lower cased by default, while the second parameter, being just a column name, is treated as double-quoted and has its case preserved. The function returns a value suitably formatted for passing to sequence functions (see Section 9.16). A typical use is in reading the current value of a sequence for an identity or serial column, for example:
pg_get_userbyid
extracts a role's name given its OID.
pg_index_column_has_property
, pg_index_has_property
, and pg_indexam_has_property
return whether the specified index column, index, or index access method possesses the named property. NULL
is returned if the property name is not known or does not apply to the particular object, or if the OID or column number does not identify a valid object. Refer to Table 9.69 for column properties, Table 9.70 for index properties, and Table 9.71 for access method properties. (Note that extension access methods can define additional property names for their indexes.)
Table 9.69. Index Column Properties
Name | Description |
| Does the column sort in ascending order on a forward scan? |
| Does the column sort in descending order on a forward scan? |
| Does the column sort with nulls first on a forward scan? |
| Does the column sort with nulls last on a forward scan? |
| Does the column possess any defined sort ordering? |
| Can the column be scanned in order by a “distance” operator, for example |
| Can the column value be returned by an index-only scan? |
| Does the column natively support |
| Does the column support |
Table 9.70. Index Properties
Name | Description |
| Can the index be used in a |
| Does the index support plain (non-bitmap) scans? |
| Does the index support bitmap scans? |
| Can the scan direction be changed in mid-scan (to support |
Table 9.71. Index Access Method Properties
Name | Description |
| Does the access method support |
| Does the access method support unique indexes? |
| Does the access method support indexes with multiple columns? |
| Does the access method support exclusion constraints? |
| Does the access method support the |
pg_options_to_table
returns the set of storage option name/value pairs (option_name
/option_value
) when passed pg_class
.reloptions
or pg_attribute
.attoptions
.
pg_tablespace_databases
allows a tablespace to be examined. It returns the set of OIDs of databases that have objects stored in the tablespace. If this function returns any rows, the tablespace is not empty and cannot be dropped. To display the specific objects populating the tablespace, you will need to connect to the databases identified by pg_tablespace_databases
and query their pg_class
catalogs.
pg_typeof
returns the OID of the data type of the value that is passed to it. This can be helpful for troubleshooting or dynamically constructing SQL queries. The function is declared as returning regtype
, which is an OID alias type (see Section 8.19); this means that it is the same as an OID for comparison purposes but displays as a type name. For example:
The expression collation for
returns the collation of the value that is passed to it. Example:
The value might be quoted and schema-qualified. If no collation is derived for the argument expression, then a null value is returned. If the argument is not of a collatable data type, then an error is raised.
The to_regclass
, to_regproc
, to_regprocedure
, to_regoper
, to_regoperator
, to_regtype
, to_regnamespace
, and to_regrole
functions translate relation, function, operator, type, schema, and role names (given as text
) to objects of type regclass
, regproc
, regprocedure
, regoper
, regoperator
, regtype
, regnamespace
, and regrole
respectively. These functions differ from a cast from text in that they don't accept a numeric OID, and that they return null rather than throwing an error if the name is not found (or, for to_regproc
and to_regoper
, if the given name matches multiple objects).
Table 9.72 lists functions related to database object identification and addressing.
Table 9.72. Object Information and Addressing Functions
Name | Return Type | Description |
|
| get description of a database object |
|
| get identity of a database object |
|
| get external representation of a database object's address |
|
| get address of a database object from its external representation |
pg_describe_object
returns a textual description of a database object specified by catalog OID, object OID, and sub-object ID (such as a column number within a table; the sub-object ID is zero when referring to a whole object). This description is intended to be human-readable, and might be translated, depending on server configuration. This is useful to determine the identity of an object as stored in the pg_depend
catalog.
pg_identify_object
returns a row containing enough information to uniquely identify the database object specified by catalog OID, object OID and sub-object ID. This information is intended to be machine-readable, and is never translated. type
identifies the type of database object; schema
is the schema name that the object belongs in, or NULL
for object types that do not belong to schemas; name
is the name of the object, quoted if necessary, if the name (along with schema name, if pertinent) is sufficient to uniquely identify the object, otherwise NULL
; identity
is the complete object identity, with the precise format depending on object type, and each name within the format being schema-qualified and quoted as necessary.
pg_identify_object_as_address
returns a row containing enough information to uniquely identify the database object specified by catalog OID, object OID and sub-object ID. The returned information is independent of the current server, that is, it could be used to identify an identically named object in another server. type
identifies the type of database object; object_names
and object_args
are text arrays that together form a reference to the object. These three values can be passed to pg_get_object_address
to obtain the internal address of the object. This function is the inverse of pg_get_object_address
.
pg_get_object_address
returns a row containing enough information to uniquely identify the database object specified by its type and object name and argument arrays. The returned values are the ones that would be used in system catalogs such as pg_depend
and can be passed to other system functions such as pg_identify_object
or pg_describe_object
. classid
is the OID of the system catalog containing the object; objid
is the OID of the object itself, and objsubid
is the sub-object ID, or zero if none. This function is the inverse of pg_identify_object_as_address
.
The functions shown in Table 9.73 extract comments previously stored with the COMMENT command. A null value is returned if no comment could be found for the specified parameters.
Table 9.73. Comment Information Functions
Name | Return Type | Description |
|
| get comment for a table column |
|
| get comment for a database object |
|
| get comment for a database object (deprecated) |
|
| get comment for a shared database object |
col_description
returns the comment for a table column, which is specified by the OID of its table and its column number. (obj_description
cannot be used for table columns since columns do not have OIDs of their own.)
The two-parameter form of obj_description
returns the comment for a database object specified by its OID and the name of the containing system catalog. For example, obj_description(123456,'pg_class')
would retrieve the comment for the table with OID 123456. The one-parameter form of obj_description
requires only the object OID. It is deprecated since there is no guarantee that OIDs are unique across different system catalogs; therefore, the wrong comment might be returned.
shobj_description
is used just like obj_description
except it is used for retrieving comments on shared objects. Some system catalogs are global to all databases within each cluster, and the descriptions for objects in them are stored globally as well.
The functions shown in Table 9.74 provide server transaction information in an exportable form. The main use of these functions is to determine which transactions were committed between two snapshots.
Table 9.74. Transaction IDs and Snapshots
Name | Return Type | Description |
|
| get current transaction ID, assigning a new one if the current transaction does not have one |
|
| same as |
|
| get current snapshot |
|
| get in-progress transaction IDs in snapshot |
|
| get |
|
| get |
|
| is transaction ID visible in snapshot? (do not use with subtransaction ids) |
|
| report the status of the given transaction: |
The internal transaction ID type (xid
) is 32 bits wide and wraps around every 4 billion transactions. However, these functions export a 64-bit format that is extended with an “epoch” counter so it will not wrap around during the life of an installation. The data type used by these functions, txid_snapshot
, stores information about transaction ID visibility at a particular moment in time. Its components are described in Table 9.75.
Table 9.75. Snapshot Components
Name | Description |
| Earliest transaction ID (txid) that is still active. All earlier transactions will either be committed and visible, or rolled back and dead. |
| First as-yet-unassigned txid. All txids greater than or equal to this are not yet started as of the time of the snapshot, and thus invisible. |
| Active txids at the time of the snapshot. The list includes only those active txids between |
txid_snapshot
's textual representation is xmin
:xmax
:xip_list
. For example 10:20:10,14,15
means xmin=10, xmax=20, xip_list=10, 14, 15
.
txid_status(bigint)
reports the commit status of a recent transaction. Applications may use it to determine whether a transaction committed or aborted when the application and database server become disconnected while a COMMIT
is in progress. The status of a transaction will be reported as either in progress
, committed
, or aborted
, provided that the transaction is recent enough that the system retains the commit status of that transaction. If is old enough that no references to that transaction survive in the system and the commit status information has been discarded, this function will return NULL. Note that prepared transactions are reported as in progress
; applications must check pg_prepared_xacts
if they need to determine whether the txid is a prepared transaction.
The functions shown in Table 9.76 provide information about transactions that have been already committed. These functions mainly provide information about when the transactions were committed. They only provide useful data when track_commit_timestamp configuration option is enabled and only for transactions that were committed after it was enabled.
Table 9.76. Committed Transaction Information
Name | Return Type | Description |
|
| get commit timestamp of a transaction |
|
| get transaction ID and commit timestamp of latest committed transaction |
The functions shown in Table 9.77 print information initialized during initdb
, such as the catalog version. They also show information about write-ahead logging and checkpoint processing. This information is cluster-wide, and not specific to any one database. They provide most of the same information, from the same source, as pg_controldata, although in a form better suited to SQL functions.
Table 9.77. Control Data Functions
Name | Return Type | Description |
|
| Returns information about current checkpoint state. |
|
| Returns information about current control file state. |
|
| Returns information about cluster initialization state. |
|
| Returns information about recovery state. |
pg_control_checkpoint
returns a record, shown in Table 9.78
Table 9.78. pg_control_checkpoint
Columns
Column Name | Data Type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg_control_system
returns a record, shown in Table 9.79
Table 9.79. pg_control_system
Columns
Column Name | Data Type |
|
|
|
|
|
|
|
|
pg_control_init
returns a record, shown in Table 9.80
Table 9.80. pg_control_init
Columns
Column Name | Data Type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg_control_recovery
returns a record, shown in Table 9.81
Table 9.81. pg_control_recovery
Columns
Column Name | Data Type |
|
|
|
|
|
|
|
|
|
|
Last updated