Guide

How to restore a Supabase backup into a new project

Get a pg_dump or supabase db dump file back into a database: a scratch Postgres to check it, or a new Supabase project to run on it. Then prove every row came back.

By Sascha Heyer · Last updated December 4, 2026

There are two reasons to restore a Supabase backup: to check that it works (do this regularly), and to get your data back (hopefully rarely). Both start the same way. The commands below assume a plain SQL dump, either one gzipped file from pg_dump (what Liferaft stores) or the three files from supabase db dump.

Restore into a scratch Postgres to check it

The safest place for a test restore is a throwaway Postgres on your machine. Use the same major version as the Supabase project:

docker run -d --name scratch -e POSTGRES_PASSWORD=scratch -p 55432:5432 postgres:17
export SCRATCH=postgresql://postgres:scratch@localhost:55432/postgres

# the roles Supabase's RLS policies refer to, so policies restore too
psql "$SCRATCH" -c "create role anon nologin; create role authenticated nologin; create role service_role nologin;"
psql "$SCRATCH" -c "create schema extensions;"

gunzip -c backup.sql.gz | psql "$SCRATCH" -v ON_ERROR_STOP=0 -q 2> restore-errors.txt

Errors about extensions that only exist on Supabase (pg_graphql, supabase_vault) are expected and harmless for your tables. Errors about your own tables are not: read restore-errors.txt.

Count every row on both sides

A restore that finishes without errors can still be missing data. Compare exact row counts per table between the source and the scratch database. This query prints them:

select format('select %L as t, count(*) from %I.%I union all', n.nspname || '.' || c.relname, n.nspname, c.relname)
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r' and n.nspname in ('public', 'auth', 'storage')
order by 1;

It generates one count(*) per table; remove the last union all, run the result on both databases and diff the output. If the source keeps changing, the counts drift by the rows written since the dump. Liferaft avoids that by counting inside the same snapshot as the dump and storing the counts next to the copy.

Restore into a new Supabase project

To run on a backup, create a new Supabase project with the same Postgres major version and restore into it through its Session pooler connection string. With the three files from the Supabase CLI, Supabase’s migration guide uses:

psql \
  --single-transaction \
  --variable ON_ERROR_STOP=1 \
  --file roles.sql \
  --file schema.sql \
  --command 'SET session_replication_role = replica' \
  --file data.sql \
  --dbname "$NEW_DB_URL"

session_replication_role = replica switches off triggers and foreign key checks while the data loads, so tables can arrive in any order.

With a single pg_dump file that includes the auth and storage schemas (like a Liferaft copy), the new project already has those tables. Load it with errors allowed: the create statements for Supabase’s own objects fail with “already exists”, and the data then loads into the existing tables:

(echo "SET session_replication_role = replica;"; gunzip -c backup.sql.gz) \
  | psql "$NEW_DB_URL" -v ON_ERROR_STOP=0 2> restore-errors.txt

Then run the row count comparison above against the new project, re-create your Storage buckets and upload the files, and point your app at the new project’s URL and keys.

Restore just one table

Most real restores are partial: one table someone emptied by accident. Restore the whole copy into the scratch database first, then copy the rows you need across with \copy or a pg_dump --table of just that table from the scratch database. Never restore a whole backup over a live project to recover one table.

Make it routine

A restore you have practised takes minutes; one you have not takes an afternoon of reading docs while users wait. Run the scratch restore once a month at least, or let Liferaft run it every week and email you the table-by-table result.

Rather not run this yourself? Liferaft runs the dump every night through a read-only role, stores the copy outside Supabase, and restores it every week to count every row. Free for one Supabase project; Solo is $9 a month for five. Back up my Supabase project free

More guides

Compare Supabase backup tools