Rosa Del Mar

Daily Brief

Issue 68 2026-03-09

Postgresql 18 Enables Statistics-Only Dev/Prod Plan Parity

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

Investor overlay

Read-throughs

  • PostgreSQL ecosystem tooling could see demand for workflows that export production planner statistics and restore them in development to reproduce query plans without copying data, potentially easing performance debugging under data access constraints.
  • Managed database and observability providers may incorporate statistics export and restore features as a lighter alternative to production cloning for plan parity investigations, positioning statistics artifacts as part of incident response.
  • SQLite-focused developer tools could emphasize portable performance repros by packaging schema plus planner statistics, enabling smaller debug payloads that still reproduce query planning behavior.

What would confirm

  • Documentation and community guidance converges on a standard end to end procedure for PostgreSQL 18 statistics export and restore, including prerequisites like schema alignment and version compatibility.
  • Adoption signals appear in tooling releases or workflows that automate copying and applying relation and attribute statistics to reproduce production plans without data replication.
  • Security and compliance guidance clarifies whether statistics artifacts can leak sensitive distribution information and defines acceptable handling, enabling broader enterprise use.

What would kill

  • Statistics restore proves fragile in practice, requiring frequent refreshes or failing to reproduce production plans due to unhandled statistics types or environment differences.
  • Security or compliance concerns escalate, with evidence that statistics dumps leak sensitive distributional information, limiting sharing across environments.
  • PostgreSQL 18 functions restore only a narrow subset of planner statistics, so plan parity remains unreliable without copying data or using heavier production clones.

Sources