The End of ANALYZE Hell: PostgreSQL 18's Statistics Preservation Story
summary
PostgreSQL 18 preserves optimizer statistics across major upgrades so you skip the long post-upgrade ANALYZE step: pg_upgrade calls built-in functions pg_restore_relation_stats and pg_restore_attribute_stats (and relies on pg_stats_export via pg_dump/restore) to reinsert table and column stats into catalogs; a complex query that falls from ~0.041 ms to 0.5 minutes without stats returns to ~0.44 ms with preservation; extended stats remain excluded but are handled by vacuumdb --missing-stats-only in milliseconds; tested up to 500 GB with no significant extra upgrade time.
AI-written summary · about
chapters (8)
- 0:00Introduction and motivation
- 2:33Old PG upgrade behavior
- 9:01Vacuum vs analyze explained
- 12:39PostgreSQL 18's new feature
- 17:30Statistics preservation details
- 22:27Performance comparison demo
- 24:16Missing stats only flag
- 25:17Conclusion and benefits
related talks
31mpg_stat_advisor: Optimizing PostgreSQL Planner with Insights
46mAn ultimate guide to upgrading your PostgreSQL installation
50mAn ultimate guide to upgrading your PostgreSQL installation
26mpg_stats: How Postgres Internal Stats Work
25mPoint-in-time query tuning and observability with pg_stat_statements
26mPostgreSQL 17 vs 18: Side‑by‑Side Performance Wins in Real‑World Queries
50mPerformance Archaeology
29mPerformance Archaeology - 20 years of improvements
