14th September 2023: PostgreSQL 16 Released!
Supported Versions: Current (16) / 15 / 14 / 13 / 12 / 11
Development Versions: devel
Unsupported versions: 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

9.20. System Administration Functions

Table 9-44 shows the functions available to query and alter run-time configuration parameters.

Table 9-44. Configuration Settings Functions

Name Return Type Description
current_setting(setting_name) text current value of setting
set_config(setting_name, new_value, is_local) text set parameter and return new value

The function current_setting yields the current value of the setting setting_name. It corresponds to the SQL command SHOW. An example:

SELECT current_setting('datestyle');

(1 row)

set_config sets the parameter setting_name to new_value. If 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);

(1 row)

The function shown in Table 9-45 sends control signals to other server processes. Use of this function is restricted to superusers.

Table 9-45. Backend Signalling Functions

Name Return Type Description
pg_cancel_backend(pid) int Cancel a backend's current query

This function returns 1 if successful, 0 if not successful. The process ID (pid) 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 ps.

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

Name Return Type Description
pg_start_backup(label_text) text Set up for performing on-line backup
pg_stop_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 interest).

For details about proper usage of these functions, see Section 22.3.