Postgresql 18 Statistics Restore Enables Production-Like Planning Without Production Data
Sources: 1 • Confidence: High • Updated: 2026-03-10 08:29
Key takeaways
- Database statistics dumps are typically under 1MB even for databases with hundreds of tables and thousands of columns, according to Radim Marek.
- 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.
- Restoring column statistics that encode skewed value distributions can change PostgreSQL plan selection, such as preferring an index for rare values but a full table scan for common values.
- PostgreSQL 18 introduced the functions pg_restore_relation_stats() and pg_restore_attribute_stats() to restore planner statistics.
- PostgreSQL's query planner relies on internal statistics to choose an execution plan for a query.
Sections
Postgresql 18 Statistics Restore Enables Production-Like Planning Without Production Data
- Database statistics dumps are typically under 1MB even for databases with hundreds of tables and thousands of columns, according to Radim Marek.
- PostgreSQL 18 introduced the functions pg_restore_relation_stats() and pg_restore_attribute_stats() to restore planner statistics.
- PostgreSQL's new statistics-restore features enable copying production statistics into development environments to simulate production query plans without copying production data.
Sqlite Provides Writable Planner Statistics Surfaces For Controlled Reproduction
- 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, including 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.
Planner Statistics As Primary Driver Of Plan Divergence
- Restoring column statistics that encode skewed value distributions can change PostgreSQL plan selection, such as preferring an index for rare values but a full table scan for common values.
- PostgreSQL's query planner relies on internal statistics to choose an execution plan for a query.
Unknowns
- What is the exact workflow and format for extracting production planner statistics and restoring them in PostgreSQL 18 (including permissions, tooling steps, and compatibility constraints)?
- To what extent does copying/restoring statistics alone reproduce production query plans when other factors (configuration, version, data shape beyond captured stats) differ?
- What sensitive information, if any, can be inferred from exported/restored statistics (e.g., distributional or cardinality leakage), and what mitigations are required?
- What measurable improvements (debugging time, reproducibility rate, performance regression detection) result from using restored/injected statistics in real teams?
- Under what conditions are SQLite’s sqlite_stat tables writable and stable across versions/build flags, and what safeguards exist to prevent accidental production misuse?