Verifying PostgreSQL backups: pg_dump, pgBackRest, Barman and WAL-G
A PostgreSQL backup is verified only by restoring it into a running server and checking the data. This guide covers pg_dump, pgBackRest, Barman and WAL-G, and how Restorly automates it.
Each backup tool has a command that checks its own files: pgbackrest verify, barman check, the checksums of a pg_dump custom archive. They find damaged or missing files. They do not prove that a server starts from the backup, that the WAL replays, or that the data is what you expect. Only a restore does.
pg_dump
Restore into a throwaway server of the same major version, with no network:
docker run -d --name restore-test --network none \
-e POSTGRES_PASSWORD=test postgres:17
docker exec restore-test pg_isready -U postgres -t 30
docker cp shop.dump restore-test:/tmp/shop.dump
docker exec restore-test createdb -U postgres shop
docker exec restore-test pg_restore -U postgres -d shop --exit-on-error /tmp/shop.dump
A plain SQL dump is loaded with psql -U postgres -d shop -v ON_ERROR_STOP=1 -f /tmp/shop.sql instead; a directory dump (-Fd) with pg_restore on the directory.
pgBackRest, Barman and WAL-G
These tools back up the whole cluster: base backups plus archived WAL. Testing one means restoring it to an empty data directory and starting PostgreSQL on it, so that the WAL is replayed:
- pgBackRest:
pgbackrest --stanza=main --pg1-path=/restore/data restore - Barman:
barman recover <server> latest /restore/data - WAL-G:
wal-g backup-fetch /restore/data LATEST, then arecovery.signalfile and arestore_commandthat callswal-g wal-fetch
Then start a PostgreSQL server of the same major version on /restore/data and wait until it accepts connections: recovery is done.
What to check after the restore
- Index and table consistency with
amcheck:CREATE EXTENSION amcheck; SELECT bt_index_check(i.indexrelid) FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid JOIN pg_am am ON am.oid = c.relam WHERE am.amname = 'btree' AND i.indisvalid AND c.relpersistence <> 't'; - Row counts of each table against the last test or production.
- The schema: tables, views, functions and extensions.
- Recent data: the newest row of a busy table, and for cluster backups the time of the last replayed transaction (
SELECT pg_last_xact_replay_timestamp()while in recovery). - Your own expectations, as SQL your application would agree with.
Note the restore time: that is your recovery time. Remove the container afterwards.
How Restorly does this
Restorly does all of this on a schedule or when a new backup arrives: it reads pg_dump archives (custom, directory or plain), pg_basebackup backups and the repositories of pgBackRest (encrypted ones too), Barman, Barman Cloud and WAL-G where they already are, restores them with the tool itself inside a container of the matching version with no network, runs amcheck, compares row counts and the schema with the last run, runs your own SQL checks and signs a report. With archived WAL it can also test a point-in-time restore. See Backups made by other tools, Supported databases and requirements and the free trial.