Skip to content
Menu

DocsGuides

View as Markdown

Migrate from Supabase

Move your application's schemas from a Supabase project to KeelDB with pg_dump, or with logical replication, and handle Supabase's own schemas, roles and extensions schema.

A Supabase project is a PostgreSQL database plus the schemas and roles of Supabase's other products: Auth (auth), Storage (storage), Realtime and more. KeelDB is PostgreSQL only, so this guide moves your application's schemas and leaves Supabase's own schemas behind. If your app keeps using Supabase Auth or Storage, it can, as long as it reaches them separately from the database. The general steps are in Migrate to KeelDB.

Supabase facts on this page come from Supabase's documentation, read on October 10, 2026: connecting to Postgres, extensions, backup and restore, replication to an external database and the dedicated IPv4 address.

Prepare

Get Supabase's connection string

For pg_dump and replication, Supabase recommends the direct connection, db.<project-ref>.supabase.co on port 5432, as user postgres. That host uses IPv6 unless the project has Supabase's IPv4 add-on. From a network without IPv6, run pg_dump through the session pooler instead: copy the Session pooler string from Supabase's Connect dialog (port 5432 on aws-<index>-<region>.pooler.supabase.com, user postgres.<project-ref>). The index is a pooler cluster number that varies within a region, so don't compose the host from the region name. Never use the transaction pooler on port 6543 for a dump.

export SOURCE_URL="postgresql://postgres:<password>@db.abcdefghijklmnop.supabase.co:5432/postgres?sslmode=require"

Create the KeelDB database

Create a KeelDB database with a PostgreSQL version at least as new as the source's (KeelDB runs 18, 17 and 16) and room to grow, wait until it is ready, then copy its direct connection string:

export TARGET_URL="postgresql://shop_owner:<password>@k7m2x9qa4pz1.us-east.db.keeldb.com:5432/shop?sslmode=require"

Use pg_dump at least as new as the newer of the two servers, usually PostgreSQL 18's.

List what to move

Your tables usually live in public. List the schemas that hold your own objects:

psql "$SOURCE_URL" -c "SELECT nspname FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname <> 'information_schema' ORDER BY 1"

Most of what this lists belongs to Supabase (auth, storage, realtime, extensions, graphql, vault and others). Move public and any schema you created yourself. The examples below use --schema=public; add one --schema flag per extra schema.

Recreate the extensions schema

Supabase installs most extensions in a schema named extensions, so a column default can read extensions.uuid_generate_v4(). List what your database uses:

psql "$SOURCE_URL" -c "SELECT e.extname, n.nspname AS schema FROM pg_extension e JOIN pg_namespace n ON n.oid = e.extnamespace ORDER BY 1"

Then create the same schema on KeelDB and the trusted extensions in it, before anything else:

-- On KeelDB
CREATE SCHEMA IF NOT EXISTS extensions;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA extensions;
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA extensions;

Create only the ones you use, and check each against Extensions. Catalog extensions such as vector are turned on in the KeelDB console instead. If your tables use a type from such an extension under the extensions schema (for example extensions.vector(1536)), run \dx on KeelDB after turning it on to see which schema it went into, and change the schema name in schema.sql below to match before you restore.

Dump and restore

