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();

Helpful Links

PostgreSQL official stats documentation

Matt McGuire

Proven technology leader with 25+ years of experience in the installation, administration, development, design, and maintenance of various enterprise data related systems.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.