Postgres backups, restore-tested · checked
How to test a Postgres backup
A backup is tested only by restoring it. Restore it into a throwaway PostgreSQL of the same major version, with pg_restore stopping at the first error, then compare every table's row count, and the schema, with the database it came from. pg_dump exiting 0 says nothing about whether the restore will work.
- Version
- pg_dump refuses a server newer than itself. Dump with the server's version or newer, and restore into the same major version to test what a recovery would do.
- Extensions
- Every extension the backup creates must exist where it is restored (pgvector and PostGIS are separate packages). A table that needs a missing one fails to restore.
- Roles
- Row-level security policies name roles. Restore with --no-owner --no-privileges, and create the roles the policies name first.
- Row-level security
- pg_dump stops when RLS would hide rows from the role it runs as. Dump as the tables' owner or a role with BYPASSRLS.
- Pooled connections
- Dump over a direct or session-mode connection, not a transaction pooler.
- Empty is not an error
- A dump of the wrong database, or of a schema that was left out, exits 0. Only comparing the counts finds it.
The commands below do the test by hand. restoreproof does the same every week in your own GitHub Actions, with every table, column, constraint, index, view, function, trigger and policy compared too, and fails the job when the backup would not restore.
Every week, in your own GitHub Actions
$ npx --allow-remote=root https://agentwares.vercel.app/dl/restoreproof-0.1.0.tgz init
Writes .github/workflows/restoreproof.yml and .github/restoreproof/drill.mjs into your repository, then tells you which repository secret to add. Each run backs the database up, restores it into a throwaway PostgreSQL of the same version on the runner, compares the two, and fails the job when the backup would not restore. To test once from this machine: npx --allow-remote=root https://agentwares.vercel.app/dl/restoreproof-0.1.0.tgz check, with the URL in RESTOREPROOF_DATABASE_URL. Free and MIT licensed; nothing is sent to us.
restoreproof: the same test, every week
restoreproof backs the database up in your own GitHub Actions, restores the backup into a throwaway PostgreSQL of the same version on the runner, and fails the job when it would not restore. Each run checks:
- The backup restores:
pg_restore --exit-on-errorinto a throwaway PostgreSQL of the same major version, made on the runner withinitdb, on 127.0.0.1 with a random password. - Every table, column, constraint, index, view, function, trigger, row-level security policy, sequence, enum and domain of the source is in the copy, with the same definition.
- Every table's rows match the live count, taken in one READ ONLY snapshot just after the backup, give or take the rows written meanwhile (at most 10 or 10%). A table with rows that restores empty always fails.
- The database has not lost more than half its rows since the last good run, while last week's backup still holds them.
A recorded run, and what else exists.
An email when a weekly restore test fails or does not run is not built.
It would email the people you name when a weekly test fails, when the backup shrinks, or when no test has run for eight days, from outside GitHub's scheduler. Today GitHub emails one person when a scheduled run fails, and nobody when it never runs: it can drop a scheduled run under load, and it turns off a public repository's schedules after 60 days without activity. Part of it runs today: agentcheck's free plan checks one URL every hour and emails you when the answer stops matching, so a check that expects "passing" from the workflow's status badge, on a public repository, tells you when a test fails, though not when one never runs. Watch the badge, free. If you would pay for the whole of it, say so with one click. The click is counted, and nothing else is sent or stored unless you then leave an email.
Counted. Thank you; nothing else was sent.
Sources
- PostgreSQL docs: pg_dump (read 9 Oct 2026)
- PostgreSQL docs: pg_restore (read 9 Oct 2026)
Related
restoreproof is a free tool from agentcheck, which runs scheduled checks of your endpoints and alerts you when an answer changes. Facts come from each provider's own pages, read on the day shown.