Locate PostgreSQL logs on Linux, macOS, or Docker

Find PostgreSQL collector files and service output using active SQL settings, platform service configuration, and container logs.

Best practices
Illustration of Linux system logging

Start with PostgreSQL's active logging settings. Package defaults are useful clues, but the running instance and its service configuration determine where records actually go.

Query the server

SHOW log_destination;
SHOW logging_collector;
SHOW log_directory;
SHOW log_filename;
SHOW data_directory;
SELECT pg_current_logfile();

If the collector is enabled, a relative log_directory is resolved against data_directory. You can inspect the same value through the settings view:

SELECT setting
FROM pg_settings
WHERE name = 'log_directory';

pg_current_logfile() can identify a current collector-managed file. If it returns null, inspect service redirection and other destinations; null does not mean there are no logs.

Follow the installation's service configuration

Environment Where to look
Debian/Ubuntu packages Often /var/log/postgresql/, with version and cluster in the filename
PGDG packages on RHEL-family systems Often a log/ directory under the versioned data directory
Homebrew on macOS The service definition and formula-specific path under the Homebrew prefix
Docker Usually container stdout/stderr unless file collection was configured

For example, Debian might use /var/log/postgresql/postgresql-15-main.log; the version is part of the example, not a required filename.

On macOS, inspect installed services:

brew services list
brew --prefix

Then inspect the relevant service information and launch configuration. Apple Silicon commonly uses /opt/homebrew and Intel installations /usr/local, but the logfile name can include the PostgreSQL formula version. Do not assume every installation writes postgres.log.

On Linux or in Docker:

journalctl -u postgresql -f
docker logs -f postgres-container

Choose the actual cluster unit or container name. PostgreSQL's stderr may be redirected to a regular file rather than journald, so an empty journal is not decisive.

Configure collector-managed files

logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_min_duration_statement = 500

Changing logging_collector requires a restart. The duration threshold can be changed by an authorized session or through reloadable configuration; it is measured in milliseconds. A value of 0 logs every completed statement's duration and can generate substantial output.

Rotation is controlled by log_rotation_age and log_rotation_size as well as the filename pattern. Removing hours and minutes makes multiple rotations target the same date-based name; whether content is appended or replaced also depends on log_truncate_on_rotation. A filename change alone is not a retention policy.

Validate before collecting

Generate a controlled test record and confirm which file or stream receives it. For DataKit file collection, configure read permissions and verify event time and multiline boundaries. Enable slow-query logging at PostgreSQL first if those are the records you want to parse; a collector cannot create missing database events.

See the PostgreSQL logging reference for destination and rotation behavior.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting