DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Query Tuning / Other Planner Options

default_statistics_target

Sets the default statistics target. This applies to table columns that have not had a column-specific target set via ALTER TABLE SET STATISTICS.

  • Default: 100
  • Type: integer
  • Range: 1 … 10000
  • Applies: Session (any user)

In plain words

ANALYZE reads a random sample of each table and records summaries the planner uses to estimate how many rows a condition matches. This number controls how detailed those summaries are. Higher means better estimates for skewed data, but slower ANALYZE and slightly slower planning.

For DBAs and operators

For a column with target N, ANALYZE samples 300 × N rows (30,000 at the default 100) and stores up to N most-common values with their frequencies and a histogram of up to N equal-frequency buckets (N+1 bounds) in pg_statistic. The table's sample size is driven by the largest target among its columns. Verified on 18.6: target 10 gave 3000 rows in sample and 11 histogram bounds; target 100 gave 30,000 rows and 101 bounds.

ANALYZE VERBOSE big1;
INFO:  "big1": scanned 4480 of 4480 pages, containing 1000000 live rows
       and 0 dead rows; 30000 rows in sample, 1000000 estimated total rows

Per column, override it with ALTER TABLE t ALTER COLUMN c SET STATISTICS 1000 (then ANALYZE): the usual fix for a skewed or highly clustered column whose estimates are badly off. Raising the global default makes every ANALYZE (including autovacuum's) read more, every pg_statistic row bigger and every planning a bit slower. The sample is random, so a value missed in the sample is estimated from the remaining fraction; check pg_stats (most_common_vals, histogram_bounds, n_distinct) when a plan misestimates. Correlated columns need extended statistics, not a higher target.

How to change it

Any user can change it for their session with SET.

See it in context

ANALYZE and statistics Planner cost model Autovacuum: when tables get vacuumed Life of a query

Related parameters

constraint_exclusion enable_nestloop cursor_tuple_fraction

All Query Tuning parameters