
My Backup Existed. Could I Actually Restore It?
PostgreSQL recovery on EC2 with pgBackRest and S3. This was my first recovery using that combination. It worked, but not on the first attempt.
The first proof was an error
ERROR: relation "users" does not existI had deliberately dropped the users table in my PostgreSQL lab. Now I had to bring it back.
An earlier manual point-in-time recovery experiment had already taught me that recovery targets and timelines need care. This time, I wanted to try the backup-and-recovery workflow with pgBackRest and Amazon S3.
This was my first recovery using that combination. It worked, but not on the first attempt.
The lab
I used PostgreSQL 16 on an Ubuntu EC2 instance, with a database called microps. A small Node.js script generated writes, while Prometheus, postgres_exporter and Grafana provided monitoring.
For recovery, I used pgBackRest 2.60.0 with a full backup and WAL archiving to an S3 bucket in us-east-1 (N. Virginia). The EC2 instance reached S3 through an IAM instance role, with credentials delivered by the instance metadata service.
The incident
I inserted a PRE_DROP_MARKER into my heartbeat table and saved its timestamp as the recovery target. Then, during the live-load drill, I ran:
DROP TABLE users CASCADE;A subsequent count query failed because the table no longer existed.
The load generator stayed running during the drill; PostgreSQL was offline during the restore, so no writes could succeed in that window. Its inserts failed once I stopped the server. The load was live up to the incident - the restore itself ran offline.
This wasn't a selective table import. I was recovering the PostgreSQL cluster to an earlier point so that the dropped table would be present again. That distinction matters: other changes after the recovery target are also outside the intended recovered state.
The first restore refused to run
After stopping PostgreSQL, I attempted the time-targeted restore. pgBackRest returned:
ERROR: [040]: unable to restore to path '/var/lib/postgresql/16/main' because it contains filesHINT: try using --delta if this is what you intended.The existing data directory was not empty. pgBackRest would not overwrite it without an explicit choice.
A useful failure. A recovery tool refusing to overwrite data is a guardrail, not something to bypass blindly. Its check for a running PostgreSQL server is separate, and the server must be fully stopped before restoring. Deleting postmaster.pid is not a substitute for verifying that.
I retried with --delta, keeping the saved time target and the promote action.
The successful command used these options:
pgbackrest --stanza=main --type=time --target="2026-11-01 04:20:18.973617+00" --target-action=promote --delta restoreThis is the command from my lab, not a drop-in production runbook.
What --delta changes
For this file-based restore, pgBackRest compares file checksums against the backup manifest, restores files that differ, and removes files that do not belong in the restored state.
It is not a guarantee of changed-block downloads or a fixed speed improvement.
The result in the log
restore backup set 20261031-152511F, recovery will start at 2026-10-31 15:25:11restore size = 30.7MB, file total = 1397restore command end: completed successfully (1928ms)The command selected the previous day's full backup from the S3-backed repository and configured recovery for my time target.
After starting PostgreSQL, I ran:
SELECT count(*) FROM users;Result: 445. The table that had returned "relation does not exist" was back with 445 rows.
What I measured, and what I didn't
The restore command completed in 1.928 seconds. That is a useful result for this small lab, but it is not my end-to-end recovery time. WAL replay, server startup and validation happen beyond that logged restore phase.
Likewise, 30.7MB and 1,397 files describe the restore size reported by pgBackRest. They are not a measurement of bytes downloaded from S3.
The 445-row count confirms that the table returned. It does not establish zero data loss. To measure that properly, I would need an independent record of acknowledged writes and a comparison against the recovered data.
There is another subtlety: my marker timestamp was recorded during an insert, not at transaction commit. I used it to configure the recovery target, but I did not capture the recovery logs needed to demonstrate the precise replay stopping point.
Those limits don't erase the result. They separate what I demonstrated from what still needs measuring.
My takeaway
Before this drill, I had a backup configuration. After it, I had a missing-table error, a restore refusal I could explain, a successful restore log and a query showing the table was back.
That is the difference I wanted to test: not whether I could create a backup, but whether I could use it when the data was gone.
References
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article