0PricingLogin
SQL Academy · Lesson

ANALYZE and pg_statistic

Keep planner statistics current with ANALYZE, inspect pg_statistic, and use extended statistics for correlated columns.

Why ANALYZE?

The query planner needs to estimate row counts and selectivities to pick a good plan. Those estimates come from per-column statistics gathered by ANALYZE.

When to Run ANALYZE

Autovacuum runs ANALYZE automatically based on row-change thresholds. After bulk loads or big DELETEs, run it manually so plans don't degrade:

ANALYZE orders;
ANALYZE (VERBOSE) orders;

All lessons in this course

  1. MVCC and Bloat Causes
  2. VACUUM, autovacuum, vacuum_cost_delay
  3. ANALYZE and pg_statistic
  4. Index-Only Scans and Visibility Map
← Back to SQL Academy