Stale Query Statistics

Causes of slow queries.

Overview

Stale query statistics are one of the most common causes of suddenly slow queries in Postgres and other cost-based optimizers. The optimizer picks plans based on table statistics; when those statistics drift away from the actual data distribution, the optimizer chooses sequential scans where it should index, hash joins where it should nested-loop, and the query that was fast yesterday becomes pathological today. The fix is rarely a new index; it is making sure ANALYZE keeps pace with the writes.

The approach

The practical approach is per-table autovacuum tuning (lower thresholds for high-write tables), manual ANALYZE after bulk operations (do not wait for autovacuum), monitoring last_analyzed times so stale stats become visible before they cause incidents, raising statistics_target on skewed columns where the default sample misrepresents the distribution, and documenting the per-table analyze strategy so the next DBA inherits the model.

Why this compounds

Stats discipline compounds across queries and tables. Each well-tuned table preserves plan stability; each well-monitored table catches drift before it becomes an incident; the team builds a vocabulary for plan health that pays off on every new schema. Without the discipline, slow-query investigations re-derive the same lesson every quarter.

Stats discipline is a database discipline that pays off across years. Nova AI Ops integrates with database telemetry, surfaces stats freshness, and supports the team’s database engineering discipline.