Monitoring the PostgreSQL message log
In any production environment, it’s always prudent to monitor log files, not only for warning and error detection but also for performance trend analysis. PostgreSQL can output an overwhelming amount of logs per day, but we don’t have to scan through every line ourselves – we can use a log analyzer such as pgBadger to generate summaries and reports, which can give us insights into what has happened inside our server for a specific time period.
Getting ready
Most Linux distribution PostgreSQL packages, as well as those from the official community repository, have log file rotation already configured as default. pgBadger can also be installed from your default package manager, either from the community repositories or your distribution’s own packages.
We also need to tweak some Postgres settings, such as setting log_line_prefix
to any format we like, as long as it at least specifies %t
(time stamp without...