DBAtlas · Database operations atlas

Reset pg_stat_statements statistics (all or a single query)

PostgreSQLPerformance

Command

-- 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.

Open in DBAtlas →

Related