Table 9-44 shows the functions available to query and alter run-time configuration parameters.
Table 9-44. Configuration Settings Functions
| ||text||current value of setting|
| ||text||set parameter and return new value|
current_setting yields the
current value of the setting setting_name.
It corresponds to the SQL command
SHOW. An example:
SELECT current_setting('datestyle'); current_setting ----------------- ISO, MDY (1 row)
set_config sets the parameter
is_local is true, the
new value will only apply to the current transaction. If you want
the new value to apply for the current session, use
false instead. The function corresponds to the
SQL command SET. An example:
SELECT set_config('log_statement_stats', 'off', false); set_config ------------ off (1 row)
The functions shown in Table 9-45 send control signals to other server processes. Use of these functions is restricted to superusers.
Table 9-45. Server Signalling Functions
| ||boolean||Cancel a backend's current query|
| ||boolean||Cause server processes to reload their configuration files|
| ||boolean||Rotate server's log file|
Each of these functions returns true if successful and false otherwise.
pg_cancel_backend sends a query cancel
(SIGINT) signal to a backend process identified by
process ID. The process ID of an active backend can be found from
the procpid column in the
pg_stat_activity view, or by listing the
postgres processes on the server with
pg_reload_conf sends a SIGHUP signal
to the postmaster, causing the configuration files
to be reloaded by all server processes.
pg_rotate_logfile signals the log-file manager to switch
to a new output file immediately. This works only when
redirect_stderr is used for logging, since otherwise there
is no log-file manager subprocess.
The functions shown in Table 9-46 assist in making on-line backups. Use of these functions is restricted to superusers.
Table 9-46. Backup Control Functions
| ||text||Set up for performing on-line backup|
| ||text||Finish performing on-line backup|
pg_start_backup accepts a single parameter which is an
arbitrary user-defined label for the backup. (Typically this would be
the name under which the backup dump file will be stored.) The function
writes a backup label file into the database cluster's data directory,
and then returns the backup's starting WAL offset as text. (The user
need not pay any attention to this result value, but it is provided in
case it is of use.)
pg_stop_backup removes the label file created by
pg_start_backup, and instead creates a backup history file in
the WAL archive area. The history file includes the label given to
pg_start_backup, the starting and ending WAL offsets for
the backup, and the starting and ending times of the backup. The return
value is the backup's ending WAL offset (which again may be of little
For details about proper usage of these functions, see Section 23.3.
The functions shown in Table 9-47 calculate the actual disk space usage of database objects.
Table 9-47. Database Object Size Functions
|int||Number of bytes used to store a particular value (possibly compressed)|
| ||bigint||Disk space used by the tablespace with the specified OID|
| ||bigint||Disk space used by the tablespace with the specified name|
| ||bigint||Disk space used by the database with the specified OID|
| ||bigint||Disk space used by the database with the specified name|
| ||bigint||Disk space used by the table or index with the specified OID|
| ||bigint||Disk space used by the table or index with the specified name. The table name may be qualified with a schema name|
| ||bigint||Total disk space used by the table with the specified OID, including indexes and toasted data|
| ||bigint||Total disk space used by the table with the specified name, including indexes and toasted data. The table name may be qualified with a schema name|
| ||text||Converts a size in bytes into a human-readable format with size units|
pg_column_size shows the space used to store any individual
the OID or name of a tablespace or database, and return the total disk
space used therein.
pg_relation_size accepts the OID or name of a table, index or
toast table, and returns the size in bytes.
pg_total_relation_size accepts the OID or name of a
table or toast table, and returns the size in bytes of the data
and all associated indexes and toast tables.
pg_size_pretty can be used to format the result of one of
the other functions in a human-readable way, using kB, MB, GB or TB as
The functions shown in Table 9-48 provide native file access to files on the machine hosting the server. Only files within the database cluster directory and the log_directory may be accessed. Use a relative path for files within the cluster directory, and a path matching the log_directory configuration setting for log files. Use of these functions is restricted to superusers.
Table 9-48. Generic File Access Functions
| ||setof text||List the contents of a directory|
| ||text||Return the contents of a text file|
| ||record||Return information about a file|
pg_ls_dir returns all the names in the specified
directory, except the special entries "." and
pg_read_file returns part of a text file, starting
at the given offset, returning at most length
bytes (less if the end of file is reached first). If offset
is negative, it is relative to the end of the file.
pg_stat_file returns a record containing the file
size, last accessed time stamp, last modified time stamp,
last file status change time stamp (Unix platforms only),
file creation timestamp (Windows only), and a boolean indicating
if it is a directory. Typical usages include:
SELECT * FROM pg_stat_file('filename'); SELECT (pg_stat_file('filename')).modification;