Where are PostgreSQL log files stored?
Locate PostgreSQL logs using active settings and pg_current_logfile, then distinguish collector files from service-manager and container output.
The active logging destination is more reliable than any platform's customary path. PostgreSQL may manage its own files, send messages to syslog, or write stderr that a service manager redirects.
Ask the running server
SHOW log_destination;
SHOW logging_collector;
SHOW data_directory;
SHOW log_directory;
SHOW log_filename;
SELECT pg_current_logfile();
When the collector is enabled, log_directory is either absolute or relative to data_directory. Current PostgreSQL uses log as its default directory; pg_log is common in older installations or explicit configurations.
pg_current_logfile() reports a collector-managed file when available. A null result can mean that the collector is disabled or that no applicable collector destination exists. It does not prove that the server emits no logs.
Check installation-specific locations
These are examples to investigate, not guaranteed paths:
# Debian/Ubuntu package-managed clusters
ls /var/log/postgresql/
tail -f /var/log/postgresql/postgresql-15-main.log
# A custom installation explicitly configured to use pg_log
tail -f "$PGDATA"/pg_log/postgresql-*.log
# A systemd unit, if its output is routed to the journal
journalctl -u postgresql -n 100 -f
Choose the actual version and cluster name. On RHEL-family installations, the data directory can be under /var/lib/pgsql/, sometimes with a version component. Resolve the configured directory rather than assuming a fixed pg_log path.
A disabled collector does not imply journald. The service could redirect stderr to a regular file or use syslog, and a package wrapper may manage that path outside PostgreSQL. A generic postgresql systemd unit may not be the instance unit that owns the output.
Configure collector-managed logs
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d.log'
log_min_error_statement = error
log_min_duration_statement = 1000
log_line_prefix = '%t [%p]: user=%u,db=%d '
Changing logging_collector requires a restart. The duration threshold and many other logging options can be reloaded with SELECT pg_reload_conf();; inspect the server log to confirm acceptance.
%t, %p, %u, and %d add the timestamp, process ID, user, and database. Rotation depends on log_rotation_age, log_rotation_size, and filename patterns together. A date in the filename does not itself schedule a rotation.
Containers and centralized collection
For a container that sends logs to stdout or stderr:
docker logs -f postgres-container
If you enabled file logging inside the container, inspect the configured mount and retention policy instead. Container output and collector files are different destinations.
After locating a fresh record, configure DataKit file collection with appropriate read permissions. Verify timestamps, multiline messages, and slow-query fields against a controlled sample; PostgreSQL's own settings still determine which events exist to collect.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan