Zero-downtime Postgres migrations on Kubernetes

Zero-downtime Postgres migrations on Kubernetes

Four-phase migration timeline next to a Kubernetes rollout

Building something like this? Book a free discovery call.

Most outages we get called in to fix don't start with a traffic spike. They start with a schema change that looked harmless in review: a renamed column, a new NOT NULL constraint, an index built on a busy table. On Kubernetes, rolling deploys make this harder, because for a few minutes the old and new versions of a service run side by side against the same database.

Expand, then contract

We split every breaking change into steps that each stay compatible with the code running next to them. First we expand: add the new column as nullable, or create the new table, without touching anything that already exists. Then we ship code that writes to both shapes and still reads the old one.

Backfill in small batches

Backfills run as a separate job, a few thousand rows at a time, with a short pause between batches. One large UPDATE holds locks, inflates the write-ahead log, and leaves replicas behind. Small batches look slower on paper. In practice they finish sooner, because nothing has to be rolled back.

Switch, verify, then clean up

When the backfill is done, we move reads to the new column behind a flag and watch error rates and query plans for a full business cycle. The old column is dropped in a later release, not the same one. Indexes are built with CREATE INDEX CONCURRENTLY, and every migration sets a lock timeout, so a blocked statement fails fast instead of queueing the whole application behind it.

None of this is exotic. It is a checklist enforced in CI, and it is the difference between a migration nobody notices and a Friday-night incident.

Vedison logo

Pouya Vedadiyan

Founder, Vedison