May 2018
Intermediate to advanced
576 pages
30h 25m
English
Connect to a database where you have installed the pg_stat_statements extension, preferably as a superuser.
You can start by retrieving a list of the most frequent queries:
SELECT query FROM pg_stat_statements ORDER BY calls DESC;
Alternatively, you can retrieve the queries with the highest average execution time:
SELECT query, total_time/calls AS avg, calls FROM pg_stat_statements ORDER BY 2 DESC;
These are just examples. I strongly recommend that you look at the PostgreSQL documentation at http://www.postgresql.org/docs/current/static/pgstatstatements.html for more detailed information on the structure of the pg_stat_statements view.