Planner & statistics

pg_statistic and pg_stats

Also called: the statistics catalog, pg_stats view

pg_statistic is the system catalog where ANALYZE stores the statistical portrait of every column. pg_stats is a friendly view on top of it that you can actually read in plain SQL.

What this means

pg_statistic is the system table where ANALYZE stashes each column's statistical portrait, but it's kept in a raw, hard-to-read form. pg_stats is the human-readable view sitting on top of it, so you can just SELECT and actually see the common values and the histogram in plain SQL.

Why it matters operationally

This is where you look to see exactly what the planner believes about your data, null fraction, common values, histogram, n_distinct, correlation. Reading pg_stats is the fastest way to find the column whose bad statistics are causing a slow query.

Related & next

← All glossary terms · GUC reference · Error catalog