Database migration strategies: zero downtime, table by table
Four ways to move a production database: what each costs in downtime, rollback and code changes, and how a table-by-table migration through a federated query engine runs. With a PostgreSQL logical replication example, a dual-write code smell and a checklist.
On this page
- Short answer: four database migration strategies compared
- Why migrations drag on for years
- Big bang: dump, restore, switch
- Replica and cutover: replicate, drain, switch
- Dual writes: how they work and where they break
- Table by table through a federated query engine
- Example: a fintech migration of 80–100 TB
- Database migration best practices
- Checklist before you start
- FAQ
- Next step
A zero downtime migration is a database migration plan where the application keeps serving while the data moves. Most of the risk sits in the moment you switch reads and writes, and in the rollback if that switch goes wrong.
This guide compares four database migration strategies. Three are classic: big bang, replica with cutover, and dual writes in the application. The fourth moves one table at a time behind a federated query engine, so the application never sees two databases. For the PostgreSQL to MariaDB product page, see gradual database migration.
Short answer: four database migration strategies compared
| Strategy | Downtime window | Rollback | App changes | Fits when |
|---|---|---|---|---|
| Big bang (dump, restore, switch) | Hours. Writes stop for the whole copy. | Restore the old database. Later writes are lost. | One connection string, once. | Small databases, a maintenance window allowed. |
| Replica and cutover (CDC, then switch) | Minutes. Stop writes, drain, switch. | Only with reverse replication set up before cutover. | One connection string, once. | Same engine family, or a target your CDC tool supports. |
| Dual writes in the application | Seconds per service. | Point reads back at the old database. | Every write path in every service. | Few write paths, one team. |
| Table by table through a federated query engine | None. Each service redeploys once. | Until promotion, the old database stays default. | One connection string per service. | Large databases, many services, a dialect change. |
The first two move everything at once. The last two move the data in smaller pieces, with the dual writes either in your application code or in the engine.
Why migrations drag on for years
The application is tied to one connection string. Every service, cron job and report points at one host. Switching a hundred callers at the same moment is much harder than copying the data, so the team waits for a window where all of them can switch, and that window keeps slipping.
Data changes during the copy. A 10 TB copy takes hours, and an 80 TB copy takes days. Writes keep landing on the old database the whole time. Without change data capture (CDC), the copy is stale before it finishes.
Every query needs dialect tuning. PostgreSQL and MariaDB differ in functions, JSON operators and upserts. With a one-shot switch, every query has to be rewritten before day one. In a table-by-table move, the rewrites can spread over months.
Big bang: dump, restore, switch
How it works: stop writes, dump the old database, restore it into the new one, switch the connection string.
Where it breaks: the downtime window grows with data size, and so does the chance of a failure at hour six. If a bug shows up on Monday, rollback loses the weekend’s writes.
Downtime window: hours. Use it for databases small enough to copy in one night.
Replica and cutover: replicate, drain, switch
How it works: the new database becomes a live replica of the old one. A snapshot copies existing rows; CDC then streams every change from the source transaction log. When the replica catches up, you stop writes, drain the last changes, and switch the application.
Within one engine family this is built in. PostgreSQL logical replication snapshots each table on the publisher, copies it to the subscriber, then sends changes continually in order. The minimum setup:
-- postgresql.conf on the old server: wal_level = logical
-- old database (publisher)
CREATE PUBLICATION mig_pub FOR TABLE orders, customers;
-- new database (subscriber)
CREATE SUBSCRIPTION mig_sub
CONNECTION 'dbname=app host=old-db user=repuser'
PUBLICATION mig_pub;
-- cutover, once lag is zero:
-- 1. stop writes on the old database
-- 2. wait for the last change to apply
-- 3. set sequences on the new database
-- 4. point the application at the new database
-- 5. DROP SUBSCRIPTION mig_subWhere it breaks, per the PostgreSQL documentation: schema and DDL are not replicated, so tables must exist on the subscriber first. Sequence data is not replicated, so serial columns restart unless you set them before the switch. Large objects and views are not replicated. Writes to the subscriber during replication can cause conflicts.
Across engine families you need an external CDC tool. AWS DMS, for example, runs “full load plus CDC” and uses logical replication slots on a PostgreSQL source. Its documentation says CDC “does not provide real-time replication” and has “no SLAs for CDC latency”. MariaDB replication stays inside its family: updates go to the binary log, and MariaDB replicas read it.
Downtime window: minutes. Rollback after the switch is the weak point. Writes now land on the new database, and going back without losing them requires reverse replication running before you cut over. Few teams set that up.
Dual writes: how they work and where they break
How it works: the application writes every change to both databases. Reads stay on the old one. A backfill job copies the historical rows. When the copies match, reads move to the new database and the old write is removed.
Dual writes need no CDC tool and no replication slot. But every write path in every service now does two writes, and that is a code smell:
def create_order(order):
old_db.insert("orders", order)
try:
new_db.insert("orders", order)
except Exception as e:
log.warning("dual write failed: %s", e)
# the copies now differ, and nothing will fix thatWhere it breaks:
- Partial failure. The first write commits, the second fails. There is no transaction across two databases, so the copies drift.
- Ordering. Two service instances update the same row. The updates land in one order on the old database and the other order on the new.
- Deletes during backfill. The backfill copies a row after the app deleted it, and the row comes back. Timescale’s dual-write guide limits the method to append-only writes for this reason.
- Coverage. A batch job or trigger you forgot never dual-writes. The drift shows up weeks later.
Downtime window: none for the database. Rollback is simple while both writes run: point reads back at the old database. Most of the cost is engineering time across every service.
Table by table through a federated query engine
The fourth strategy moves the dual writes out of the application and into a federated query engine that sits between the services and both databases. The application sees one SQL endpoint, and the engine decides per table which database answers. See what a federated query engine is.
Otterstax is an open-source federated query engine for MariaDB, PostgreSQL, ClickHouse, S3 and Kafka. Applications connect with their existing MariaDB / MySQL or PostgreSQL driver. CDC with guarantees and cross-database transactions are (Enterprise) features. A gradual migration runs in five steps.
1. Connect both databases. Add the old database and the new one to the engine. The old database stays the default for every query.
2. Switch services to the engine. Each service changes only its connection string. Queries still go to the old database.
3. Copy one table and keep it in sync. The engine copies the table to the new database. CDC and dual writes keep both copies current. Row counts confirm they match.
4. Promote the table. When related tables and queries are ready, the table moves to the new database. Your DBA team decides when. In the fintech case this took about 2–4 weeks per table.
5. Repeat, then retire the old database. The team rewrites queries for the new dialect at its own pace. When the last table moves, the old database is switched off.
If something goes wrong
Until a table is promoted, the old database stays the default and receives every write. If checks on the new copy fail, you stop the move. Queries keep going to the old database, and the application notices nothing. Each table moves on its own, so a problem with one table does not block the rest. Ask your vendor how a promoted table goes back.
A JOIN between a table in the old database and one in the new is slow, because intermediate rows cross the network. Move joined tables close in time. More in cross-database JOINs.
Example: a fintech migration of 80–100 TB
A fintech company ran a payments platform on PostgreSQL 12. The main service held 80–100 TB, with a 99.95% availability requirement. The team estimated an in-place PostgreSQL upgrade at about 2 years.
They moved to MariaDB 11 table by table through Otterstax instead. PostgreSQL stayed the default until each object was promoted. CDC and dual writes kept the copies in sync, and row counts confirmed they matched. Objects with few dependencies moved first, at about 2–4 weeks each. The migration finished in about a year. The worst-case forecast was 18 months. Migration TCO came in at −23%, against a projected 25%, covering infrastructure, operations, instance sizes, storage and engineering time. The hard parts were SQL dialect differences and JOINs across data split between the two databases. Source: case study on mariadb.org.
Database migration best practices
- Decide the downtime budget first. Google Cloud’s migration guide says a switch with no downtime at all is impossible, so aim for a small window. Write the number down and choose the strategy from it.
- Use CDC from the transaction log. Log-based CDC sees every change, including jobs you forgot. Timestamp polling misses deletes.
- Verify before every switch. Compare row counts per table at minimum, and checksums on a sample if you can.
- Rehearse the rollback. Run the rollback procedure at least once before you need it.
Checklist before you start
A database migration checklist for step one:
- Downtime budget agreed with the business, in minutes.
- Inventory of every caller: services, cron jobs, reports, BI tools, triggers.
- Tables sorted by dependencies, with foreign keys mapped. Start with the ones few others depend on.
- Schema created on the target by hand, including indexes and sequences. No replication method moves DDL.
- Network access to both databases, with a user that can read and write the tables you move.
- CDC enabled on the source:
wal_level = logicalfor PostgreSQL, row-based binary logging for MariaDB / MySQL. - A consistency check you can run on demand, for example row counts per table.
- Queries with dialect-specific features listed: JSON operators, upserts, pgvector.
- A rollback procedure, written down and tested once.
FAQ
How long does a zero downtime migration take?
It depends on data size, the number of tables and how many queries need a rewrite. A big bang on a small database takes one night. In the fintech case above, 80–100 TB took about a year at 2–4 weeks per table. Query rewrites set the pace.
Can you roll back?
Before the switch, yes, in every strategy. After it, it depends. Big bang restores a backup and loses later writes. Replica and cutover needs reverse replication set up in advance. Table by table, the old database stays default until a table is promoted, so stopping a move costs nothing. Ask your vendor how a promoted table goes back.
What about foreign keys between tables that now live in different databases?
A foreign key cannot point at a table in another database, so it is not enforced during the move. Handle it with ordering: move tables that reference each other close together, or in one step. A federated query engine still runs JOINs across both databases, so reads keep working. Constraint checks sit in the application until both tables are on one side.
Does the application need code changes?
Big bang and replica with cutover: one connection string, plus every query in the old dialect. Dual writes in the application: every write path in every service. Table by table through a federated query engine: one connection string per service. Otterstax speaks the MariaDB / MySQL and PostgreSQL wire protocols, so drivers and ORMs stay.
Next step
The Otterstax quickstart runs one process locally with a demo MariaDB and ClickHouse in about five minutes. Run the quickstart →
Planning a migration of more than a few terabytes? Book a 30-minute pilot call →
Sources
- PostgreSQL 18: Chapter 29. Logical Replication — checked 30.10.2026
- PostgreSQL 18: 29.8. Restrictions — checked 30.10.2026
- PostgreSQL 18: 29.2. Subscription — checked 30.10.2026
- PostgreSQL 18: 29.14. Quick Setup — checked 30.10.2026
- MariaDB Server docs: Replication Overview — checked 30.10.2026
- AWS DMS: Creating tasks for ongoing replication using AWS DMS — checked 30.10.2026
- Google Cloud: Database migration: Concepts and principles (Part 1) — checked 30.10.2026
- Timescale / Tiger Data: Dual-write and backfill — checked 30.10.2026
- mariadb.org: From PostgreSQL 12 to MariaDB 11: A Gradual Fintech Migration with 23% Lower TCO — checked 30.10.2026
- Otterstax quickstart — checked 30.10.2026
- Internal: /use-cases/database-migration, /use-cases/cross-database-joins, /guides/what-is-a-federated-query-engine, /demo
More guides
-
What is a federated query engine?
A federated query engine runs one SQL query across several databases without copying data. How it works, how it differs from ETL, and when you need it.
-
Zero-ETL analytics: when to replace ETL with federated queries
What zero-ETL means, what stays on ETL, what moves to queries on live databases, and how to switch one dashboard at a time without hurting the app.
-
SQL on Kafka: 5 ways to query a Kafka topic with SQL
Compare ksqlDB, Flink SQL, the ClickHouse Kafka engine, the Trino Kafka connector and Otterstax for SQL on Kafka, with code and a stream-to-table JOIN.
See Otterstax on your own data sources
In a 30-minute call we'll map your stack and show a working query across your data sources.