Database migration without the 3am pager
Database migrations are the scariest part of any cloud move. Do them wrong and you're either down for hours or corrupting data silently. Here's the playbook that works.
The only pattern that works: replicate-then-cutover
- Stand up destination — empty target database, configured to match source schema and version.
- Start replication — continuous logical replication from source to target. Tools: AWS DMS, Azure Database Migration Service, Google DMS, or native (pg_logical, MySQL binlog, SQL Server Always On).
- Let it catch up — replication lag must reach near-zero. Monitor for days, not hours.
- Test reads against target — in a staging app pointed at the target, run smoke tests. Read queries should return identical results.
- Schedule cutover window — short, ideally off-peak. Communicate widely.
- Stop writes on source — put the app in maintenance mode or freeze writes.
- Final sync — wait for replication lag to reach zero.
- Cut writes over to target — flip the connection string or promote the replica.
- Validate — row counts, critical queries, application smoke tests.
- Cut source to read-only mode — not deleted yet. You might need it.
- Monitor for 72 hours — if anything's wrong, you can still fail back.
- Decommission source — after 30 days of clean operation.
The mistakes that cause outages
Skipping step 2-3 (replication catch-up)
Doing a fresh dump-and-restore during the maintenance window means your window is the duration of the dump. Replication means the window is the final sync only (seconds to minutes).
Skipping step 5 (stopping writes)
If writes keep happening during cutover, some end up on source and some on target. Now you have data divergence. This is the #1 cause of post-migration incidents.
Skipping step 11 (monitoring before decomm)
"We migrated, decommissioned source next day, then discovered missing audit records." Never decommission until you're sure.
Tools
- Database Migration Assistant for complexity scoring and tool selection.