How can I dynamically determine the current Postgres log file?
Is there a standard way to figure out which is the most recent log file of the running Postgres instance?
pg_config, unfortunately, does not eve开发者_如何学Cn give information about the log directory.
The logs are in the data directory, in directory pg_log. You can ask the database to get this information for you:
SELECT
pg_ls_dir AS filename,
pg_size_pretty((pg_stat_file('pg_log/' || pg_ls_dir)).size),
(pg_stat_file('pg_log/' || pg_ls_dir)).access,
(pg_stat_file('pg_log/' || pg_ls_dir)).modification,
(pg_stat_file('pg_log/' || pg_ls_dir)).creation -- Windows only
FROM
pg_ls_dir('pg_log')
WHERE
(pg_stat_file('pg_log/' || pg_ls_dir)).isdir = false
ORDER BY
modification DESC
LIMIT 1;
If you want to read the content of a logfile, you can use pg_read_file().
You have to be superuser to get the information.
精彩评论