OpenTelemetry Support
...
Service Integration Guides
Postgres Monitoring

Enable logging in PostgreSQL

5min
this document provides instructions for enabling logging in postgresql enabling logging in postgresql edit the postgresql conf postgresql conf which locate at /etc/postgresql/\<version>/main/postgresql conf /etc/postgresql/\<version>/main/postgresql conf file this file is usually found in the data directory of your postgresql installation open it in your preferred text editor set logging parameters add or modify the following parameters to enable logging use the below configuration for postgresql version >=15 \# use these settings for pgsql version >= 15 log destination = 'jsonlog' logging collector = on log min messages = warning log min duration statement = 250 # duration in ms change this for desired slow query logging use the below configuration for postgresql version < 15 \# use these settings for pgsql version < 15 log destination = 'stderr' logging collector = on log min messages = warning log min duration statement = 250 # duration in ms change this for desired slow query logging log line prefix = '%m \[%p] %d %u ' json log is only supported in postgresql 15 and above 3\ save changes and restart postgresql after making changes, save the postgresql conf postgresql conf file and restart the postgresql server to apply the new logging settings systemctl restart postgresql important notes postgresql version limitations versions 14 and older cannot save logs in json format supported formats are stderr stderr , csvlog , and syslog syslog versions 15, 16, and 17 json logging is supported, providing more structured and flexible log data check your postgresql version you can check your postgresql version by running the following command in the psql command line interface select version();