Following a failover, the statistics are reset to 0 on the new primary in the pg_stat_user_tables view.
relname | n_tup_ins | n_tup_upd | n_tup_del | n_live_tup | n_dead_tup | last_autovacuum | last_autoanalyze | n_mod_since_analyze
--------- ----------- ----------- ----------- ------------ ------------ ----------------- ------------------ ---------------------
foo | 0 | 0 | 0 | 0 | 0 | | | 0
(1 row)
If modifications are made on a tables (update/delete/insert) and the vacuum was not executed before the FO, the planner's statistics won't be up to date. Is there an easy way to deal with this problem?
CodePudding user response:
Those are not the planner's statistics, those are the autovac launcher's statistics. The planner's statistics are in pg_statistic and friends, which are logged transactional tables and so are not lost on FO.
If a table was just about to be auto-analyzed before the FO, then it could undergo twice the normal activity between auto-analyzes. So yes, the planner stats can become slightly more out of date than they usually are. That generally won't be a problem, but if you are worried you can do a manual ANALYZE per db, or use vacuumdb
to do it.