BRIN index

Also known as: Block Range Index · BRIN

On this page 7

A BRIN index, short for Block Range Index, is a compact secondary index that stores a small summary per range of physical table blocks, typically the minimum and maximum value of the indexed column, instead of one entry per row. In database indexing, BRIN is designed for very large tables whose physical row order correlates with column values, such as append-only event logs keyed by timestamp.

PostgreSQL introduced BRIN in version 9.5, and comparable ideas exist elsewhere as zone maps, storage indexes and min-max skipping in columnar formats. The approach trades precision for size: a BRIN index can be hundreds or thousands of times smaller than a B-tree index on the same column, but it only narrows a search to candidate block ranges, which must then be scanned and rechecked.

How a BRIN index summarizes block ranges

A BRIN index works by dividing the table heap into consecutive block ranges and storing one summary tuple for each range. In PostgreSQL the range size is set by the storage parameter pages_per_range, which defaults to 128 pages of 8 kB, or about 1 MB of heap per summary entry.

For the default minmax operator class, each summary records the lowest and highest value found in its range. When a query asks for created_at BETWEEN '2026-03-01' AND '2026-03-02', the executor compares the predicate with every summary and builds a lossy bitmap of matching ranges. A bitmap heap scan then reads only those ranges and rechecks every row against the original condition, because a range that overlaps the predicate may still contain many rows outside it.

The structure itself has three parts, shown below. Because the summaries are tiny and few, the whole index often fits in a handful of pages and stays permanently in memory.

ComponentRoleTypical size
MetapageStores version and pages_per_range settingOne page
Range map (revmap)Maps each block range to its summary tupleA few pages per million blocks
Summary tuplesHold min-max or other summary valuesTens of bytes per range
Internal components of a BRIN index

Why physical correlation decides BRIN effectiveness

A BRIN index is only selective when values that are close in the column are also close on disk. Planner statistics express this as correlation, a value between -1 and 1 that measures how closely physical row order follows logical value order. Values near 1 or -1 produce narrow, non-overlapping ranges; values near 0 produce ranges whose min-max spans cover almost the entire domain, so nearly every range matches every query.

Correlation arises naturally in append-only workloads: sensor readings, financial ticks, audit logs and clickstream data are inserted roughly in time order. It degrades when updates create new row versions in free space elsewhere, when bulk loads arrive unsorted, or when VACUUM frees space that later inserts reuse out of order.

Column patternTypical correlationBRIN usefulness
Insert timestamp on append-only logClose to 1.0Excellent
Monotonic sequence identifierClose to 1.0Excellent
Order date with late corrections0.8 to 0.95Good, with some extra reads
Customer identifier in an order tableNear 0Poor, almost no pruning
Frequently updated status columnNear 0Unsuitable
Column patterns and expected BRIN usefulness

BRIN compared with other index types

BRIN complements rather than replaces the B-tree index. A B-tree stores every key with a pointer to its row and answers point lookups in a few page reads, while BRIN stores only range summaries and answers range predicates over huge, ordered data at a fraction of the storage and maintenance cost. Neighboring structures such as the GIN index and GiST index solve different problems, namely multi-valued containment and geometric or nearest-neighbor search.

Index typeGranularityRelative sizeBest fit
BRINOne summary per block rangeVery smallRange scans on correlated columns
B-treeOne entry per rowLargeEquality, sorting, selective ranges
HashOne entry per rowMediumEquality only
GINOne entry per contained elementLargeArrays, JSON, full-text search
PartitioningOne partition per key rangeNo index storagePruning plus data lifecycle management
BRIN index versus related index types

BRIN cannot enforce uniqueness, cannot return rows in index order and cannot support an index-only scan, because it never stores individual keys. It also gives the query planner only a rough cost estimate, so an explain plan with buffer counts is the reliable way to confirm a benefit.

Operator classes and tuning parameters

The behavior of a BRIN index is shaped by its operator class and a few storage parameters. Since PostgreSQL 14, the minmax-multi class keeps several smaller intervals per range, which tolerates outliers and moderately unsorted data, and the bloom class stores a Bloom filter that supports equality lookups on columns without useful ordering. The inclusion class summarizes geometric and network types with a bounding value.

SettingEffectTrade-off
pages_per_rangeSets how many heap pages share one summarySmaller values prune better but enlarge the index
autosummarizeSummarizes new ranges after they fillAdds background work for autovacuum
minmax-multi operator classStores multiple intervals per rangeLarger summaries, better outlier tolerance
bloom operator classSupports equality on unordered valuesProbabilistic false positives, no range queries
Main BRIN tuning options in PostgreSQL

A practical starting point is the default range size, followed by measurement. Lowering pages_per_range to 16 or 32 often reduces the number of heap pages read for narrow time windows, while the index remains small by B-tree standards.

Maintenance, limitations and common mistakes

New rows appended beyond the last summarized range are not covered until summarization runs, either through autovacuum, the autosummarize option or an explicit call to brin_summarize_new_values(). Unsummarized ranges are always treated as matches, so queries stay correct but scan more data. Deleting rows does not narrow an existing summary; summaries only widen until a range is desummarized and rebuilt.

  • Indexing an uncorrelated column produces an index the planner uses but that prunes almost nothing.
  • Expecting point-lookup speed ignores the recheck cost of reading whole 1 MB ranges.
  • Large unsorted bulk loads widen many summaries at once; sorting before loading preserves pruning.
  • Heavy updates scatter new row versions and erode correlation over time.

In plain words

Picture a long shelf of diaries kept in date order. Instead of listing every entry, a sticky note on each box says which dates it covers, from the first day to the last. To find March entries, you open only the boxes whose notes include March.

A BRIN index is that set of sticky notes for a database table. It is tiny and cheap to keep, but it only works well when the data really sits in order. If the diaries are shuffled, every note covers the whole year and helps nobody.

A real-world example

An industrial monitoring team stores readings from 40,000 sensors in a PostgreSQL table that grows by about two billion rows per month. Rows arrive in timestamp order, and engineers usually query a single sensor group over a few hours. A B-tree index on the timestamp column had grown to roughly 60 GB and slowed every insert.

The team replaced it with a BRIN index on the timestamp using pages_per_range = 32. The new index occupies under 10 MB, insert throughput rises noticeably, and typical six-hour queries read only the matching block ranges. Queries by sensor identifier still use a separate B-tree, so each index serves the access pattern it fits.