Batched Backfills: Updating Millions of Rows Safely
Updating millions of rows in one giant statement looks tidy but behaves badly: it locks rows for a long time, bloats the table, and can run for hours.
The safer way is to do the work in small batches, a few thousand rows at a time, so the database keeps breathing while the change rolls through.
Pro members see the rest of this lesson
- A 4-step state diagram: Naive → Stall → Batch → Resume
- The full mechanism: what PostgreSQL does internally, in source terms
- 1 SQL query you can run, each labelled by how it was verified
- 1 transcript captured on PostgreSQL 17.10
- The closing insight, the mistake it prevents, and what it changes in your work
Card required. Cancel before day 7 and you are not charged.
Anchored to postgres/postgres on REL_17_STABLE and cross-checked against the manual for PostgreSQL 15–18. Every query here was run and its output captured on a throwaway PostgreSQL 17.10 lab; corrections are noted inline. UPDATE in the official docs →
Connected
Where this lesson sits
What comes before, after, and alongside it.
Finished a free lesson?
Pro opens the rest of the engine course
You felt one mechanism. Pro is the full bodies, interview depth, and the tracks that build on this session.