System Information Functions and Operators
System Information Functions and Operators
Table 8.54 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 11.1.1 for more information.
Table Session Information Functions
Function Description |
---|
Returns the name of the current database. (Databases are called “catalogs” in the SQL standard, so |
This is equivalent to |
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. |
Returns an array of the names of all schemas presently in the effective search path, in their priority order. (Items in the current "guc-search-path" setting that do not correspond to existing, searchable schemas are omitted.) If the Boolean argument is |
Returns the user name of the current execution context. |
Returns the IP address of the current client, or |
Returns the IP port number of the current client, or |
Returns the IP address on which the server accepted the current connection, or |
Returns the IP port number on which the server accepted the current connection, or |
Returns the process ID of the server process attached to the current session. |
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. |
Returns the OID of the current session's temporary schema, or zero if it has none (because it has not created any temporary tables). |
This is equivalent to |
Returns a string describing the Tacnode server's version. You can also get this information from "guc-server-version", or for a machine-readable version use "guc-server-version-num". Software developers should use |
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 "sql-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 Tacnode
does not, since it unifies users and roles into a single kind of entity.)
Table 8.55 lists functions that allow querying object access privileges programmatically. 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:
Table Access Privilege Inquiry Functions
Function Description |
---|
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 |
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 ( |
Does user have privilege for database? Allowable privilege types are |
Does user have privilege for foreign-data wrapper? The only allowable privilege type is |
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 |
Does user have privilege for language? The only allowable privilege type is |
Does user have privilege for schema? Allowable privilege types are |
Does user have privilege for sequence? Allowable privilege types are |
Does user have privilege for foreign server? The only allowable privilege type is |
Does user have privilege for table? Allowable privilege types are |
Does user have privilege for tablespace? The only allowable privilege type is |
Does user have privilege for data type? The only allowable privilege type is |
Table 8.56 shows the operators available for the aclitem
type, which is the catalog representation of access privileges.
Table aclitem
Operators
Operator Description Example(s) |
---|
Are
|
Does array contain the specified privileges? (This is true if there is an array entry that matches the
|
This is a deprecated alias for
|
Table 8.57 shows some additional functions to manage the aclitem
type.
Table aclitem
Functions
Function Description |
---|
Constructs an |
Returns the |
Most of the functions that reconstruct (decompile) database objects have an optional pretty
flag, which if true
causes the result to be “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 Tacnode; so avoid using pretty-printed output for dump purposes. Passing false
for the pretty
parameter yields the same result as omitting the parameter.
Table Index Column Properties
Name | Description |
---|---|
asc | Does the column sort in ascending order on a forward scan? |
desc | Does the column sort in descending order on a forward scan? |
nulls_first | Does the column sort with nulls first on a forward scan? |
nulls_last | Does the column sort with nulls last on a forward scan? |
orderable | Does the column possess any defined sort ordering? |
distance_orderable | Can the column be scanned in order by a “distance” operator, for example ORDER BY col <-> constant ? |
returnable | Can the column value be returned by an index-only scan? |
search_array | Does the column natively support col = ANY(array) searches? |
search_nulls | Does the column support IS NULL and IS NOT NULL searches? |
Table Index Properties
Name | Description |
---|---|
clusterable | Can the index be used in a CLUSTER command? |
index_scan | Does the index support plain (non-bitmap) scans? |
bitmap_scan | Does the index support bitmap scans? |
backward_scan | Can the scan direction be changed in mid-scan (to support FETCH BACKWARD on a cursor without needing materialization)? |
Table Index Access Method Properties
Name | Description |
---|---|
can_order | Does the access method support ASC , DESC and related keywords in CREATE INDEX ? |
can_unique | Does the access method support unique indexes? |
can_multi_col | Does the access method support indexes with multiple columns? |
can_exclude | Does the access method support exclusion constraints? |
can_include | Does the access method support the INCLUDE clause of CREATE INDEX ? |
The functions shown in Table 8.61 extract comments previously stored with the COMMENT command. A null value is returned if no comment could be found for the specified parameters.
Table Comment Information Functions
Function Description |
---|
Returns the comment for a table column, which is specified by the OID of its table and its column number. ( |
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. |
Returns the comment for a shared database object specified by its OID and the name of the containing system catalog. This is just like |
The data type pg_snapshot
stores information about transaction ID visibility at a particular moment in time. Its components are described in Table 8.62. 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 Snapshot Components
Name | Description |
---|---|
xmin | Lowest transaction ID that was still active. All transaction IDs less than xmin are either committed and visible, or rolled back and dead. |
xmax | One past the highest completed transaction ID. All transaction IDs greater than or equal to xmax had not yet completed as of the time of the snapshot, and thus are invisible. |
xip_list | Transactions in progress at the time of the snapshot. A transaction ID that is xmin <= `X` < xmax and not in this list was already completed at the time of the snapshot, and thus is either visible or dead according to its commit status. This list does not include the transaction IDs of subtransactions. |
Table pg_control_checkpoint
Output Columns
Column Name | Data Type |
---|---|
checkpoint_lsn | pg_lsn |
redo_lsn | pg_lsn |
redo_wal_file | text |
timeline_id | integer |
prev_timeline_id | integer |
full_page_writes | boolean |
next_xid | text |
next_oid | oid |
next_multixact_id | xid |
next_multi_offset | xid |
oldest_xid | xid |
oldest_xid_dbid | oid |
oldest_active_xid | xid |
oldest_multi_xid | xid |
oldest_multi_dbid | oid |
oldest_commit_ts_xid | xid |
newest_commit_ts_xid | xid |
checkpoint_time | timestamp with time zone |
Table pg_control_system
Output Columns
Column Name | Data Type |
---|---|
pg_control_version | integer |
catalog_version_no | integer |
system_identifier | bigint |
pg_control_last_modified | timestamp with time zone |
Table pg_control_init
Output Columns
Column Name | Data Type |
---|---|
max_data_alignment | integer |
database_block_size | integer |
blocks_per_segment | integer |
wal_block_size | integer |
bytes_per_wal_segment | integer |
max_identifier_length | integer |
max_index_columns | integer |
max_toast_chunk_size | integer |
large_object_chunk_size | integer |
float8_pass_by_value | boolean |
data_page_checksum_version | integer |
Table pg_control_recovery
Output Columns
Column Name | Data Type |
---|---|
min_recovery_end_lsn | pg_lsn |
min_recovery_end_timeline | integer |
backup_start_lsn | pg_lsn |
backup_end_lsn | pg_lsn |
end_of_backup_record_required | boolean |