Portable Statistics in PostgreSQL 18

Portable Statistics in PostgreSQL 18

Portable Statistics in PostgreSQL 18

Original URL: https://boringsql.com/posts/portable-stats/

Article Written: March 8, 2026

Added: June 11, 2026

Type: tech2

Summary

The article discusses the new features in PostgreSQL 18 that allow for the export and import of optimizer statistics, enabling developers to replicate production query plans in non-production environments. It introduces two key functions, pg_restore_relation_stats and pg_restore_attribute_stats, which allow users to inject production-like statistics into test databases. This capability is particularly useful for CI pipelines and debugging, as it helps maintain consistency in query planning across different environments. The article also highlights the importance of column-level statistics in influencing query plans and provides practical examples of how to use these functions effectively.