Charles Lavery

Using pg_stat_statements to Track query execution time

Use pg_stat_statements to track query execution time automatically.

shared_preload_libraries = 'pg_stat_statements' # requires restart

postgresql.conf

> CREATE EXTENSION pg_stat_statements;
  ...run application...
> SELECT total_time, total_time/calls as avg_time, query
  FROM pg_stat_statements
  ORDER BY avg_time DESC
  LIMIT 10;