Production query plans without production data

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Developers can now reproduce production query plans in test environments by copying tiny statistics files instead of cloning gigabytes of real data.

Read this as

PostgreSQL 18, released in September 2025, added two functions that copy the small internal notes the database uses to plan fast queries. Developers usually cannot recreate slow queries in test databases because test data looks different from live data. Now they can import just those notes, a text file under 1MB, instead of copying hundreds of gigabytes of production data. SQLite, a smaller database, already had the same trick.

Database teams spend time and infrastructure syncing production data into development environments just to debug slow queries, because query performance depends on data statistics that differ between environments. PostgreSQL 18's statistics-restore functions let teams replicate production query behavior with a text file under 1MB instead of a copy that may be hundreds of gigabytes. The payoff is faster debugging and lower data-transfer overhead; teams on older PostgreSQL versions gain nothing.

PostgreSQL 18 adds pg_restore_relation_stats() and pg_restore_attribute_stats(), which inject planner statistics such as null_frac, avg_width, n_distinct, and most_common_vals/freqs. An example marks a status column as 95% 'delivered', letting the planner choose an index scan for rare values and a sequential scan for common ones. Radim Marek notes statistics dumps for a database with hundreds of tables fit under 1MB. D. Richard Hipp confirmed SQLite offers the same via writable sqlite_stat1/sqlite_stat4 tables.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

PostgreSQL 18 SQLite sqlite_stat1 sqlite_stat4 .fullschema

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading