Skip to content
VDS · Databases

Moving a database from another server

The procedure for migrating a database to Millida VDS: preparation, transferring the dump over the network, checking integrity, and switching the application with minimal downtime.

Updated August 23, 2026

A database migration doesn't break on the commands — it breaks on the order of steps: people switch the domain first and only then discover that half the data never made it over. Below is a sequence that prevents that.

Preparation

On the new machine, install the same or a newer version of the database server — PostgreSQL or MySQL. Downgrading is not supported.

psql --version
mysql --version
df -h /

You need roughly 2.5 times the database size in free space: the dump, the unpacked data, and some headroom. On VDS-1 that's 40 GB total, so plan ahead.

Create a user and an empty database with the same encoding as on the old server.

Moving the data

The simplest path is a dump over SSH, with no intermediate files:

ssh root@OLD 'pg_dump -Fc -U shop shop' > /srv/shop.dump
pg_restore -U postgres -d shop --no-owner --role=shop /srv/shop.dump

For MySQL:

ssh root@OLD 'mysqldump --single-transaction --routines --events -u root shop' \
  | mysql -u root shop

Roles and users aren't included in a database dump — you export them separately: pg_dumpall --roles-only, or create them manually — see users and grants.

Bandwidth is up to 500 Mbps, so a 20 GB database migrates in a matter of minutes; the bottleneck is usually disk writes, which are limited by the tier.

Verify before switching

Check the numbers, not just “the site loaded”:

SELECT relname, n_live_tup FROM pg_stat_user_tables ORDER BY n_live_tup DESC LIMIT 20;
SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema='shop';

Compare row counts in the key tables against the old server, check that the sequences haven't reset (SELECT last_value FROM users_id_seq;), and run the application against the new database in test mode.

Switching over

  1. Enable maintenance mode or stop the application on the old server.
  2. Take a final dump of the changes made during preparation.
  3. Restore it on the new machine.
  4. Switch the application's connection string and restart the service.
  5. Keep the old server running for another week without deleting the data.

Don't skip step five: discovering a missing table three days later is par for the course.

Common mistakes

SymptomCause
role does not exist during restoreRoles weren't migrated — use --no-owner plus manual role creation
Garbled charactersMismatched encodings: restore into a database with utf8mb4 or UTF8
Sequences start at 1The dump contained only data, without setval
Restore takes hoursIndexes are being built on the fly; for large databases use pg_restore -j 4
Ran out of space midwayThe dump size alongside the data wasn't accounted for

Before migrating, check that the new database listens only on 127.0.0.1. There's no need to expose it publicly “for the duration of the migration” — the transfer goes over SSH, see remote access.