Company
Date Published
Author
Samuel Cochran
Word count
1005
Language
English
Hacker News points
None

Summary

Buildkite, a Rails-based application, faced the challenge of migrating its large PostgreSQL database from integer primary keys to bigint to prevent integer overflow, particularly in a critical table with over 2 billion rows. The team implemented a zero-downtime strategy by adding a new bigint column, writing to both the old and new columns simultaneously, and backfilling the bigint column in batches to minimize impact on production. This process involved creating triggers, using statement timeouts, and building indexes concurrently to avoid long transactions. After ensuring the new column's integrity with CHECK constraints, the final step involved swapping the columns and updating the primary key constraints, all while maintaining application functionality. With the primary table successfully migrated, attention turned to foreign keys and remaining tables, with plans to address these in future efforts.