May 2018
Intermediate to advanced
576 pages
30h 25m
English
Set up a cron job to run regularly (for example once every hour, day, or week) and let pgBadger analyze one or more log files. Here, you can find a very simple example that can be used to prepare daily reports every hour.
For the sake of simplicity, the script has been purged of any error check. Production usage requires the addition of some basic shell controls:
#!/bin/bashoutdir=/var/www/reportsbegin=$(date +'%Y-%m-%d %H:00:00' -d '-1 day')end=$(date +'%Y-%m-%d %H:00:00')outfile="$outdir/daily-$(date +'%H').html"pgbadger -q -b "$begin" -e "$end" -o "$outfile" \ /var/log/postgres.log.1 /var/log/postgres.log
The preceding script informs pgbadger to analyze the current log file (/var/log/postgresql.log) and the previously rotated ...