PostgreSQL can generate gigabytes of logs per day. Lots of data is good if you want to investigate a specific event, but it is not what you will use for daily monitoring of database health.
In this recipe, we'll look at how to perform a post analysis of our log files and get reports (and insights) about what has happened in a given period of time.
A different approach is to perform real-time analysis of queries through the pg_stat_statements
extension, which will be covered in the next recipe.
Make sure that your PostgreSQL is set up to rotate log files, for example, daily. I personally prefer to integrate PostgreSQL with rsyslog
and logrotate
for log management on Linux or Unix systems, but you can use any method that is allowed by PostgreSQL (CSV or standard error, for example).
A typical default setup will divert log messages to stderr
, and you can set up log rotation directly in PostgreSQL through the log_rotation_age
configuration...