pg_stat_statements or How to Know Where It Hurts
summary
pg_stat_statements is a PostgreSQL extension that records and aggregates SQL query usage across the whole cluster in a shared in-memory hash (default up to 5000 entries), requiring adding the library to shared_preload_libraries and a server restart, and optionally enabling save/load to survive restarts. It normalizes queries into canonical forms and accumulates counts, total runtime, rows and I/O cumulatively (so you need periodic sampling or a tool like pgwatch for history); recent changes split planning vs runtime in v13 and added top_level and eviction statistics in v14, where eviction drops roughly the lowest ~5% by total time.
AI-written summary · about
