Tuesday, October 01, 2024

PostgreSQL - Logging

PostgreSQL records all activity and errors of cluster database into logs. From these logs, we can get useful information for troubleshooting, monitoring and debugging.

1. Where To Log

  •     Controls logging type for a database cluster
  •     Can be set to stderr, csvlog, jsonlog, syslog, and eventlog
  •     Enables logger process to capture stderr and csv logging messages 
  •     These messages can be redirected based on configuration settings
Log File and Directory Settings

2. When To Log

3. What To Log
  • log_connectionsLog successful connections to the server log
  • log_disconnectionsLog some information each time a session disconnects, including the duration of the session
  • log_temp_filesLog temporary files of this size or larger, in kilobytes 
  • log_checkpointsCauses checkpoints and restart points to be logged in the server log
  • log_lock_waitsLog information if a session is waits longer than deadlock_timeout to acquire a lock
  • log_error_verbosityHow detailed the logged message is. Can be set to default, terse or verbose
  • log_line_prefixAdditional details to log with each line. Default is '%m [%p] ‘ which logs a timestamp and the process ID
  • log_statementLegal values are none, ddl, mod (DDL and all other data-modifying statements), or all

Ref: