Postgresql Planner-Statistics Restore Enables Production-Like Query Planning Without Production Data
Sources: 1 • Confidence: High • Updated: 2026-04-12 10:23
Key takeaways
- Radim Marek reports that database statistics dumps are typically under 1MB even for databases with hundreds of tables and thousands of columns.
- SQLite exposes query-planner statistics in the writable sqlite_stat1 table and optionally sqlite_stat4 (when compiled with SQLITE_ENABLE_STAT4), allowing users to inject alternative statistics.
- PostgreSQL 18 introduced the functions pg_restore_relation_stats() and pg_restore_attribute_stats() to restore planner statistics.
- Restoring column distribution statistics can change PostgreSQL plan selection such that rare values may use an index while common values may use a full table scan.
- PostgreSQL's query planner relies on internal statistics to choose an execution plan for a query.
Sections
Postgresql Planner-Statistics Restore Enables Production-Like Query Planning Without Production Data
- Radim Marek reports that database statistics dumps are typically under 1MB even for databases with hundreds of tables and thousands of columns.
- PostgreSQL 18 introduced the functions pg_restore_relation_stats() and pg_restore_attribute_stats() to restore planner statistics.
- Restoring column distribution statistics can change PostgreSQL plan selection such that rare values may use an index while common values may use a full table scan.
- PostgreSQL's query planner relies on internal statistics to choose an execution plan for a query.
- PostgreSQL's new features allow copying production statistics into development to simulate production query plans without copying production data.
Sqlite Supports Writable Planner-Statistics Tables And Minimal Repro Export Via Cli
- SQLite exposes query-planner statistics in the writable sqlite_stat1 table and optionally sqlite_stat4 (when compiled with SQLITE_ENABLE_STAT4), allowing users to inject alternative statistics.
- SQLite documentation describes manual control of query plans using sqlite_stat tables and the ability to fix ANALYZE results.
- The SQLite CLI .fullschema command outputs both schema and sqlite_statN contents to help reproduce query problems without loading multi-terabyte database files.
Unknowns
- What specific PostgreSQL objects and statistics are covered by pg_restore_relation_stats() and pg_restore_attribute_stats(), and what is excluded?
- What is the exact end-to-end workflow for exporting production statistics and restoring them safely into development (including any required privileges and operational steps)?
- Under what conditions does statistics-only replication fail to reproduce production query plans (e.g., which environment differences still matter)?
- How representative is the reported 'typically under 1MB' statistics-dump size across different workloads and schemas?
- For SQLite, what practical guidance exists for generating, validating, and safely modifying sqlite_stat1/sqlite_stat4 to reproduce or control planner behavior?