PostgreSQL

Statistics cached for transaction duration causing stale data

warning
monitoringUpdated Feb 26, 2026
Technologies:
How to detect:

Statistics values are cached until the end of the current transaction by default. Long-running transactions will see static statistics even as actual database activity continues. Time delta between accessing different statistics can cause significant skew in cached values.

Recommended action:

For interactive analysis or expensive queries, set stats_fetch_consistency to 'snapshot' to minimize skew (with increased memory usage) or 'none' if statistics are only accessed once. Call pg_stat_clear_snapshot() to discard cached values within a transaction and force fresh data retrieval.