Cookbook recipe

BRIN indexes for huge append-only tables

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

A billion-row time-series table cannot afford a b-tree the size of the data. A BRIN index summarizes block ranges and is thousands of times smaller. Diagnose it Build a BRIN on the naturally-ordered column: CREATE INDEX…

Investigation Path

A billion-row time-series table cannot afford a b-tree the size of the data. A BRIN index summarizes block ranges and is thousands of times smaller.

Diagnose it

Build a BRIN on the naturally-ordered column:

CREATE INDEX idx_metrics_brin
  ON metrics USING brin (recorded_at)
  WITH (pages_per_range = 128);

Why it happens

BRIN stores the min/max of a column per block range. When data is physically ordered (append-only by time), the planner skips entire ranges that cannot match, scanning only relevant blocks — at a fraction of a b-tree size.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes