Rosa Del Mar

Daily Brief

Issue 68 2026-03-09

Postgresql 18 Statistics Restore Enables Production-Like Planning Without Production Data

Issue 68 Edition 2026-03-09 5 min read
General
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?

Investor overlay

Read-throughs

  • PostgreSQL 18 statistics restore could enable production like query plan debugging in non prod without copying data, potentially improving performance regression testing workflows if teams can move small stats dumps instead of large datasets.
  • SQLite writable planner statistics surfaces could support minimal reproducible planning bug reports by exporting schema plus stats, potentially improving developer tooling and support workflows around query optimization issues.

What would confirm

  • Documentation and examples showing end to end workflow for extracting and restoring PostgreSQL 18 planner statistics, including required privileges, tooling steps, and version compatibility limits.
  • Benchmarks or team case studies reporting higher query plan reproducibility and reduced debugging time when using restored statistics versus schema only environments.
  • Security guidance clarifying what information can be inferred from exported statistics and recommended mitigations for sharing stats outside production.

What would kill

  • Evidence that restored statistics rarely reproduces production query plans when configuration, versions, or other non captured factors differ, limiting practical value.
  • Findings that exported statistics materially leak sensitive distribution or cardinality information, making sharing impractical for many organizations.
  • SQLite sqlite_stat table behavior proves unstable across versions or build flags, or common deployments cannot safely write or rely on these tables.

Sources