Postgresql 18 Enables Statistics-Only Dev/Prod Plan Parity
Sources: 1 • Confidence: High • Updated: 2026-04-13 03:57
Key takeaways
- Database statistics dumps are typically under 1MB even for databases with hundreds of tables and thousands of columns.
- SQLite exposes query-planner statistics in a writable sqlite_stat1 table and optionally sqlite_stat4 (when compiled with SQLITE_ENABLE_STAT4), enabling injection of alternative statistics.
- Restoring column value-distribution statistics can change PostgreSQL plan selection, such as favoring an index for rare values and 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 Enables Statistics-Only Dev/Prod Plan Parity
- 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.
- PostgreSQL can copy production planner statistics into a development environment to simulate production query plans without copying production data.
Sqlite Supports Statistics Injection And Portable Performance Repros
- SQLite exposes query-planner statistics in a writable sqlite_stat1 table and optionally sqlite_stat4 (when compiled with SQLITE_ENABLE_STAT4), enabling injection of alternative statistics.
- SQLite documentation describes manually controlling query plans via sqlite_stat tables and fixing ANALYZE results.
- The SQLite CLI .fullschema command outputs both schema and sqlite_statN contents to help reproduce query problems without loading very large database files.
Planner Statistics Drive Execution-Plan Selection
- Restoring column value-distribution statistics can change PostgreSQL plan selection, such as favoring an index for rare values and 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 end-to-end procedure for exporting production statistics and restoring them into development for PostgreSQL 18, and what prerequisites must match (schema, versions, extensions)?
- Which specific classes of PostgreSQL planner statistics are restored by the new functions (e.g., per-relation, per-attribute, histograms, MCV lists), and what is not covered?
- How stable are statistics dumps over time, and how frequently would they need to be refreshed to remain representative of production query planning behavior?
- What are the security, privacy, and compliance implications of exporting and sharing statistics dumps, including whether they can leak sensitive distributional information?
- Under what build/runtime conditions is sqlite_stat4 available in deployed SQLite environments, and how often do real deployments include it?