By Sascha Heyer · Last updated December 4, 2026
Backups fail quietly. A cron job keeps running after its credentials expire and uploads an empty file. pg_dump hits a table it cannot read and stops half way. A version mismatch produces a dump that does not restore into the server you have. None of this shows up until someone restores the backup, which is why the only test that counts is a restore. This guide works for any Postgres, and includes the Supabase specifics.
Level 1: the file is whole
Cheap checks that catch truncated or corrupted files. Record a checksum when you make the backup and compare it before you trust the file:
sha256sum backup.sql.gz > backup.sql.gz.sha256 # at backup time
sha256sum -c backup.sql.gz.sha256 # later
gzip -t backup.sql.gz && echo "gzip ok"
# custom-format dumps (pg_dump -Fc): list the table of contents
pg_restore --list backup.dump | headThese prove the file is readable. They do not prove the data is complete or that it restores.
Level 2: count rows in the same snapshot as the dump
To know what “complete” means, you need the row count of every table at the moment of the dump. Counting before or after gives numbers that drift with every write. Postgres can share one snapshot between sessions: export it from a repeatable read transaction, count inside it, and hand it to pg_dump with --snapshot, all while the transaction stays open. In one psql session:
export DB_URL='postgresql://…:5432/postgres' # a session connection, not a transaction pooler
psql "$DB_URL" -X -q -A -t -F ' ' <<'SQL'
begin isolation level repeatable read;
select pg_export_snapshot() as snap \gset
\setenv SNAP :snap
\o counts-source.txt
select string_agg(format('select %L, count(*) from %I.%I', n.nspname || '.' || c.relname, n.nspname, c.relname), ' union all ') || ' order by 1'
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r' and n.nspname not in ('pg_catalog', 'information_schema') and n.nspname not like 'pg_toast%'
\gexec
\o
\! pg_dump "$DB_URL" --snapshot="$SNAP" --no-owner --no-privileges | gzip > backup.sql.gz
commit;
SQLcounts-source.txt now holds one line per table with its exact row count, matching the dump to the row. On Supabase, add the --exclude-schema flags from the pg_dump guide to the pg_dump line and the same schemas to the not in list, and connect with a role that bypasses RLS.
Level 3: restore into a throwaway database and compare
Restore into a fresh Postgres of the same major version. Docker makes it disposable:
docker run -d --name drill -e POSTGRES_PASSWORD=drill -p 55432:5432 postgres:17
export SCRATCH=postgresql://postgres:drill@localhost:55432/postgres
until pg_isready -d "$SCRATCH" -q; do sleep 1; done
gunzip -c backup.sql.gz | psql "$SCRATCH" -q -v ON_ERROR_STOP=0 2> restore-errors.txtRun the same count query against the scratch database and compare:
psql "$SCRATCH" -X -q -A -t -F ' ' -o counts-restored.txt <<'SQL'
select string_agg(format('select %L, count(*) from %I.%I', n.nspname || '.' || c.relname, n.nspname, c.relname), ' union all ') || ' order by 1'
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r' and n.nspname not in ('pg_catalog', 'information_schema') and n.nspname not like 'pg_toast%'
\gexec
SQL
diff counts-source.txt counts-restored.txt && echo "PASS: every table matches"
docker rm -f drillAn empty diff means every table came back with exactly the rows it had. Then read restore-errors.txt: errors about extensions or roles that only exist on the source (on Supabase, supabase_vault or pg_graphql) are expected; errors about your own tables are findings. For a Supabase dump, create the anon, authenticated and service_role roles in the scratch database first so the RLS policies restore, as the restore guide shows.
Level 4: make it a routine
- Run the drill on a schedule, weekly at least, against the newest backup, not a special test copy.
- Fail loudly: a non-zero exit, an alert, an email to more than one person.
- Record how long the restore took. That number is your real recovery time, and it grows with the data.
- Re-run it after every change to the backup itself: new flags, a new role, a Postgres upgrade.
The same drill in two commands
The free, source-available liferaft CLI packages levels 1 to 3: liferaft dump counts every table in the dump’s snapshot and writes a manifest with the sha256, and liferaft drill restores into a throwaway Postgres (started with initdb, no Docker needed) and exits with 1 if any table is short:
LIFERAFT_DB="$DB_URL" npx github:SaschaHeyer/liferaft-cli dump -o backup.sql.gz
npx github:SaschaHeyer/liferaft-cli drill backup.sql.gzFor Supabase projects, the hosted Liferaft runs that drill for you every week on every plan, free included, and emails the result table by table: expected rows, restored rows, pass or fail.
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
Frequently asked questions
How often should I test a Postgres backup?
At least monthly, and after every change to how the backup is made (new flags, new role, new Postgres version). Weekly is better, and it is cheap once the drill is a script.
Is pg_restore --list enough to verify a backup?
It proves the archive is readable and lists what is inside, which catches truncated files. It does not prove that every row is there or that the restore succeeds, so it complements a real restore rather than replacing it.
Why compare exact row counts instead of pg_class estimates?
reltuples in pg_class is an estimate from the last ANALYZE and can be far off. Exact count(*) per table, taken in the same snapshot as the dump, gives numbers that must match the restored database row for row.