pg_stat_statements: Top Queries
Enable pg_stat_statements, find the heaviest queries by total time, and target them for optimisation.
What pg_stat_statements Gives You
An accumulating record of every query, normalised by shape — the single most useful DBA tool in PostgreSQL.
Enable It
It's a contrib extension. Add to shared_preload_libraries and restart:
-- postgresql.conf
shared_preload_libraries = 'pg_stat_statements'
-- After restart:
CREATE EXTENSION pg_stat_statements;All lessons in this course
- pg_stat_statements: Top Queries
- pgBadger for Log Analysis
- Connection Pooling: PgBouncer
- Capacity Planning and Bloat Audits