How to reset the pg_stat statistics tables.
There is a group of PostgreSQL views that allow you to view various statistics on the database. Some of the most common statistics views I use are:
- pg_stat_statements
- pg_stat_all_tables
- pg_statio_all_tables
- pg_stat_all_indexes
- pg_statio_all_indexes
- pg_stat_activity
- pg_stat_database
To get a full list of statistics views you can run something like this:
SELECT viewname
FROM pg_views
WHERE viewname LIKE 'pg_stat%';
To reset these statistics you can run a couple of simple commands. To reset pg_stat_statements data you can run:
SELECT pg_stat_statements_reset();
To reset other Postgres stats run:
SELECT pg_stat_reset();