Moving a Postgres database
Three commands and a connection string.
Most Postgres migrations are simpler than the anxiety around them: a logical dump on one side, a restore on the other, a row count to prove it, one connection string changed. This page walks it through as it applies to moving onto Lathe, but the steps are the same for any two Postgres servers.
The move, in order.
- Dump
- pg_dump -Fc against the old connection string writes a compressed custom-format archive. Run it from a machine near the source; a few gigabytes take minutes.
- Restore
- pg_restore --no-owner --no-privileges into the new instance's direct port. Ownership and grants belong to the new owner role, which is why those two flags are there.
- Check
- Compare row counts on both sides for your largest tables, and run the query your app runs most. If they match, the data moved.
- Switch
- Change the connection string in your app's configuration and deploy. Use the pooled port 6432 for serverless functions and the direct port 5432 for migrations and long sessions.
- Keeping downtime short
- Put the app in read-only mode or a short maintenance page, take the final dump, restore, switch. For most small databases the whole window is minutes. Writes made to the old database after the dump do not move, so the dump must be the last thing that happens there.
- Traffic and cost
- The dump leaves the old provider as outbound traffic and arrives here as inbound, which is not counted. 20 TB a month is included in every Lathe plan, so the move costs nothing on this side however large the database.
Good for
- Leaving a metered platform for a flat price
- Moving a side project off a free tier that keeps pausing
- Consolidating several small databases onto one machine
- Rehearsing a restore, which is the same steps with a backup as the source
Questions
Do extensions come across?
The dump records CREATE EXTENSION statements. pgvector, pg_stat_statements, pg_trgm and pgcrypto are available on every Lathe instance; others from the allowed list can be switched on from the portal before the restore.
What about very large databases?
Run pg_dump with parallel jobs (-j) into a directory format and pg_restore the same way. Tens of gigabytes move in an hour; the machine's NVMe disk takes the restore at full speed.
Can I test the move without downtime?
Yes: dump and restore while the old database keeps serving, check the result, then repeat with a final short window. The first pass costs nothing here.
And if I want to leave Lathe later?
The same three commands in the other direction, at full speed, for nothing. Your data is yours.
Read next: Flat-price managed database, No egress fees, Never paused, never metered, Self-hosted VPS or managed, pgvector on your own machine, Supabase alternative, Neon alternative, Redis beside Postgres, A database for side projects, One machine, every engine. Every number on this page comes from the pricing page's facts.
Three commands away, from $15 a month.
Live about 90 seconds after checkout. Cancel any time; Mini starts with a 3-day free trial.
Create an instance