Database migration: moving data without losing it
A database migration moves data and schema to a new server, a new version or a new engine. The method you choose decides how long the application is down, so pick it from the downtime you can accept.
What kinds of database migration are there?
Three, often combined. A host migration moves the same engine and version to new hardware, such as from an older machine to a faster one. A version upgrade moves to a newer release of the same engine, such as PostgreSQL 15 to 17. An engine migration changes the product, such as MySQL to PostgreSQL, which also means converting schema, data types and queries. Each step adds risk, so do one at a time when you can: move the host first, upgrade later.
When is dump and restore enough?
When the database is small enough that the copy fits in your maintenance window. Stop writes, dump, transfer, restore, point the application at the new server. A 20 GB database dumps and restores in well under an hour on NVMe machines with parallel jobs. Use the engine's parallel options to save time.
pg_dump -h old-db -U migrator -Fd -j 8 -f /srv/xfer/shop shop rsync -a --info=progress2 /srv/xfer/shop/ migrator@203.0.113.52:/srv/xfer/shop/ pg_restore -h 127.0.0.1 -U postgres -d shop -j 12 --no-owner /srv/xfer/shop
How do I migrate with only minutes of downtime?
Replicate first, then switch. Set up the new server as a replica of the old one, let it catch up while the application keeps running, then stop writes briefly, confirm the replica has applied everything, promote it and repoint the application. For PostgreSQL, physical streaming replication works within one major version; logical replication also works across major versions, which turns an upgrade into a short cutover. MariaDB and MySQL use binary log replication with GTIDs in the same way.
-- on the old server CREATE PUBLICATION mig_all FOR ALL TABLES; -- on the new server, after loading the schema only CREATE SUBSCRIPTION mig_from_old CONNECTION 'host=203.0.113.51 dbname=shop user=repl_mig' PUBLICATION mig_all;
Logical replication does not copy sequences or schema changes, so sync sequence values at cutover and freeze schema changes during the migration.
What about changing engines?
Plan it as a software project. Types differ, such as unsigned integers, date handling and case sensitivity in comparisons, and so do stored procedures and query dialects. Tools such as pgloader move schema and data from MySQL to PostgreSQL in one run and report what they could not convert. Then run the application's test suite against the new engine and compare query plans for the slowest queries.
How do I check that the data arrived intact?
Compare more than row counts. Count rows per table, compute checksums or aggregates over key columns, compare the newest records and run a sample of real queries on both sides. Automate this so you can run it before and after cutover.
psql -h 203.0.113.52 -U migrator -d shop -Atc "SELECT 'orders', count(*), sum(total_cents), max(created_at) FROM orders"
| Method | Downtime | Best for |
|---|---|---|
| Dump and restore | Minutes to hours, grows with size | Small databases, version jumps |
| Physical replication, then promote | Seconds to minutes | Same engine and major version, new hardware |
| Logical replication, then switch | Minutes | Major version upgrades, partial moves |
| Conversion tool plus testing | Planned window | Engine changes |
Why keep a rollback plan?
Because some problems only appear under real traffic. Keep the old server untouched and running for a few days after cutover, and decide in advance which signals would trigger a return. With logical replication you can even replicate back from new to old for a while, which makes rollback a short switch rather than a data loss. Monthly terms make this easy: keep the old machine one more month, then let it lapse.
Which machine should the new database run on?
One with more memory than the working set and fast NVMe for write-heavy loads. BUSINESS-2 2024 has 64 GB DDR5 and 2x 960 GB SSD NVMe, Soft RAID for $109.80 a month; ENTERPRISE-a2 2026 has 128 GB DDR5 for large databases. Our Migrate to a new server guide covers moving the rest of the server, and Data migration covers non-database data.
Machines often chosen as new database hosts
| Model | Processor | Cores | Memory | Drives | Port | Per month |
|---|---|---|---|---|---|---|
| ESSENTIAL-S | AMD Ryzen 7 9700X | 8 | 64 GB | 2x 512 GB SSD NVMe | 1 Gbps unmetered | $46.20 |
| BUSINESS-2 2024 | AMD EPYC 4344P | 8 | 64 GB | 2x 960 GB SSD NVMe | 3 Gbps unmetered | $109.80 |
| BUSINESS-4 2026 | AMD EPYC 4585PX | 16 | 64 GB | 2x 960 GB SSD NVMe | 3 Gbps unmetered | $212.40 |
| ENTERPRISE-a2 2026 | AMD EPYC TURIN 9255 | 24 | 128 GB | 2x 1.92 TB SSD NVMe | 5 Gbps unmetered | $446.40 |
Related pages
Migrate to a new server
Move a live service to a newer or larger machine with minutes of downtime: plan the overlap, copy, replicate the database and switch DNS.
Read morePostgreSQL servers
Run PostgreSQL on dedicated hardware: current versions from the project repository, memory settings, NVMe planner costs, replicas, pgBackRest and failover.
Read moreDatabase servers
NVMe machines with large memory for PostgreSQL, MySQL, MariaDB and MongoDB, from a single primary to replicated pairs.
Read moreShip database dumps to a second server
Schedule compressed, encrypted MariaDB or PostgreSQL dumps and send them to a Storage machine elsewhere, with retention and restore tests.
Read moreQuestions and answers
What is the fastest way to migrate a small database?
Dump with parallel jobs, copy with rsync and restore with parallel jobs. On NVMe servers a 20 GB database usually moves within an hour.
How can I migrate a database with almost no downtime?
Set up the new server as a replica, let it catch up, then pause writes briefly, promote it and repoint the application.
Can logical replication upgrade PostgreSQL versions?
Yes. It replicates across major versions, but sequences and schema changes must be handled separately.
How do I verify a database migration?
Compare row counts, sums of key columns, the newest records and the results of real queries on both servers.
Should I upgrade the engine and move hardware at once?
Better to do one step at a time, so that if something breaks you know which change caused it.