This recipe describes how to collect the statistics needed to understand what is going on in the database system on a regular basis, so that they can be used for further optimizing the queries which are slow or which are becoming slow as the database changes.
The code to do is in file
Find the package
Set up a directory as shown next for running the scripts:
mkdir /opt/pg_statlogs cd /opt/pg_statlogs tar xzvf pg_statlogs.tgz
Set up a schema for collecting the snapshots of statistics data and generating deltas from it as follows:
psql mydatabase <./pg_statlogs_prepare.sql
Run the following from command line:
psql mydatabase <./pg_statlogs_collect.sql ...