PostgreSQL
9.26. System Information Functions and Operators #
The functions described in this section are used to obtain various information about a PostgreSQL installation.
9.26.1. Session Information Functions #
Table 9.67 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 28.2.25 for more information.
Table 9.67. Session Information Functions
Function Description |
---|
`+current_catalog+` → `+name+` `+current_database+` () → `+name+` Returns the name of the current database. (Databases are called “[.quote]#catalogs”# in the SQL standard, so |
`+current_query+` () → `+text+` Returns the text of the currently executing query, as submitted by the client (which might contain more than one statement). |
`+current_role+` → `+name+` This is equivalent to |
`+current_schema+` → `+name+`
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+` ( _`+include_implicit+`_ `+boolean+` ) → `+name[]+` Returns an array of the names of all schemas presently in the effective search path, in their priority order. (Items in the current search_path setting that do not correspond to existing, searchable schemas are omitted.) If the Boolean argument is |
`+current_user+` → `+name+` Returns the user name of the current execution context. |
`+inet_client_addr+` () → `+inet+` Returns the IP address of the current client, or |
`+inet_client_port+` () → `+integer+` Returns the IP port number of the current client, or |
`+inet_server_addr+` () → `+inet+` Returns the IP address on which the server accepted the current connection, or |
`+inet_server_port+` () → `+integer+` Returns the IP port number on which the server accepted the current connection, or |
`+pg_backend_pid+` () → `+integer+` Returns the process ID of the server process attached to the current session. |
`+pg_blocking_pids+` ( `+integer+` ) → `+integer[]+` Returns an array of the process ID(s) of the sessions that are blocking the server process with the specified process ID from acquiring a lock, 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, 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+` () → `+timestamp with time zone+` Returns the time 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+` ( [ [.optional]#`+text+`# ] ) → `+text+` Returns the path name of the log file currently in use by the logging collector. The path includes the log_directory directory and the individual log file name. The result is |
`+pg_my_temp_schema+` () → `+oid+` 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+` ( `+oid+` ) → `+boolean+` 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_jit_available+` () → `+boolean+` Returns true if a JIT compiler extension is available (see Chapter 32) and the jit configuration parameter is set to |
`+pg_listening_channels+` () → `+setof text+` Returns the set of names of asynchronous notification channels that the current session is listening to. |
`+pg_postmaster_start_time+` () → `+timestamp with time zone+` Returns the time when the server started. |
`+pg_safe_snapshot_blocking_pids+` ( `+integer+` ) → `+integer[]+` Returns an array of the process ID(s) 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 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. |
`+pg_trigger_depth+` () → `+integer+` Returns the current nesting level of PostgreSQL triggers (0 if not called, directly or indirectly, from inside a trigger). |
`+session_user+` → `+name+` Returns the session user’s name. |
`+system_user+` → `+text+` Returns the authentication method and the identity (if any) that the user presented during the authentication cycle before they were assigned a database role. It is represented as |
`+user+` → `+name+` This is equivalent to |
`+version+` () → `+text+` Returns a string describing the PostgreSQL server’s version. You can also get this information from server_version, or for a machine-readable version use server_version_num. Software developers should use |
+
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 “[.quote]#real user”# and the current user is the “[.quote]#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.)
9.26.2. Access Privilege Inquiry Functions #
Table 9.68 lists functions that allow querying object access privileges programmatically. (See Section 5.7 for more information about privileges.) In these functions, the user whose privileges are being inquired about can be specified by name or by OID (pg_authid
.oid
), or if the name is given as public
then the privileges of the PUBLIC pseudo-role are checked. Also, the `user argument can be omitted entirely, in which case the `current_user is assumed. The object that is being inquired about can be specified either by name or by OID, too. When specifying by name, a schema name can be included if relevant. The access privilege of interest is specified by a text string, which must evaluate to one of the appropriate privilege keywords for the object’s type (e.g.,
SELECT
). 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:
SELECT has_table_privilege('myschema.mytable', 'select');
SELECT has_table_privilege('joe', 'mytable', 'INSERT, SELECT WITH GRANT OPTION');
Table 9.68. Access Privilege Inquiry Functions
Function Description |
---|
`+has_any_column_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+table+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for any column of table? This succeeds either if the privilege is held for the whole table, or if there is a column-level grant of the privilege for at least one column. Allowable privilege types are |
`+has_column_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+table+`_ `+text+` or `+oid+`, _`+column+`_ `+text+` or `+smallint+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for the specified table column? This succeeds either if the privilege is held for the whole table, or if there is a column-level grant of the privilege for the column. The column can be specified by name or by attribute number ( |
`+has_database_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+database+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for database? Allowable privilege types are |
`+has_foreign_data_wrapper_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+fdw+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for foreign-data wrapper? The only allowable privilege type is |
`+has_function_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+function+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for function? The only allowable privilege type is When specifying a function by name rather than by OID, the allowed input is the same as for the
|
`+has_language_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+language+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for language? The only allowable privilege type is |
`+has_parameter_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+parameter+`_ `+text+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for configuration parameter? The parameter name is case-insensitive. Allowable privilege types are |
`+has_schema_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+schema+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for schema? Allowable privilege types are |
`+has_sequence_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+sequence+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for sequence? Allowable privilege types are |
`+has_server_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+server+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for foreign server? The only allowable privilege type is |
`+has_table_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+table+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for table? Allowable privilege types are |
`+has_tablespace_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+tablespace+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for tablespace? The only allowable privilege type is |
`+has_type_privilege+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+type+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for data type? The only allowable privilege type is |
`+pg_has_role+` ( [ [.optional]#_`+user+`_ `+name+` or `+oid+`,# ] _`+role+`_ `+text+` or `+oid+`, _`+privilege+`_ `+text+` ) → `+boolean+` Does user have privilege for role? Allowable privilege types are |
`+row_security_active+` ( _`+table+`_ `+text+` or `+oid+` ) → `+boolean+` Is row-level security active for the specified table in the context of the current user and current environment? |
+
Table 9.69 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.69. aclitem
Operators
Operator Description Example(s) |
---|
`+aclitem+` `+=+` `+aclitem+` → `+boolean+` Are
|
`+aclitem[]+` `+@>+` `+aclitem+` → `+boolean+` Does array contain the specified privileges? (This is true if there is an array entry that matches the `aclitem’s grantee and grantor, and has at least the specified set of privileges.)
|
This is a deprecated alias for
|
+
Table 9.70 shows some additional functions to manage the aclitem
type.
Table 9.70. aclitem
Functions
Function Description |
---|
`+acldefault+` ( _`+type+`_ `+"char"+`, _`+ownerId+`_ `+oid+` ) → `+aclitem[]+` Constructs an |
`+aclexplode+` ( `+aclitem[]+` ) → `+setof record+` ( _`+grantor+`_ `+oid+`, _`+grantee+`_ `+oid+`, _`+privilege_type+`_ `+text+`, _`+is_grantable+`_ `+boolean+` ) Returns the |
`+makeaclitem+` ( _`+grantee+`_ `+oid+`, _`+grantor+`_ `+oid+`, _`+privileges+`_ `+text+`, _`+is_grantable+`_ `+boolean+` ) → `+aclitem+` Constructs an |
+
9.26.3. Schema Visibility Inquiry Functions #
Table 9.71 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. Thus, to list the names of all visible tables:
SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);
For functions and operators, an object in the search path is said to be visible if there is no object of the same name and argument data type(s) earlier in the path. For operator classes and families, both the name and the associated index access method are considered.
Table 9.71. Schema Visibility Inquiry Functions
Function Description |
---|
`+pg_collation_is_visible+` ( _`+collation+`_ `+oid+` ) → `+boolean+` Is collation visible in search path? |
`+pg_conversion_is_visible+` ( _`+conversion+`_ `+oid+` ) → `+boolean+` Is conversion visible in search path? |
`+pg_function_is_visible+` ( _`+function+`_ `+oid+` ) → `+boolean+` Is function visible in search path? (This also works for procedures and aggregates.) |
`+pg_opclass_is_visible+` ( _`+opclass+`_ `+oid+` ) → `+boolean+` Is operator class visible in search path? |
`+pg_operator_is_visible+` ( _`+operator+`_ `+oid+` ) → `+boolean+` Is operator visible in search path? |
`+pg_opfamily_is_visible+` ( _`+opclass+`_ `+oid+` ) → `+boolean+` Is operator family visible in search path? |
`+pg_statistics_obj_is_visible+` ( _`+stat+`_ `+oid+` ) → `+boolean+` Is statistics object visible in search path? |
`+pg_table_is_visible+` ( _`+table+`_ `+oid+` ) → `+boolean+` Is table visible in search path? (This works for all types of relations, including views, materialized views, indexes, sequences and foreign tables.) |
`+pg_ts_config_is_visible+` ( _`+config+`_ `+oid+` ) → `+boolean+` Is text search configuration visible in search path? |
`+pg_ts_dict_is_visible+` ( _`+dict+`_ `+oid+` ) → `+boolean+` Is text search dictionary visible in search path? |
`+pg_ts_parser_is_visible+` ( _`+parser+`_ `+oid+` ) → `+boolean+` Is text search parser visible in search path? |
`+pg_ts_template_is_visible+` ( _`+template+`_ `+oid+` ) → `+boolean+` Is text search template visible in search path? |
`+pg_type_is_visible+` ( _`+type+`_ `+oid+` ) → `+boolean+` Is type (or domain) visible in search path? |
+
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:
SELECT pg_type_is_visible('myschema.widget'::regtype);
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.
9.26.4. System Catalog Information Functions #
Table 9.72 lists functions that extract information from the system catalogs.
Table 9.72. System Catalog Information Functions
Function Description |
---|
`+format_type+` ( _`+type+`_ `+oid+`, _`+typemod+`_ `+integer+` ) → `+text+` Returns the SQL name for 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_char_to_encoding+` ( _`+encoding+`_ `+name+` ) → `+integer+` Converts the supplied encoding name into an integer representing the internal identifier used in some system catalog tables. Returns |
`+pg_encoding_to_char+` ( _`+encoding+`_ `+integer+` ) → `+name+` Converts the integer used as the internal identifier of an encoding in some system catalog tables into a human-readable string. Returns an empty string if an invalid encoding number is provided. |
`+pg_get_catalog_foreign_keys+` () → `+setof record+` ( _`+fktable+`_ `+regclass+`, _`+fkcols+`_ `+text[]+`, _`+pktable+`_ `+regclass+`, _`+pkcols+`_ `+text[]+`, _`+is_array+`_ `+boolean+`, _`+is_opt+`_ `+boolean+` ) Returns a set of records describing the foreign key relationships that exist within the PostgreSQL system catalogs. The `fktable |
`+pg_get_constraintdef+` ( _`+constraint+`_ `+oid+` [[.optional]#, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Reconstructs the creating command for a constraint. (This is a decompiled reconstruction, not the original text of the command.) |
`+pg_get_expr+` ( _`+expr+`_ `+pg_node_tree+`, _`+relation+`_ `+oid+` [[.optional]#, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Decompiles the internal form of an expression stored in the system catalogs, such as the default value for a column. If the expression might contain Vars, specify the OID of the relation they refer to as the second parameter; if no Vars are expected, passing zero is sufficient. |
`+pg_get_functiondef+` ( _`+func+`_ `+oid+` ) → `+text+` Reconstructs the creating command for a function or procedure. (This is a decompiled reconstruction, not the original text of the command.) The result is a complete |
`+pg_get_function_arguments+` ( _`+func+`_ `+oid+` ) → `+text+` Reconstructs the argument list of a function or procedure, in the form it would need to appear in within |
`+pg_get_function_identity_arguments+` ( _`+func+`_ `+oid+` ) → `+text+` Reconstructs the argument list necessary to identify a function or procedure, in the form it would need to appear in within commands such as |
`+pg_get_function_result+` ( _`+func+`_ `+oid+` ) → `+text+` Reconstructs the |
`+pg_get_indexdef+` ( _`+index+`_ `+oid+` [[.optional]#, _`+column+`_ `+integer+`, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Reconstructs the creating command for an index. (This is a decompiled reconstruction, not the original text of the command.) If `column` is supplied and is not zero, only the definition of that column is reconstructed. |
`+pg_get_keywords+` () → `+setof record+` ( _`+word+`_ `+text+`, _`+catcode+`_ `+"char"+`, _`+barelabel+`_ `+boolean+`, _`+catdesc+`_ `+text+`, _`+baredesc+`_ `+text+` ) Returns a set of records describing the SQL keywords recognized by the server. The `word |
`+pg_get_partkeydef+` ( _`+table+`_ `+oid+` ) → `+text+` Reconstructs the definition of a partitioned table’s partition key, in the form it would have in the |
`+pg_get_ruledef+` ( _`+rule+`_ `+oid+` [[.optional]#, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Reconstructs the creating command for a rule. (This is a decompiled reconstruction, not the original text of the command.) |
`+pg_get_serial_sequence+` ( _`+table+`_ `+text+`, _`+column+`_ `+text+` ) → `+text+` 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 that column. For columns created using one of the serial types ( A typical use is in reading the current value of the sequence for an identity or serial column, for example:
|
`+pg_get_statisticsobjdef+` ( _`+statobj+`_ `+oid+` ) → `+text+` Reconstructs the creating command for an extended statistics object. (This is a decompiled reconstruction, not the original text of the command.) |
`+pg_get_triggerdef+` ( _`+trigger+`_ `+oid+` [[.optional]#, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Reconstructs the creating command for a trigger. (This is a decompiled reconstruction, not the original text of the command.) |
`+pg_get_userbyid+` ( _`+role+`_ `+oid+` ) → `+name+` Returns a role’s name given its OID. |
`+pg_get_viewdef+` ( _`+view+`_ `+oid+` [[.optional]#, _`+pretty+`_ `+boolean+`# ] ) → `+text+` Reconstructs the underlying |
Reconstructs the underlying |
Reconstructs the underlying |
`+pg_index_column_has_property+` ( _`+index+`_ `+regclass+`, _`+column+`_ `+integer+`, _`+property+`_ `+text+` ) → `+boolean+` Tests whether an index column has the named property. Common index column properties are listed in Table 9.73. (Note that extension access methods can define additional property names for their indexes.) |
`+pg_index_has_property+` ( _`+index+`_ `+regclass+`, _`+property+`_ `+text+` ) → `+boolean+` Tests whether an index has the named property. Common index properties are listed in Table 9.74. (Note that extension access methods can define additional property names for their indexes.) |
`+pg_indexam_has_property+` ( _`+am+`_ `+oid+`, _`+property+`_ `+text+` ) → `+boolean+` Tests whether an index access method has the named property. Access method properties are listed in Table 9.75. |
`+pg_options_to_table+` ( _`+options_array+`_ `+text[]+` ) → `+setof record+` ( _`+option_name+`_ `+text+`, _`+option_value+`_ `+text+` ) Returns the set of storage options represented by a value from |
`+pg_settings_get_flags+` ( _`+guc+`_ `+text+` ) → `+text[]+` Returns an array of the flags associated with the given GUC, or |
`+pg_tablespace_databases+` ( _`+tablespace+`_ `+oid+` ) → `+setof oid+` Returns the set of OIDs of databases that have objects stored in the specified tablespace. If this function returns any rows, the tablespace is not empty and cannot be dropped. To identify the specific objects populating the tablespace, you will need to connect to the database(s) identified by |
`+pg_tablespace_location+` ( _`+tablespace+`_ `+oid+` ) → `+text+` Returns the file system path that this tablespace is located in. |
`+pg_typeof+` ( `+"any"+` ) → `+regtype+` 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 For example:
|
`+COLLATION FOR+` ( `+"any"+` ) → `+text+` Returns the name of the collation of the value that is passed to it. The value is quoted and schema-qualified if necessary. If no collation was derived for the argument expression, then For example:
|
`+to_regclass+` ( `+text+` ) → `+regclass+` Translates a textual relation name to its OID. A similar result is obtained by casting the string to type |
`+to_regcollation+` ( `+text+` ) → `+regcollation+` Translates a textual collation name to its OID. A similar result is obtained by casting the string to type |
`+to_regnamespace+` ( `+text+` ) → `+regnamespace+` Translates a textual schema name to its OID. A similar result is obtained by casting the string to type |
`+to_regoper+` ( `+text+` ) → `+regoper+` Translates a textual operator name to its OID. A similar result is obtained by casting the string to type |
`+to_regoperator+` ( `+text+` ) → `+regoperator+` Translates a textual operator name (with parameter types) to its OID. A similar result is obtained by casting the string to type |
`+to_regproc+` ( `+text+` ) → `+regproc+` Translates a textual function or procedure name to its OID. A similar result is obtained by casting the string to type |
`+to_regprocedure+` ( `+text+` ) → `+regprocedure+` Translates a textual function or procedure name (with argument types) to its OID. A similar result is obtained by casting the string to type |
`+to_regrole+` ( `+text+` ) → `+regrole+` Translates a textual role name to its OID. A similar result is obtained by casting the string to type |
`+to_regtype+` ( `+text+` ) → `+regtype+` Translates a textual type name to its OID. A similar result is obtained by casting the string to type |
+
Most of the functions that reconstruct (decompile) database objects have an optional `pretty flag, which if `true causes the result to be “[.quote]#pretty-printed”#. Pretty-printing suppresses unnecessary parentheses and adds whitespace for legibility. 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; so avoid using pretty-printed output for dump purposes. Passing
false
for the `pretty` parameter yields the same result as omitting the parameter.
Table 9.73. 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 “[.quote]#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.74. 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.75. 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 |
+
Table 9.76. GUC Flags
Flag | Description |
---|---|
|
Parameters with this flag are included in |
|
Parameters with this flag are excluded from |
|
Parameters with this flag do not support |
|
Parameters with this flag are excluded from |
|
Parameters with this flag are not included in |
|
Parameters with this flag are runtime-computed ones. |
+
9.26.5. Object Information and Addressing Functions #
Table 9.77 lists functions related to database object identification and addressing.
Table 9.77. Object Information and Addressing Functions
Function Description |
---|
`+pg_describe_object+` ( _`+classid+`_ `+oid+`, _`+objid+`_ `+oid+`, _`+objsubid+`_ `+integer+` ) → `+text+` Returns a textual description of a database object identified 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 especially useful to determine the identity of an object referenced in the |
`+pg_identify_object+` ( _`+classid+`_ `+oid+`, _`+objid+`_ `+oid+`, _`+objsubid+`_ `+integer+` ) → `+record+` ( _`+type+`_ `+text+`, _`+schema+`_ `+text+`, _`+name+`_ `+text+`, _`+identity+`_ `+text+` ) 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 |
`+pg_identify_object_as_address+` ( _`+classid+`_ `+oid+`, _`+objid+`_ `+oid+`, _`+objsubid+`_ `+integer+` ) → `+record+` ( _`+type+`_ `+text+`, _`+object_names+`_ `+text[]+`, _`+object_args+`_ `+text[]+` ) 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 |
`+pg_get_object_address+` ( _`+type+`_ `+text+`, _`+object_names+`_ `+text[]+`, _`+object_args+`_ `+text[]+` ) → `+record+` ( _`+classid+`_ `+oid+`, _`+objid+`_ `+oid+`, _`+objsubid+`_ `+integer+` ) Returns a row containing enough information to uniquely identify the database object specified by a type code and object name and argument arrays. The returned values are the ones that would be used in system catalogs such as |
+
9.26.6. Comment Information Functions #
The functions shown in Table 9.78 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.78. Comment Information Functions
Function Description |
---|
`+col_description+` ( _`+table+`_ `+oid+`, _`+column+`_ `+integer+` ) → `+text+` Returns the comment for a table column, which is specified by the OID of its table and its column number. ( |
`+obj_description+` ( _`+object+`_ `+oid+`, _`+catalog+`_ `+name+` ) → `+text+` Returns the comment for a database object specified by its OID and the name of the containing system catalog. For example, |
Returns the comment for a database object specified by its OID alone. This is deprecated since there is no guarantee that OIDs are unique across different system catalogs; therefore, the wrong comment might be returned. |
`+shobj_description+` ( _`+object+`_ `+oid+`, _`+catalog+`_ `+name+` ) → `+text+` Returns the comment for a shared database object specified by its OID and the name of the containing system catalog. This is just like |
+
9.26.7. Data Validity Checking Functions #
The functions shown in Table 9.79 can be helpful for checking validity of proposed input data.
Table 9.79. Data Validity Checking Functions
Function Description Example(s) |
---|
`+pg_input_is_valid+` ( _`+string+`_ `+text+`, _`+type+`_ `+text+` ) → `+boolean+` Tests whether the given `string` is valid input for the specified data type, returning true or false. This function will only work as desired if the data type’s input function has been updated to report invalid input as a “[.quote]#soft”# error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly.
|
`+pg_input_error_info+` ( _`+string+`_ `+text+`, _`+type+`_ `+text+` ) → `+record+` ( _`+message+`_ `+text+`, _`+detail+`_ `+text+`, _`+hint+`_ `+text+`, _`+sql_error_code+`_ `+text+` ) Tests whether the given `string This function will only work as desired if the data type’s input function has been updated to report invalid input as a “[.quote]#soft”# error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly.
|
detail |
hint |
sql_error_code --------------------------------------------------------------------+---------------- value "42000000000" is out of range for type integer |
22003 ----
[source,programlisting] ---- message |
detail ------------------------+----------------------------------------------------------------------------------- numeric field overflow |
A field with precision 7, scale 4 must round to an absolute value less than 10^3. ---- |
+
9.26.8. Transaction ID and Snapshot Information Functions #
The functions shown in Table 9.80 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.80. Transaction ID and Snapshot Information Functions
Function Description |
---|
`+pg_current_xact_id+` () → `+xid8+` Returns the current transaction’s ID. It will assign a new one if the current transaction does not have one already (because it has not performed any database updates); see Section 74.1 for details. If executed in a subtransaction, this will return the top-level transaction ID; see Section 74.3 for details. |
`+pg_current_xact_id_if_assigned+` () → `+xid8+` Returns the current transaction’s ID, or |
`+pg_xact_status+` ( `+xid8+` ) → `+text+` Reports the commit status of a recent transaction. The result is one of |
`+pg_current_snapshot+` () → `+pg_snapshot+` Returns a current snapshot, a data structure showing which transaction IDs are now in-progress. Only top-level transaction IDs are included in the snapshot; subtransaction IDs are not shown; see Section 74.3 for details. |
`+pg_snapshot_xip+` ( `+pg_snapshot+` ) → `+setof xid8+` Returns the set of in-progress transaction IDs contained in a snapshot. |
`+pg_snapshot_xmax+` ( `+pg_snapshot+` ) → `+xid8+` Returns the |
`+pg_snapshot_xmin+` ( `+pg_snapshot+` ) → `+xid8+` Returns the |
`+pg_visible_in_snapshot+` ( `+xid8+`, `+pg_snapshot+` ) → `+boolean+` Is the given transaction ID visible according to this snapshot (that is, was it completed before the snapshot was taken)? Note that this function will not give the correct answer for a subtransaction ID (subxid); see Section 74.3 for details. |
+
The internal transaction ID type xid
is 32 bits wide and wraps around every 4 billion transactions. However, the functions shown in Table 9.80 use a 64-bit type xid8
that does not wrap around during the life of an installation and can be converted to xid
by casting if required; see Section 74.1 for details. The data type pg_snapshot
stores information about transaction ID visibility at a particular moment in time. Its components are described in Table 9.81. pg_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
.
Table 9.81. Snapshot Components
Name | Description |
---|---|
|
Lowest transaction ID that was still active. All transaction IDs less than |
|
One past the highest completed transaction ID. All transaction IDs greater than or equal to |
|
Transactions in progress at the time of the snapshot. A transaction ID that is |
+
In releases of PostgreSQL before 13 there was no xid8
type, so variants of these functions were provided that used bigint
to represent a 64-bit XID, with a correspondingly distinct snapshot data type txid_snapshot
. These older functions have txid
in their names. They are still supported for backward compatibility, but may be removed from a future release. See Table 9.82.
Table 9.82. Deprecated Transaction ID and Snapshot Information Functions
Function Description |
---|
`+txid_current+` () → `+bigint+` See |
`+txid_current_if_assigned+` () → `+bigint+` See |
`+txid_current_snapshot+` () → `+txid_snapshot+` See |
`+txid_snapshot_xip+` ( `+txid_snapshot+` ) → `+setof bigint+` See |
`+txid_snapshot_xmax+` ( `+txid_snapshot+` ) → `+bigint+` See |
`+txid_snapshot_xmin+` ( `+txid_snapshot+` ) → `+bigint+` See |
`+txid_visible_in_snapshot+` ( `+bigint+`, `+txid_snapshot+` ) → `+boolean+` See |
`+txid_status+` ( `+bigint+` ) → `+text+` See |
+
9.26.9. Committed Transaction Information Functions #
The functions shown in Table 9.83 provide information about when past transactions were committed. They only provide useful data when the track_commit_timestamp configuration option is enabled, and only for transactions that were committed after it was enabled. Commit timestamp information is routinely removed during vacuum.
Table 9.83. Committed Transaction Information Functions
Function Description |
---|
`+pg_xact_commit_timestamp+` ( `+xid+` ) → `+timestamp with time zone+` Returns the commit timestamp of a transaction. |
`+pg_xact_commit_timestamp_origin+` ( `+xid+` ) → `+record+` ( _`+timestamp+`_ `+timestamp with time zone+`, _`+roident+`_ `+oid+`) Returns the commit timestamp and replication origin of a transaction. |
`+pg_last_committed_xact+` () → `+record+` ( _`+xid+`_ `+xid+`, _`+timestamp+`_ `+timestamp with time zone+`, _`+roident+`_ `+oid+` ) Returns the transaction ID, commit timestamp and replication origin of the latest committed transaction. |
+
9.26.10. Control Data Functions #
The functions shown in Table 9.84 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, not specific to any one database. These functions provide most of the same information, from the same source, as the pg_controldata application.
Table 9.84. Control Data Functions
Function Description |
---|
`+age+` ( `+xid+` ) → `+integer+` Returns the number of transactions between the supplied transaction id and the current transaction counter. |
`+mxid_age+` ( `+xid+` ) → `+integer+` Returns the number of multixacts IDs between the supplied multixact ID and the current multixacts counter. |
`+pg_control_checkpoint+` () → `+record+` Returns information about current checkpoint state, as shown in Table 9.85. |
`+pg_control_system+` () → `+record+` Returns information about current control file state, as shown in Table 9.86. |
`+pg_control_init+` () → `+record+` Returns information about cluster initialization state, as shown in Table 9.87. |
`+pg_control_recovery+` () → `+record+` Returns information about recovery state, as shown in Table 9.88. |
+
Table 9.85. pg_control_checkpoint
Output Columns
Column Name | Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
Table 9.86. pg_control_system
Output Columns
Column Name | Data Type |
---|---|
|
|
|
|
|
|
|
|
+
Table 9.87. pg_control_init
Output Columns
Column Name | Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
Table 9.88. pg_control_recovery
Output Columns
Column Name | Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
+
Prev | Up | Next |
---|---|---|
9.25. Set Returning Functions |
9.27. System Administration Functions |
Submit correction
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.
Copyright © 1996-2024 The PostgreSQL Global Development Group