DocsGuides
View as MarkdownMigrate from Neon
Move a Neon database to KeelDB with pg_dump and pg_restore, or with logical replication for a cutover of seconds, including Neon's own rules for direct hosts and replication.
This guide moves one Neon branch, usually your production branch, to a KeelDB database with standard PostgreSQL tools. Recreate preview branches on KeelDB afterwards: they are instant on Free and Launch. The general steps are in Migrate to KeelDB; this page adds what is specific to Neon.
| Approach | Downtime | Best for |
|---|---|---|
| Dump and restore | Writes stop for as long as the dump and restore take | Most databases, especially up to a few tens of GB |
| Logical replication | Seconds to minutes at cutover | Large or busy databases that can't stop for long |
Neon facts on this page come from Neon's documentation, read on October 10, 2026: connection pooling and logical replication. Check them again before you start, since Neon may change them.
Prepare
Get Neon's direct connection string
Neon gives each branch a pooled and a direct connection string. The pooled one has -pooler in its hostname, for example ep-cool-darkness-123456-pooler.us-east-2.aws.neon.tech; the direct one doesn't. The pooler runs PgBouncer in transaction mode, so use the direct string for pg_dump and for replication. In Neon's Connect dialog, turn connection pooling off and copy the string.
export SOURCE_URL="postgresql://<role>:<password>@ep-cool-darkness-123456.us-east-2.aws.neon.tech/neondb?sslmode=require"Create the KeelDB database
-
Check the source's version and size:
psql "$SOURCE_URL" -c "SHOW server_version" psql "$SOURCE_URL" -c "SELECT pg_size_pretty(pg_database_size(current_database()))" -
Create a KeelDB database with a PostgreSQL version at least as new as the source's (KeelDB runs 18, 17 and 16; 18 is the default) and a plan with room to grow. Storage limits are on Plans and billing.
-
Wait until it is
ready, then copy its direct connection string from the Overview page:export TARGET_URL="postgresql://shop_owner:<password>@k7m2x9qa4pz1.us-east.db.keeldb.com:5432/shop?sslmode=require"
Use pg_dump and pg_restore at least as new as the newer of the two servers, usually PostgreSQL 18's. Older tools refuse to dump a newer server.
Check extensions
psql "$SOURCE_URL" -c "SELECT extname, extversion FROM pg_extension ORDER BY 1"Compare the list with Extensions. Create trusted extensions such as pg_trgm or citext yourself before the restore, and turn on catalog extensions such as vector or postgis in the console first. Your KeelDB role owns its database but is not a superuser, so an extension that only exists on Neon is reported as an error by the restore; decide whether your app needs it.
Dump and restore
-
Stop writes to Neon: put the app in maintenance mode or stop the processes that write.
-
Dump over the direct host.
--no-owner --no-aclleaves out ownership and grants that name Neon's roles, so restored objects belong to your KeelDB owner role:pg_dump "$SOURCE_URL" --format=custom --no-owner --no-acl --file=app.dump -
Restore into KeelDB over its direct host:
pg_restore --dbname="$TARGET_URL" --no-owner --no-acl --jobs=4 app.dumpKeep
--jobswithin your role's connection limit and around the database's vCPU count. Read the errorspg_restoreprints: one about an extension that exists only on Neon is often harmless, a failedCREATE TABLEis not. -
Update statistics:
psql "$TARGET_URL" -c "ANALYZE"
Logical replication
Logical replication copies the existing data, then streams every change from Neon until you switch over. Writes stop only for the final catch-up.
Neon's rules
- Turning it on is permanent. In the Neon Console, open the project's Settings, then Postgres, then Logical replication, and select Enable. This changes
wal_levelfromreplicatological, and Neon says it cannot be reverted. - It restarts computes. Enabling it restarts all of the project's computes and drops active connections. Pick a quiet moment.
- Use a role with replication rights. Roles created in the Neon Console, CLI or API belong to
neon_superuser, which has theREPLICATIONprivilege. Roles created with SQL don't, and it can't be granted to them. - The Neon compute stays awake while a subscriber is connected, so it does not scale to zero during the migration. Expect Neon compute usage for those days.
- Don't leave the slot idle. Neon removes inactive replication slots after about 40 hours. If the subscription is stopped longer than that, start again from the schema copy.
KeelDB's side
- Your owner role is a member of
pg_create_subscription, so it can create the subscription itself. - The subscription connects from KeelDB to Neon's direct host over the internet with TLS.
- Every replicated table needs a primary key, or
REPLICA IDENTITY FULL, for updates and deletes to replicate. - Logical replication does not copy schema changes, sequence values or large objects. Freeze schema changes until the cutover.
Steps
-
Copy the schema to KeelDB:
pg_dump "$SOURCE_URL" --schema-only --no-owner --no-acl --no-publications --no-subscriptions --file=schema.sql psql "$TARGET_URL" -f schema.sql -
Create a publication on Neon:
-- On Neon CREATE PUBLICATION keeldb_migration FOR ALL TABLES;If that is refused for lack of privileges, list the tables instead:
CREATE PUBLICATION keeldb_migration FOR TABLE public.orders, public.customers; -
Create the subscription on KeelDB with Neon's direct hostname and a role that has replication rights:
-- On KeelDB, connected to the direct host CREATE SUBSCRIPTION keeldb_migration CONNECTION 'host=ep-cool-darkness-123456.us-east-2.aws.neon.tech port=5432 dbname=neondb user=<role> password=<password> sslmode=require' PUBLICATION keeldb_migration;This creates a replication slot on Neon, copies every table, then streams changes.
-
Watch it catch up. On KeelDB, every table should reach state
r(ready):SELECT srrelid::regclass AS table_name, srsubstate AS state FROM pg_subscription_rel ORDER BY 1;On Neon, the lag should approach zero:
SELECT slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)) AS lag FROM pg_replication_slots WHERE slot_name = 'keeldb_migration'; -
At cutover, stop writes to Neon, wait for zero lag, then copy sequence values, which logical replication does not carry:
psql "$SOURCE_URL" -At -c " SELECT format('SELECT setval(%L, %s, true);', quote_ident(schemaname) || '.' || quote_ident(sequencename), last_value) FROM pg_sequences WHERE last_value IS NOT NULL" > sequences.sql psql "$TARGET_URL" -f sequences.sql -
Remove the subscription on KeelDB, which also drops the slot on Neon while Neon is reachable, then drop the publication on Neon:
-- On KeelDB DROP SUBSCRIPTION keeldb_migration; -- On Neon DROP PUBLICATION keeldb_migration;
Verify
Compare row counts table by table:
psql "$SOURCE_URL" -At -c "
SELECT format('SELECT %L, count(*) FROM %I.%I;', schemaname || '.' || relname, schemaname, relname)
FROM pg_stat_user_tables
ORDER BY 1" > count-queries.sql
psql "$SOURCE_URL" -At -F ' ' -f count-queries.sql > source-counts.txt
psql "$TARGET_URL" -At -F ' ' -f count-queries.sql > target-counts.txt
diff source-counts.txt target-counts.txt && echo "Row counts match"Also check that every extension you need exists on KeelDB, that sequences continue after Neon's highest values, and that your test suite passes. A branch of the migrated database is a safe place to run it.
Cut over
- Point app traffic at KeelDB's pooled host,
<id>-pooler.us-east.db.keeldb.com. If your app used Neon's-poolerhost, the same transaction mode rules apply:SET LOCALinside transactions, transaction-level advisory locks, and the direct host forLISTEN. See Connecting. - Point migrations (Prisma Migrate, drizzle-kit and similar) at the direct host, for example as
DIRECT_URL. See Prisma and Drizzle. - Keep
connect_timeout=10in the connection string: each KeelDB hostname can return several proxy addresses, and the timeout lets the client move on quickly when one is unreachable. - Make sure the database's IP allowlist includes your app's outbound addresses, or is empty.
- Take an on-demand backup on KeelDB (Back up now).
- Keep Neon read-only until you are confident, then remove the publication, any leftover slot and the old credentials.
Recreate your branches
Neon branches don't move with a dump. On KeelDB, create branches of the migrated database from the Branches tab, with POST /api/v1/databases/{id}/branches or with the create_branch MCP tool. On Free and Launch they are copy-on-write, so they are ready without copying the data. Give temporary ones an expiry time.
To weigh the two services first, see KeelDB and Neon compared.