Migrate a PostgreSQL database to Plexivo
Move a PostgreSQL database to Plexivo Postgres with pg_dump and pg_restore: the right flags, versions, extensions, TLS and a cut-over checklist.
There are two ways to bring a PostgreSQL database to Plexivo Postgres. Plexivo can copy it for you from any database it can reach over the internet. Or you move it yourself with pg_dump and pg_restore, which this page shows, when the source is not reachable from outside or you want to control each step.
Before you begin#
- Versions. Plexivo Postgres runs PostgreSQL 18, recommended, or 17. Create the new database on a version the same as your source or newer. Use the
pg_dumpandpg_restoreof that newer version: a newerpg_dumpreads older servers. - Extensions. Every extension your source uses must be one your
appuser can create. Check the list on the new database with the query in Extensions. - An empty database. Create a Plexivo Postgres database with room for your data. See Create a database.
- A way in. From your computer, open a tunnel with
plexivo db connect, or add your address under Trusted networks. See Networking.
Move it#
- Get both connection strings. Your source’s, as
SOURCE_URL. From the new database’s Connect tab, choose Reveal and copy its connection string asTARGET_URL, and choose Download CA certificate to saveplexivo-postgres-ca.pemin the same folder.bashexport SOURCE_URL='postgresql://user:PASSWORD@old-host:5432/mydb?sslmode=require' export TARGET_URL='postgresql://app:PASSWORD@orders-db-3f9a1c.db.plexivo.app:31542/app?sslmode=verify-full&sslrootcert=plexivo-postgres-ca.pem' - Stop writes. Put your app in maintenance mode, or stop it, so nothing written after the dump is left behind.
- Dump the source. Use the custom format, and leave out the source’s owners, grants, publications and subscriptions, which belong to the old server.
bash
pg_dump -Fc --no-owner --no-acl --no-publications --no-subscriptions \ -d "$SOURCE_URL" -f app.dump - Leave out provider-only objects. Monitoring extensions such as
pg_stat_statementsand event triggers hold no data and need a superuser. Make a list of everything else:bashpg_restore -l app.dump \ | grep -v -E ' EVENT TRIGGER | COMMENT - EXTENSION | EXTENSION - "?(pg_stat_statements|pg_stat_monitor|pg_buffercache|pgaudit|pg_repack|plpgsql)"? *$' \ > keep.list - Restore into Plexivo Postgres. Everything restored is owned by
app.--exit-on-errorstops at the first error instead of leaving a half-restored database. For a large database,--jobs 4restores tables in parallel; keep it below your connection limit.bashpg_restore --no-owner --no-acl --exit-on-error --jobs 4 \ -L keep.list -d "$TARGET_URL" app.dump - Refresh statistics. Run
ANALYZEso the new database plans queries well from the first request. Warnings that it skips system tables are expected.bashpsql "$TARGET_URL" -c 'ANALYZE;' - Check the data. Compare row counts of your important tables on both sides, and the next value of their sequences.
bash
psql "$SOURCE_URL" -Atc 'select count(*) from orders' psql "$TARGET_URL" -Atc 'select count(*) from orders' - Switch your app over. For a Plexivo App Runner app, connect the database on the app’s Environment tab: Plexivo sets
DATABASE_URLandDATABASE_CA_CERT. For an app elsewhere, give it the new connection string and the CA certificate. Then end maintenance mode.
TLS#
Plexivo Postgres accepts only TLS connections. With sslmode=verify-full and the database’s CA certificate, your client checks both the certificate and the host name. Apps connected in Plexivo receive the certificate as DATABASE_CA_CERT. Never turn off certificate checks. See TLS.
Through a plexivo db connect tunnel, connect to 127.0.0.1 on the port it prints, with sslmode=require, as Connect shows.
Cut-over checklist#
- Plan the switch for a quiet hour, and tell your users if the app will be read-only for a while.
- Do a full practice run first, and time it: the real move takes about as long.
- Stop writes, dump, restore, run
ANALYZE, and check row counts. - Switch the app to the new connection string with TLS checks on.
- Test sign-in, a write and a read in the app, then end maintenance mode.
- Keep the old database, read-only, for a few days as your way back.
- Then delete it, and remove its passwords from wherever you kept them.
Free migration help#
Prefer a hand? Tell us about your database, and Plexivo support plans the move with you. Ask for free migration help.
Next steps#
PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada.
Updated 2 November 2026