Reset pg_stat_statements statistics (all or a single query)
PostgreSQLPerformanceCommand
-- Last reset time and number of entries evicted because the table was full (dealloc)
SELECT dealloc, stats_reset FROM pg_stat_statements_info;
-- Reset a single query only (userid, dbid, queryid; 0 = all)
SELECT pg_stat_statements_reset(0, 0, 5927525816675996975);
-- Reset all statistics
SELECT pg_stat_statements_reset();What it does
Resets pg_stat_statements counters entirely or per user/database/queryid; pg_stat_statements_info shows the last reset time and how many entries were evicted for lack of space.
When to use it
To start a clean measurement before a tuning change (index, parameter, deploy) or to measure a single query's new plan in isolation.
Caution
A reset cannot be undone; monitoring/APM tools that rely on cumulative counters will show a gap, so take a snapshot first (see the plan regression recipe). If dealloc keeps growing, pg_stat_statements.max is too small (changing it requires a restart). By default only superusers can run it; grant it with GRANT EXECUTE ON FUNCTION.
Related
- Find the most expensive queries (pg_stat_statements: total and mean time)
- Find queries driving disk I/O, temp files and WAL (pg_stat_statements)
- Log execution plans of slow queries with auto_explain
- Read a plan in depth with EXPLAIN (ANALYZE, BUFFERS, SETTINGS, WAL)
- Catch plan regressions by queryid (pg_stat_statements snapshot comparison)
- Check parallel query capacity and current worker usage