Database Migration: Zero-Downtime Strategies for the Paranoid Sysadmin
I once watched a CTO literally pull hair out of his head during a failed migration. It was 3:00 AM. The destination server in Frankfurt had slightly higher latency than expected, the transaction logs desynchronized, and the primary e-commerce store for a major Nordic retailer went dark. Six hours of downtime. Millions in lost revenue.
Database migration is not a "copy-paste" operation. It is open-heart surgery on a patient running a marathon.
If you are moving workloads to Norway—perhaps to satisfy Datatilsynet requirements or simply to get closer to your Oslo user base—you need a plan that assumes everything will fail. Because eventually, it will.
The Hardware Reality Check
Before you even touch a config file, look at your disk I/O. Most botched migrations happen because the target disk cannot write fast enough to catch up with the incoming stream. I don't care how optimized your SQL is; if you are writing to shared spinning rust or cheap SATA SSDs, you are going to bottle-neck.
This is where infrastructure choice becomes binary. You either have NVMe or you have problems. At CoolVDS, we standardized on enterprise NVMe for our Norwegian nodes specifically for this use case. High IOPS isn't a luxury; it's a requirement when you're replaying binary logs at 10x speed to catch up a replica.
Strategy 1: The "Dump and Pipe" (Low Volume)
For databases under 10GB where a few minutes of maintenance mode is acceptable, don't overengineer it. Streaming a dump directly over SSH is faster than saving to a file, transferring, and restoring. It saves disk I/O and time.
The Wrong Way:
mysqldump -u root -p database > dump.sql
scp dump.sql user@new-server:~
ssh user@new-server "mysql -u root -p database < dump.sql"
The Battle-Hardened Way:
mysqldump --single-transaction --quick --compress --routines --triggers -u root -p'SecretPass' source_db | ssh -C user@coolvds-norway-ip "mysql -u root -p'NewPass' target_db"
Pro Tip: The --quick flag forces mysqldump to retrieve rows from the server a row at a time rather than retrieving the whole result set and buffering it in memory before writing it out. Essential for avoiding OOM kills on smaller instances.
Strategy 2: Replication (The Zero-Downtime Standard)
For anything critical, you never stop the master. You create a slave, let it sync, and then promote it. This is how we move terabytes of data across the NIX (Norwegian Internet Exchange) without users noticing a flicker.
Step 1: Configure the Source (Master)
Edit your my.cnf (or mysqld.cnf). You need binary logging enabled. If you are still running MyISAM tables in 2023, stop reading and fix your schema first. We are assuming InnoDB.
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_format = ROW
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
Step 2: The Initial Sync
Use Percona XtraBackup. It allows you to take a hot backup without locking the database. If you use mysqldump here, you will lock tables and your app will hang.
xtrabackup --backup --target-dir=/data/backups/ --datadir=/var/lib/mysql
xtrabackup --prepare --target-dir=/data/backups/
Transfer this directory to your CoolVDS instance using rsync. We use specific flags to preserve permissions and show progress.
rsync -avzP -e "ssh -p 22" /data/backups/ root@coolvds-norway:/var/lib/mysql/
Step 3: Establish Replication
Once the data is on the new CoolVDS NVMe instance, start MySQL and configure it as a replica. You'll need the binlog coordinates from the XtraBackup `xtrabackup_binlog_info` file.
CHANGE MASTER TO
MASTER_HOST='10.0.0.5',
MASTER_USER='replicator',
MASTER_PASSWORD='ComplexPassword123!',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS= 107;
START SLAVE;
Check status immediately:
SHOW SLAVE STATUS\G
Look for Seconds_Behind_Master. If this number is increasing, your target disk I/O is too slow. This is the moment most VPS providers fail. If you are on CoolVDS, you should see this drop to 0 rapidly thanks to the underlying NVMe architecture.
The Geographic Edge: Why Norway?
Latency is physics. You cannot code around the speed of light. If your users are in Oslo, Bergen, or Trondheim, hosting in Frankfurt adds 20-30ms to every single round trip. For a complex SQL query fetching related data, that latency compounds.
Furthermore, Schrems II killed the privacy shield. Hosting customer data on US-owned cloud infrastructure is a compliance minefield. By moving to a Norwegian provider like CoolVDS, you simplify your GDPR stance significantly. Your data stays within the jurisdiction. No legal gymnastics required.
Post-Migration Verification
Don't just switch DNS and pray. Verify.
| Check | Command / Tool | Success Criteria |
|---|---|---|
| Row Counts | SELECT COUNT(*) FROM table; |
Exact match on Master/Slave |
| Checksums | pt-table-checksum |
Zero diffs detected |
| Connectivity | nc -zv ip_address 3306 |
Connection Succeeded |
Once verified, update your application connection strings to point to the new CoolVDS IP, then shut down the old master. Congratulations, you just performed a platform migration.
Don't let slow I/O or network jitter kill your uptime during the critical phase. If you need a staging environment to test this process, spin up a high-performance instance today.
Deploy your test instance on CoolVDS in 55 seconds.