Test your Postgres backups with a restore drill, and fix the pg_restore errors that stop one.
A backup is only proven when you restore it. On a schedule, restore the newest backup into a scratch database, compare row counts with production, check the newest rows are recent, run a few real queries and time it. Read every pg_restore warning: by default it skips failed statements and still finishes.
Facts checked
What a drill catches that a green backup job doesn’t
A backup job reports success when pg_dump exits 0. That says nothing about whether the file restores, whether it has the tables you think it has, or whether you can get it running fast enough to matter. The failures people find during a real outage are mundane:
- The job dumped the wrong database. The URL still pointed at staging after a migration, or at an empty database a new deploy provisioned.
- The job stopped running months ago and nobody looked, because the old files were still in the bucket.
- The restore needs things the dump doesn’t carry: roles, an extension, or the encryption key your app uses for columns it encrypts itself.
- The restore “worked” with errors. pg_restore continued past failed statements and printed a count at the end. Some tables are empty.
- It takes four hours. Nobody knew, because nobody had timed it.
A restore drill you can script
The drill restores into a database that nothing else uses, checks it, records the result and drops it. Run it against the same files your real recovery would use, fetched the same way, not a fresh dump taken for the occasion.
Create the scratch database from template0: the pg_dump docs warn that local additions to template1 cause duplicate-definition errors. --exit-on-error makes the first failure stop the run instead of becoming a line in a summary. --jobs restores tables and builds indexes in parallel, which only works for custom or directory format and can’t be combined with --single-transaction.
#!/usr/bin/env bash
# Restore drill: restore the newest dump into a scratch database, check it, drop it.
set -euo pipefail
DUMP="$1" # a pg_dump custom-format file (-Fc)
SCRATCH="drill_$(date +%Y%m%d_%H%M)"
start=$(date +%s)
createdb --template=template0 "$SCRATCH"
pg_restore --no-owner --no-privileges --exit-on-error --jobs=4 \
--dbname="$SCRATCH" "$DUMP"
echo "restore took $(( $(date +%s) - start )) s"
psql -X -d "$SCRATCH" -v ON_ERROR_STOP=1 -f drill-checks.sql > "drill-$SCRATCH.txt"
dropdb "$SCRATCH"What to check after the restore
Run the same counting query against production and diff the two outputs. Counts can differ by the writes since the backup was taken; a table that is empty in the copy and full in production is the result you are looking for.
- Row counts per table. Catches empty or missing tables and a dump of the wrong database.
- Freshness. The newest timestamp tells you how much data the backup would lose. If it is three days old on a nightly schedule, the job has been failing.
- A real query or two. Log in as a test user, load a page, run the report finance cares about. Catches a missing extension or a broken function before anyone depends on it.
- Elapsed time. The restore time plus the time to find and download the file is your recovery time. Write it down next to the date.
-- drill-checks.sql: exact row count for every table
SELECT table_schema, table_name,
(xpath('/row/c/text()',
query_to_xml(format('SELECT count(*) AS c FROM %I.%I', table_schema, table_name),
false, true, '')))[1]::text::bigint AS row_count
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY 1, 2;
-- Freshness: the newest row should be younger than your backup interval
SELECT max(created_at) AS newest_order FROM orders;
-- One query your app cannot live without
SELECT count(*) FROM users WHERE email IS NOT NULL;pg_restore errors and what fixes them
These are the messages that stop or quietly damage a restore, with the exact text so you can search for it. Statement failures arrive as pg_restore: error: could not execute query: followed by the server’s error and the command that failed.
- Restore one table:
pg_restore -l dump > list, comment out lines with;, thenpg_restore -L list -d target dump. - All or nothing:
--single-transactionapplies everything or nothing, but rules out--jobs. For drills,--exit-on-errorwith parallel jobs into a throwaway database does the same job faster.
| Message | What it means | Fix |
|---|---|---|
input file appears to be a text format dump. Please use psql. † † | The file is a plain SQL dump (pg_dump’s default format), not an archive. | psql -X -d target -f dump.sql. Use pg_dump -Fc next time if you want pg_restore’s options. |
unsupported version (1.16) in file header † † † | Your pg_restore is older than the pg_dump that wrote the file. The numbers are the archive format version, not the Postgres version. | Use a pg_restore from the same major version as the pg_dump, or newer. Check with pg_restore --version. |
did not find magic string in file header † | The file isn’t a pg_dump archive: still gzipped, truncated, or an HTML error page saved by a failed download. | Check with file dump and head -c 5 dump (an archive starts with PGDMP). Decompress or download again. |
ERROR: role "app_user" does not exist † † | The dump sets owners and grants to roles the target server doesn’t have. | Add --no-owner --no-privileges so the connecting user owns everything, or create the roles first. |
ERROR: extension "vector" is not available † | The target server doesn’t have the extension installed. The hint says it must first be installed on the system where PostgreSQL is running. | Install the extension on the target before restoring, or restore onto a server that has it. |
ERROR: relation "users" already exists † † | The target database isn’t empty. | Restore into a fresh database made from template0, or use --clean --if-exists to drop objects first. |
pg_restore: warning: errors ignored on restore: 3 † † | pg_restore kept going past three failed statements and exited. Some objects or rows are missing. | Scroll up for the three errors. Use --exit-on-error in drills so this can’t pass unnoticed. |
† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. `input file appears to be a text format dump. Please use psql.` (2026-10-29) · `input file appears to be a text format dump. Please use psql.` (2026-10-29) · `unsupported version (1.16) in file header` (2026-10-29) · `unsupported version (1.16) in file header` (2026-10-29) · `unsupported version (1.16) in file header` (2026-10-29) · `did not find magic string in file header` (2026-10-29) · `ERROR: role "app_user" does not exist` (2026-10-29) · `ERROR: role "app_user" does not exist` (2026-10-29) · `ERROR: extension "vector" is not available` (2026-10-29) · `ERROR: relation "users" already exists` (2026-10-29) · `ERROR: relation "users" already exists` (2026-10-29) · `pg_restore: warning: errors ignored on restore: 3` (2026-10-29) · `pg_restore: warning: errors ignored on restore: 3` (2026-10-29)
On Canner: verified backups and Inspect first
Turn on a backup policy for a project database and Canner runs a drill for you each night. It restores your newest backup into a scratch database, reads every table back, deletes the scratch database and marks the backup Verified. A failed test raises an alert by email, and to a signed webhook if you set one. You can verify any backup on demand, or turn the nightly tests off in the alert settings.
Each backup also records its schema and policies: tables, columns, indexes, row-level-security state, policies, grants and the row counts at backup time. The verification restore compares the copy with that record and fails if a table, column, policy or grant didn’t come back. That is the row-count diff above, done by Canner.
For a real recovery, choose Inspect first. Canner restores into a temporary inspect database with its own connection string. It is never injected into your app and it deletes itself after 24 hours unless you keep it. Compare with live shows which tables are new, missing or different, with row counts. When you are satisfied, keep it as a database and copy it over the original. Restores are all-or-nothing, and replacing a database snapshots what was there first, kept for 7 days. Details are in the database docs.
# Verify one backup now (Canner restores it into a scratch database and reads it back)
canner db backups <name> <id> --verify
# Restore into a temporary inspect database instead of the live one
canner db backups <name> <id> --restore --inspect
canner db diff <inspect> # tables new, missing or different, with row counts
canner db inspect <inspect> --keep # keep it past the 24-hour expiryWhat this doesn’t cover
A verified backup proves the file restores. It doesn’t keep your app up while you restore. Canner runs one region (Montréal) with no standby or automatic failover, and backups live on the server that took them until you add an off-site destination, a bucket you own on any S3-compatible service. If your recovery plan needs a hot standby in another region, Canner isn’t that today. See backups and point-in-time recovery for the window between nightly backups.
Questions
How often should I test Postgres backup restores?
Automate a restore of the newest backup at least as often as you take full backups, so a broken job is caught within a day. Do a manual, timed recovery rehearsal, with someone following the written steps, a few times a year and after any change to how backups are taken.
Why does pg_restore say “errors ignored on restore”?
By default pg_restore continues when a statement fails and reports how many failed at the end. The restore finished, but some objects or data are missing. Scroll up to the individual errors, fix the cause (often missing roles or an extension), and use --exit-on-error so the next run stops at the first failure.
How do I fix “role does not exist” when restoring a dump?
Restore with --no-owner --no-privileges so the user you connect as owns every object and the dump’s grants are skipped. If you need the original roles and permissions, create those roles on the target server before running pg_restore.
Does Canner test my backups?
Yes, for databases with a backup policy. Each night Canner restores the newest backup into a scratch database, reads every table back, compares it with the schema and policy record taken at backup time, and marks it Verified. A failure raises an alert. You can also verify any backup on demand.
Backups that are restored every night.
Backup policies, nightly verification and Inspect first come with project databases. Compare plans on pricing.