GoCardless Postgres migration drops foreign keys causing production timeouts

thetshaped.dev9 min read

Schema migrations in PostgreSQL can cause unexpected production outages even when the tables are small or empty, due to lock queues that block subsequent queries. The author explains how strong locks like ACCESS EXCLUSIVE interact with long-running transactions and details five dangerous schema changes, offering safer alternative patterns such as setting lock timeouts, splitting constraints into NOT VALID and VALIDATE steps, and running backfills in batched jobs. Open article →