Postgres in Production Special Series: How pg_stat_statements Decides What to Keep (Part 4)
In the fourth part of the "Postgres in Production" series, Ryan Booz walks through the pg_stat_statements source code to show how it decides which entries to keep when its hash table fills up. Allocation is driven by pg_stat_statements.max, a hidden per-query usage counter and mean_query_length. Eviction sorts every entry on each deallocation, only completed executions are stored, and raising pg_stat_statements.max carries a cost.
AI-written summary, checked against the cited sources. How summaries work