- Michael Vitale
- 27th April 2020
- Aurora, Database, postgres, postgresql
If you reboot your PostgreSQL aurora instance, your distribution stats will still be there, but your monitoring stats will not. Official PostgreSQL documentation states that if you do a normal shutdown, both distribution and monitoring stats will still be there when you restart your instance (Monitoring Stats):
“When the server shuts down cleanly, a permanent copy of the statistics data is stored in the pg_stat subdirectory, so that statistics can be retained across server restarts. When recovery is performed at server start (e.g. after immediate shutdown, server crash, and point-in-time recovery), all statistics counters are reset.”
This does not work however for the current aurora engine versions for PostgreSQL. This is a known bug in aurora. As of this date, April 27, 2020, these are the versions of the Aurora engine that have this bug:
So until this is fixed, you need to run vacuum analyze on all your tables whenever you reboot, or the autovacuum daemon will think that vacuum was never done.
The monitoring stats are the ones that get reset by calling pg_stat_reset(). The pg_stat_ and pg_statio_ tables fall into this category. The distribution stats are the ones that track distribution of data – number of distinct values, most common values in the column, histogram of data etc., which are more durably stored in the database.
Regarding this bug, the Amazon Aurora team states:
“Unfortunately, the monitoring stats like ‘pg_stat_all_tables’ and ‘pg_stat_user_tables’ gets reset after an instance reboot but the data distribution stats will not be impacted. This is a known bug in Aurora PostgreSQL. There is a feature request pending with engineering teams to preserve the stats after reboot. Unfortunately there isn’t any ETA on it.”
Michael Vitale, Team Elephas
- Vacuum Those MVs!
- Working With Repmgr: Using Other 3rd Party Tools for Setting up a Standby
- Working with Amazon Aurora PostgreSQL: dag, standby rebooted again!
- Working with Amazon Aurora PostgreSQL: what happened to the stats?
- How to set application_name for psql command line utility?
- Is there a limit on number of partitions handled by Postgres?
- Postgres 11 partitioning
- Audit logging with Postgres partitioning
- Audit logging using JSONB in Postgres
- Connecting Postgres to Active Directory for Authentication