Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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');

 current_setting
-----------------
 ISO, MDY
(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);

 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

Name Return Type Description
pg_cancel_backend(pid int) boolean Cancel a backend's current query
pg_reload_conf() boolean Cause server processes to reload their configuration files
pg_rotate_logfile() 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 ps.

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

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 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

Name Return Type Description
pg_column_size(any) int Number of bytes used to store a particular value (possibly compressed)
pg_tablespace_size(oid) bigint Disk space used by the tablespace with the specified OID
pg_tablespace_size(name) bigint Disk space used by the tablespace with the specified name
pg_database_size(oid) bigint Disk space used by the database with the specified OID
pg_database_size(name) bigint Disk space used by the database with the specified name
pg_relation_size(oid) bigint Disk space used by the table or index with the specified OID
pg_relation_size(text) bigint Disk space used by the table or index with the specified name. The table name may be qualified with a schema name
pg_total_relation_size(oid) bigint Total disk space used by the table with the specified OID, including indexes and toasted data
pg_total_relation_size(text) 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
pg_size_pretty(bigint) 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 data value.

pg_tablespace_size and pg_database_size accept 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 appropriate.

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

Name Return Type Description
pg_ls_dir(dirname text) setof text List the contents of a directory
pg_read_file(filename text, offset bigint, length bigint) text Return the contents of a text file
pg_stat_file(filename text) 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;


 
 
  Published courtesy of The PostgreSQL Global Development Group Design by Interspire