PostgreSQL‎ > ‎

Logging

postgresql.conf (unless otherwise organized):
# From pgBadger docs, good initial settings
log_line_prefix = 'db=%d,user=%u,app=%a,client=%h ' 
log_error_verbosity = default
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0

# Log ALL autovacuum attempts
log_autovacuum_min_duration = 0

# Log ALL DML & DDL statements
log_statement = 'mod'

# Log queries that take over 5 seconds
log_min_duration_statement = 5000


syslog Setup

postgresql.conf:
# syslog setup (if using syslog)
log_destination = 'syslog'
syslog_facility = 'LOCAL0'
syslog_ident = 'postgres'

/etc/rsyslog.conf:
$FileOwner      postgres
local0.*        /var/log/postgresql/postgresql.log
Then: systemctl restart rsyslog

/etc/logrotate.d/postgresql:
/var/log/postgresql/postgresql.log {
    rotate 7
    daily
    dateext
    copytruncate
    compress
    delaycompress
    nomail
    notifempty
}




Comments