Skip to main content
Version: 1.0.16

adminpack

adminpack provides support functions such as remote management of server log files. All of these functions are restricted to superusers by default, but access can be granted to other users using the GRANT command.

The functions shown in Table C.1 provide file writing capabilities. For these functions, only files located in the database cluster directory can be accessed, using either relative or absolute paths.

Table C.1. adminpack Functions

Function/Description
pg_catalog.pg_file_write ( filename text, data text, append boolean ) → bigint Writes or appends to a text file.
pg_catalog.pg_file_sync ( filename text ) → void Flushes a file or directory to disk.
pg_catalog.pg_file_rename (oldname text, newname text [, archivename text ] )→ Boolean Renames a file.
pg_catalog.pg_file_unlink ( filename text ) → boolean Removes a file.
pg_catalog.pg_logdir_ls () → setof record Lists the log files in the log_directory directory.

pg_file_write writes the specified data to the file named by filename. If append is false, the file must not already exist. If append is true, the file may already exist and will be appended to. This function returns the number of bytes written.

pg_file_sync fsyncs the specified file or directory named by filename. An error is thrown on failure (for example, if the specified file does not exist). Note that data_sync_retry has no effect on this function, so a failure to flush database files will not trigger a PANIC-level error.

pg_file_rename renames a file. If archivename is omitted or NULL, it simply renames oldname to newname (which must not already exist). If archivename is provided, the function first renames newname to archivename (which must not already exist), then renames oldname to newname. If the second rename fails, the function attempts to rename archivename back to newname before reporting an error. The function returns true on success, false if the source file does not exist or is not writable, and throws an error in other cases.

pg_file_unlink removes the specified file. The function returns true on success, false if the specified file does not exist or the unlink() call fails, and throws an error in other cases.

pg_logdir_ls returns the start timestamp and path name of all log files in the log_directory. To use this function, the log_filename parameter must be set to its default value (postgresql-%Y-%m-%d_%H%M%S.log).