Stage 4 · Reliability · Medium · 14 min
Changing a database table without downtime
How to rename a column on a table that a live app is using. It takes six small steps, each safe beside the code that is already running.
What each interview level is expected to know
Learn first: Choosing a database and modelling data, CI/CD and safe deployments
After this lesson you can:
- Rename a live column in six safe steps, each working beside the running code.
- Explain why the old rows must be copied before reads move to the new column.
- Spot the step that breaks if it runs too early or is skipped.
Start here
See it in 60 seconds
Rename a column while the app runs
One rename breaks the running code, so the safe way adds a second column and moves over in six small steps.
Scene 1 of 7 · Rename in one step
The column becomes full_name, so every request from the old code for name fails.
- Old code — reads name — FAILED — writes name
- No release now — nothing being shipped — IDLE — not running
- users table — healthy — columns: id, full_name
| User | name | full_name |
|---|---|---|
| Asha | no column | Asha |
| Ben | no column | Ben |
- Requests failed
- 3
- Names shown blank
- 0
- Names lost for good
- 0
- Rename in one step. The column becomes full_name, so every request from the old code for name fails.
- Add, do not rename. Start again: keep name, add an empty full_name beside it, and the old code still works.
- Write to both. A release ships code that writes each new name to both columns.
- Copy the old rows. A copy job fills full_name in the older rows, such as those of Asha and Ben.
- Read the new column. The next release reads full_name, and still writes both for the older code beside it.
- Stop the old writes. The release after that writes only full_name, and once it is out, no running code uses name.
- Remove the old column. Only now is name removed, and not one request failed on the way.
- Now you try. Run the six steps again, but skip one. Which step do you skip? For example: No request fails, but names show blank 16 times, and 4 names are lost for good. Rows from before the double write have an empty full_name, and reading an empty cell is not an error.
Scene 1 of 7: Rename in one step. The column becomes full_name, so every request from the old code for name fails.
Key points
- During every release, two versions of the code share one table.
- Add the new column first, and remove the old one last.
- The code must write both columns before the copy runs.
- A skipped step may give no error, only blank or lost names.
Go deeper in the Table change: rename a column with no downtime lab →
In plain words
Say a table called users has a column called name, and the team wants to call it full_name. The app is live, and its code reads and writes name all day. If you rename the column in one step, the running code asks for a column that is gone, and its requests fail. The safe way is to add before you remove. Add full_name beside name. Change the code in small releases until nothing uses name. Then remove name. For a while the table holds both columns, so old code and new code can both work. This method is often called (A way to change a table that is in use. First add the new column beside the old one, then move the code over, then remove the old column.).
In practice the rename takes five releases. First, add full_name, empty. Next, make the code write to both columns. Then copy the old values across in small batches, so the table is never locked for long. After that, switch reads to full_name and stop writing name. Last, drop name.
The problem it solves
Shipping new code takes time. For some minutes, old code and new code run side by side on one table. So there is no single moment when you can change the table and all the code together. A change that suits the new code breaks the old code, and the other way round. The worst faults give no error at all: a page shows a blank name, and nobody is told.
Why it matters
Almost every feature changes a table sooner or later: a new column, a new name, a new type. The app cannot stop while that happens. An interviewer who asks "how would you change this table?" wants the order of the steps, and what each step protects.
A worked example
Say 4 users signed up through code that wrote only the old column: Asha, Ben, Chen and Dina. The plan skips the step that copies old rows. Later sign-ups are written to both columns, so they look right. Then the code starts to read full_name. Those 4 users show a blank name, and no error appears. When the old column is removed, their 4 names are gone for good.
Think of it like…
Think of a shop that moves to a new street. It opens the new shop first, puts a sign on the old door, and moves the stock over. It closes the old shop only when no customer comes there any more.
Where this analogy stops working
Opening the new before you close the old is the useful part. But a customer can read the sign and walk over. Old code cannot: it keeps asking for the old column until someone ships new code. So the old column must stay until no running code uses it.
Try it
See it working
Also try: Deployments · Replication
Mechanics
How it works
The pictures follow this page's example: the users table, where name becomes full_name while the app is live. They show the first step, the (A job that fills in a new column or table for the rows that already exist. On a large table it runs in small batches.) and the last step, where most mistakes happen.
Add the new column
Pick a case to follow belowWith this case: Renaming in one step broke the running code at once: it asked for name, and name was gone.
Running code, serves users Running code serves users users table, the live table, NOW users table the live table full_name only NOW - Running code — serves users — healthy
- users table — the live table — healthy — NOW — full_name only
- Error
Step 1 of 2Step 1 of 2 · users table
Watch: The column name is renamed to full_name
- What happens
- One command renames the column in the table.
- Why
- It looks like the quickest way to make the change.
- What changes
- The running code was not changed, and it still asks for name.
- Next
- The running code asks for name, and gets an error
Columnsfull_nameRunning code usesnameRequestsworkingusers are servedStep 1 of 2: users table. The column name is renamed to full_name. One command renames the column in the table.
Add full_name to the table, empty in every row. The old code never asks for it, so nothing changes for users. This is the expand half: the table grows first.
In the picture, a one-step rename breaks the running code at once: its queries ask for name, and name is gone.
Adding full_name beside name changes nothing for that code, so users see no errors.
Write to both columns
Ship code that writes each new name to name and to full_name. It still reads name. Once this release has finished, every new row is right in both columns.
Copy the old rows
Pick a case to follow belowWith this case: With no backfill, the page for user:7 showed a blank name, and no error was raised anywhere.
Running code, serves users Running code serves users users table, the live table, NOW users table the live table user:7: empty NOW Backfill job, 1,000 rows at a time Backfill job 1,000 rows at a time - Running code — serves users — healthy
- users table — the live table — healthy — NOW — user:7: empty
- Backfill job — 1,000 rows at a time — healthy
- Rows
Step 1 of 2Step 1 of 2 · users table
Watch: user:7 has an empty full_name
- What happens
- user:42 signed up after the code began writing both columns, so it has both. user:7 is older.
- Why
- Writing both columns only fixes rows written from then on.
- What changes
- Nothing copies the old rows.
- Next
- The page for user:7 shows a blank name
user:7 full_nameemptyWatch: saved before step 2user:42 full_nameLeo Parkwritten to both columnsPage for user:7 shows–not read yetStep 1 of 2: users table. user:7 has an empty full_name. user:42 signed up after the code began writing both columns, so it has both. user:7 is older.
Rows from before step 2 still have an empty full_name. A copy job fills them from name. This is called a backfill. On a large table it runs in small batches, such as 1,000 rows at a time, so the live app stays fast.
In the picture, user:7 signed up before the code wrote both columns, so its full_name is empty. Without a backfill, code that reads full_name shows a blank name, and no error is raised anywhere.
With the backfill run first, the page shows "Asha Rao".
Read the new column
Ship code that reads full_name. It still writes both columns, because the release before it still reads name. While this release goes out, both versions run side by side and both see every name.
Stop writing the old column
Ship code that writes only full_name. When this release has finished, no running code reads or writes name.
Remove the old column
Pick a case to follow belowWith this case: Removing name while the code still wrote it made every sign-up fail.
Running code, serves users, NOW Running code serves users writes both NOW users table, the live table users table the live table - Running code — serves users — healthy — NOW — writes both
- users table — the live table — healthy
- Query
- Error
Step 1 of 3Step 1 of 3 · Running code
Done: The running code still writes both columns
- What happens
- The release that reads full_name is live. It still writes name, for the release before it.
- Why
- Step 5 has not shipped yet.
- What changes
- The team removes name.
- Next
- The column name is removed
Running code writesname + full_nameColumnsname, full_nameSign-upsworkingnew users can joinStep 1 of 3: Running code. The running code still writes both columns. The release that reads full_name is live. It still writes name, for the release before it.
What these pictures simplify. These pictures use two rows and stated releases. A real table may hold millions of rows, and adding a column can lock the table on some databases and versions. The table change lab above runs all six steps.
Remove name from the table. This is the contract half, and it cannot be undone. Many teams wait some days first, and check that nothing has read the column.
In the picture, removing name while the running code still writes it makes every sign-up fail. Removing it after step 5 has finished changes nothing for users.
Use it when
- Any change that running code would notice: a renamed column, a changed type, one column split in two, or one table split in two.
- Any table too large to change in one quick step, where a lock would stop the app.
Skip it when
- A new column that no code uses yet: add it in one step, and ship the code that uses it after.
- A system that can stop for a planned window, such as an office tool used only in the day. One step in the window is cheaper.
- A feature that has no real data yet: change its table freely until real users arrive.
Check yourself
Judgement
Trade-offs and how it fails
What you give up
- Speed
- One rename is one step and takes seconds, but the running code fails until the new code has replaced it.
- Safety
- Six steps break nothing, and the first four can be undone at once. The price is three releases, a copy job, and a table that holds the names twice for a while.
Failure modes
- A skipped copy: no request fails, but old rows show a blank name. In the lab, 4 names are lost when the old column goes.
- A copy that runs too early: code that still writes only the old column adds rows behind the copy. In the lab, 2 names are missed.
- An old column removed too soon: code that still writes it fails on every sign-up.
- A copy in one big step: it locks or slows a large table, and the live app times out.
- A copy that overwrites: it must fill only empty cells, or it can put an older name over a newer one.
In the real world
- GitHub built gh-ost to change large MySQL tables. It copies the rows into a new table in small batches, then swaps the two tables.
- Stripe has described moving data in four stages: write to both places, change the reads, change the writes, then remove the old data.
- PostgreSQL 11 and later can add a column with a fixed default value without rewriting the table. Older versions rewrote every row. Source: PostgreSQL 11 release notes (checked 14 October 2026)
- Tools such as Flyway and Liquibase keep every table change in files stored with the code, and run the changes in a fixed order.
Trade-offs to be ready to discuss: One step vs six steps · Backfill speed vs load
Check yourself
Interview
What interviewers look for
- Say the rule first: add before you remove, and each release must work beside the one before it.
- For a large table, say that the copy runs in small batches and can be paused.
- Say what going back costs. Up to step 4 it is one (Undoing a change to return to the last good state. A release rollback puts the previous version back. A transaction rollback cancels its writes.). After step 5 the old column is out of date, and after step 6 it is gone.
- The same rule holds for messages and API fields. The API styles page shows it in "Changing a record without breaking readers".
Say it out loud: Why must the code write to both columns before the copy runs, and not after?
Expected depth by interview level
Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.
- JuniorUseful
- Why one rename breaks running code, and the rule: add before you remove.
- MidExpected
- The six steps for a rename, and what each skipped step costs.
- SeniorExpected
- A change plan for a large table: batches, a check between steps, and how to go back.
- StaffExpected
- Table changes across teams: who reads a column, how long old code lives, and what a failed step costs.
Practice
Apply it
Three harder questions
The first two use the idea on a new case. The last asks you to judge a design.
Apply it
Apply it
Judge a design
Go deeper
Sources and further reading
First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Engineering guideParallelChangeMartin Fowler (Danilo Sato)Expand, migrate, contract: changing an interface in steps so old and new callers both work.
- Engineering guideEvolutionary Database DesignSadalage and FowlerSmall, versioned database changes that ship with the code that needs them.
- Official docsCREATE INDEXPostgreSQL documentationBuilding an index CONCURRENTLY so writes are not blocked, and its caveats.