I get current log file by using SQL without getting in server via ssh. So I use a query like the one below;
SELECT pg_read_binary_file(
concat_ws('/',
current_setting('log_directory'),
'postgresql-Fri.log'
)
);
Log files are not too big so i am fine with that. The thing is, I cannot use this query in a generic way. Is there a way to get 'postgresql-Fri.log' from my log_filename
setting which is currently postgresql-%a.log
but the format can differ?
Best Answer
There is now a
pg_current_logfile()
function returning this information:but it's a new feature of PostgreSQL 10, which you probably don't run since it hasn't yet got out as a
General Availability
release (it's stillRelease Candidate
at the moment).With previous versions, you're pretty much on your own to figure out the current name, either by interpreting
log_filename
, or by finding the latest modified, for instance with a combination ofpg_ls_dir
andpg_stat_file
:This can fail if the server's clock goes backward or if non-log files are dumped into the same directory as the log files.