Hands-on Lab·PostgreSQL
PostgreSQL Server Log Configuration
logging_collector is off, pg_current_logfile() returns NULL, and there is still a log file. Then four settings that turn it into something worth reading.
Monitoring and Operations Guide 40 of 47 Intermediate
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- Host2 core / 4 GB, 400,000-row test table
- TimeAbout 18 min
log_connections became a list in PostgreSQL 18 - receipt, authentication, authorization. on is still accepted and means all of them. On 17 and earlier it is a plain boolean.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when pg_current_logfile() returns NULL and there is still a log. This matters because the packaging does not use the logging collector - so what matters is the prefix, and the three things actually worth logging.
- finding the log the packaging really uses, with the collector switched off
- reading
log_line_prefix, and what each escape in it means - logging the statements slower than a threshold
- logging connections the PostgreSQL 18 way, and logging lock waits
- putting it back, and meeting a role that will not drop
Before you start
- Shell access as a user who can
sudo -u postgresand read/var/log/postgresql/.
-
Find the log the packaging actually uses
-
Read the prefix
-
Log the slow statements
-
Log who connects, PostgreSQL 18 style
-
Log the lock waits
-
Put it back, and hit a role that will not drop