Skip to main content

Zero-Downtime Database Migrations for PostgreSQL

Practical techniques for changing schemas on busy PostgreSQL databases without taking the app down, including expand-and-contract, online DDL, and safe backfills.

advanced
Database Operations

Zero-Downtime Database Migrations for PostgreSQL

Practical techniques for changing schemas on busy PostgreSQL databases without taking the app down, including expand-and-contract, online DDL, and safe backfills.

17 cards
22 minutes
1 / 17
0% Known
0
? 0
Card 1 of 17
Fundamentals
Swipe left/right to navigate cards
Question

Why do schema migrations on a busy PostgreSQL table often cause outages even when the change looks small?

Tap to reveal
Answer

Most `ALTER TABLE` statements take an `ACCESS EXCLUSIVE` lock. That blocks every read and write until the migration finishes. On a hot table, even a 200ms lock can pile up thousands of waiting queries, exhaust the connection pool, and take the app down. The migration itself runs fine. The queue of blocked queries is what breaks production.

postgresql
database-migrations
zero-downtime
Sponsored
Carbon Ads