Writes stop for as long as this takes.

  1. Stop writes to the Supabase database.

  2. Dump the schema of your schemas as plain SQL, so you can read and edit it:

    pg_dump "$SOURCE_URL" --schema-only --schema=public --no-owner --no-acl --file=schema.sql
  3. Look for references to Supabase. These lines will fail on KeelDB:

    grep -nE '\b(auth|storage|realtime|graphql|vault)\.|\bTO (anon|authenticated|service_role)\b' schema.sql
    • Row level security policies written for Supabase's anon, authenticated and service_role roles, or that call auth.uid() or auth.jwt(), protect Supabase's Data API. An app that connects with its own database role doesn't use them. Remove them, or rewrite them for your own roles.
    • Foreign keys to auth.users need that table. Drop the constraint, or keep a copy of the user ids in a table of your own.
    • Triggers that call functions in Supabase's schemas need those functions. Remove them or replace them.
  4. Restore the schema:

    psql "$TARGET_URL" -f schema.sql

    psql prints an error for each statement that fails and carries on. schema "public" already exists is harmless; read the rest. Tables restored with --no-owner belong to your KeelDB owner role, which row level security does not restrict unless a table has FORCE ROW LEVEL SECURITY.

  5. Dump and restore the data:

    pg_dump "$SOURCE_URL" --data-only --schema=public --no-owner --no-acl --format=custom --file=data.dump
    pg_restore --dbname="$TARGET_URL" --data-only --no-owner --no-acl data.dump
    psql "$TARGET_URL" -c "ANALYZE"

    If pg_dump warns about circular foreign keys, restore those tables in an order that satisfies them, or drop and recreate the constraints around the data load.

Then verify and cut over.

Logical replication

Supabase can publish changes to an external PostgreSQL database, so a cutover can take seconds instead of the length of a dump.

  • Network: the subscription connects from KeelDB to Supabase's direct host over IPv4, so turn on Supabase's IPv4 add-on for the migration. The transaction and session poolers don't carry replication.
    • The IPv4 add-on is a paid add-on on Pro and above. On Supabase Free, use Dump and restore through the session pooler instead.
    • Turning the add-on on or off can drop direct connections for up to about a minute while DNS changes, and it replaces the project's IPv6 address rather than adding an IPv4 one, so a client that reaches the direct host only over IPv6 loses it. Do both outside busy hours.
  • Role: connect as postgres, or as a role created with CREATE ROLE <name> WITH REPLICATION LOGIN PASSWORD '<password>'; that can read your tables.
  • KeelDB: your owner role is a member of pg_create_subscription, so it can create the subscription itself.
  • 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.

Steps:

  1. Copy the schema with steps 2 to 4 of Dump and restore, without stopping writes.

  2. Create a publication on Supabase that lists your tables:

    -- On Supabase: prints the statement for every table in public
    SELECT 'CREATE PUBLICATION keeldb_migration FOR TABLE '
           || string_agg(format('%I.%I', schemaname, tablename), ', ') || ';'
    FROM pg_tables
    WHERE schemaname = 'public';

    Run the statement it prints.

  3. Create the subscription on KeelDB:

    -- On KeelDB, connected to the direct host
    CREATE SUBSCRIPTION keeldb_migration
      CONNECTION 'host=db.abcdefghijklmnop.supabase.co port=5432 dbname=postgres user=postgres password=<password> sslmode=require'
      PUBLICATION keeldb_migration;
  4. Watch it catch up, then cut over: stop writes on Supabase, wait for zero lag, copy sequence values and remove the subscription. The queries are the same as in Migrate to KeelDB.

Verify

Compare row counts table by table for the schemas you moved:

psql "$SOURCE_URL" -At -c "
  SELECT format('SELECT %L, count(*) FROM %I.%I;', schemaname || '.' || relname, schemaname, relname)
  FROM pg_stat_user_tables
  WHERE schemaname = 'public'
  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"

Cut over

  1. Point app traffic at KeelDB's pooled host, <id>-pooler.us-east.db.keeldb.com, and migrations at the direct host. If you used Supabase's transaction pooler, the same rules apply on KeelDB's pooler; see Connecting.
  2. Code that used Supabase's client libraries to read and write tables through the Data API now needs a database driver or an ORM. See Next.js, Prisma and Drizzle.
  3. Make sure the database's IP allowlist includes your app's outbound addresses, or is empty.
  4. Take an on-demand backup on KeelDB (Back up now).
  5. Keep the Supabase project until you are confident. Turn the IPv4 add-on off again if you added it only for the migration, outside busy hours: direct connections can drop for up to about a minute.

To weigh the two services first, see KeelDB and Supabase compared.