Catalogue / buildkite-2021-bigint-primary-key-migration

Buildkite moved a PostgreSQL table of over 2 billion rows from integer to bigint keys with a shadow column and no downtime

Buildkite. Core PostgreSQL database behind the Rails monolith.

Organisation
Buildkite
Evidence
Reported from production
Source
Avoiding integer overflows with zero downtime

Buildkite Blog, published 2021-03-25 (No date is printed; this is the first-published date in the page's own metadata, which also records an update on 2024-05-02.)

Records

Decision#d1

Widen an integer primary key by adding a bigint column, dual-writing with a trigger, backfilling and swapping

Decision#d2

Keep migrations from hurting production with concurrent index builds and a load-aware backfill

Decision#d3

Add NOT NULL through a validated CHECK constraint so PostgreSQL can skip the table scan

Sign in to read what was chosen, what was rejected and what it cost, each with its place in the source. An account is free. The job-queue cards are open without one.