Skip to content

.tip

· one of the small things

A BRIN index for append-only time series

Events inserted in time order sit in time order on disk too. A B-tree on the timestamp indexes every row. A BRIN indexes ranges of pages instead, so it's a few hundred kilobytes for a table of hundreds of gigabytes, and a date range query skips almost everything.

CREATE INDEX events_ts ON events USING brin (created_at);

It's the wrong choice for tables that get updated in place, and the right one for logs, events and metrics.

postgresqlperformance

Longer version: the post this came from.