pg_current_logfile()

A system function for showing the locations of log file(s) currently in use

pg_current_logfile() is a system function which will return the path(s) of the log file(s) currently in use.

pg_current_logfile() was added in PostgreSQL 10.

Usage

pg_current_logfile(), when called without a parameter, returns in the following order of priority one of:

  • the logfile path where current stderr log output is being directed
  • the logfile path where current csvlog log output is being directed
  • NULL

To return the logfile path of one of the two log types, provide either 'stderr' or 'csvlog' as the function parameter value. See below for examples.

pg_current_logfile() can only be executed by a superuser or a user granted execution permissions on the function, e.g. with:

GRANT EXECUTE ON FUNCTION pg_catalog.pg_current_logfile() TO someuser;
GRANT EXECUTE ON FUNCTION pg_catalog.pg_current_logfile(text) TO someuser;

Implementation

pg_current_logfile() is a helper function which reports the contents of the file current_logfiles, located at the top-most level of the data directory.

Change history

Examples

postgres=# SHOW log_destination;
 log_destination 
-----------------
 stderr,csvlog
(1 row)

postgres=# SELECT * FROM pg_current_logfile();
      pg_current_logfile
------------------------------
 /var/log/pgsql/postgresql.log
(1 row)

postgres=# SELECT * FROM pg_current_logfile('csvlog');
      pg_current_logfile
------------------------------
 /var/log/pgsql/postgresql.csv
(1 row)

postgres=# SELECT * FROM pg_current_logfile('foo');
ERROR:  log format "foo" is not supported
HINT:  The supported log formats are "stderr" and "csvlog".

Categories

Logging

See also

log_directory, log_destination, pg_rotate_logfile()