pgBadger Report – Steps to Create

What is pgBadger?

pgBadger is a PostgreSQL performance analyzer, built for speed with fully detailed reports which include graphs based on your PostgreSQL log files.

What is a Log File?

The log file can be a single log file or a list of files, or a shell command returning a list of files. These files would be generated by the executed queries on a prod or test database.

Why it is Important to use pgBadger?

Knowing what goes on with your PostgreSQL database is of great importance. Looking at the PostgreSQL logs will give you a clue, however, simply browsing the logs with a text editor is difficult to understand since the logs become very large with lots of repetitive content.

What are the steps needed to install the pgBadger and then to run a report?

  1. Install the PG Badger for your LINUX version (any full version is good) using the following link. Here, you would get the script to execute on your box.

https://www.postgresql.org/download/linux/redhat/

  • Register the repository with the yum command (RPM)
  • Install pgBadger from that repository

# Install the repository RPM for PostgreSQL version 10.11 on CENTOS 7 x86 64:
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PgBadger
yum install pgbadger

# Install PostgreSQL:
yum install -y postgresql10-server

  • After the successful installation of PgBadger, copy your Postgres DB logs into a specific folder on Linux. These DB logs should be generated from the query runs, should contain all the query execution information.
  • Use the below command to create a PgBadger report

pgbadger -f  rds -o report123.html /root/logs/*

If you have a combined logs file as < rds.log >, then use the below command, please note that the default top 20 queries will be listed by this

pgbadger -f  rds -o report123.html rds.log

If you need to create a list of 100 queries, then need to specify the time parameter as follows

pgbadger -f  rds -t 100 -o report456.html rds.log

  • Below is the screen print for your reference

Once the report successfully generated, you would return to the command prompt

  • Open the report123.html report from the folder where it was created, in that you can see the PgBadger report created for your logs.

That’s all you need to know, please do let us know if you need any other information.