Sub topic 15
When to Use pgBackRest, Barman or WAL-G
This chapter assumes you have worked through the earlier chapters. You should know how archive_command, pg_basebackup, restore_command, recovery.signal and recovery targets fit together. You should also be comfortable with timelines and with retention rules that keep the WAL a base backup needs.
The manual setup in this tutorial is correct and fully supported. It is also a set of scripts you own. This chapter covers what those scripts leave out, what the three common tools add, and how to choose between them.
What hand-written scripts leave to you
The archive_command from the earlier chapters is a single test ! -f ... && cp ... line. A production setup needs more than that:
- Durability. Plain
cpdoes not callfsyncon the copied file or its directory. A crash right after the copy can leave a short or missing file in the archive even though PostgreSQL was told the copy succeeded. - Off-host storage.
/mnt/archiveis often a mount on the same site, or even the same failure domain, as the database. - Integrity checks. Nothing verifies that a segment still matches what was written, or that a base backup is complete.
- Retention. You must write the logic that deletes old base backups and only the WAL older than the oldest backup you keep.
- Speed.
pg_basebackupcopies the whole cluster every time, and each WAL segment is copied uncompressed unless you add that yourself. - Restore automation. You edit
postgresql.confand createrecovery.signalby hand during an incident.
Dedicated tools cover these points. They still use the same PostgreSQL mechanisms: continuous archiving, a physical base backup, and restore_command during recovery. The concepts you have learned apply unchanged.
What the tools add
Features that go beyond pg_basebackup and cp include:
- Compression of both backups and WAL segments.
- Encryption of data at rest in the repository.
- Checksums stored with each file and verified at restore time or with a dedicated verify command.
- Incremental and differential backups, which copy only files or blocks that changed since an earlier backup.
- Parallel backup and restore, and parallel WAL archiving and fetching.
- Retention policies that expire backups and the WAL they no longer need together.
- Remote storage, including object stores such as Amazon S3, Google Cloud Storage and Azure Blob Storage.
- Recovery helpers that write the recovery settings for you.
The three tools
pgBackRest
pgBackRest keeps a repository, called a stanza per cluster, that holds backups and archived WAL. It runs from the database host, from a dedicated repository host, or both. Its main strengths are:
- Full, differential and incremental backups, with parallel processing and compression.
- Backup from a standby to reduce load on the primary.
- Built-in retention for full and differential backups, with WAL expiry tied to them.
- Support for POSIX, S3-compatible, GCS and Azure repositories, with encryption.
- Delta restore, which reuses files already present in the target directory and fetches only the ones that differ.
- Asynchronous WAL archiving, which keeps the primary from stalling when the repository is slow.
A minimal local configuration looks like this:
# /etc/pgbackrest/pgbackrest.conf
[global]
repo1-path=/mnt/pgbackrest
repo1-retention-full=2
compress-type=zst
[main]
pg1-path=/var/lib/postgresql/16/mainOn the server, point PostgreSQL at the tool:
# postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'Then create the stanza, check it, and take the first backup:
sudo -u postgres pgbackrest --stanza=main stanza-create
sudo -u postgres pgbackrest --stanza=main check
sudo -u postgres pgbackrest --stanza=main --type=full backupTo recover to a time, stop the server and run a restore with the target. The --type=time option makes pgBackRest write restore_command, the target and recovery.signal for you:
sudo systemctl stop postgresql
sudo -u postgres pgbackrest --stanza=main --delta \
--type=time --target="2026-11-27 14:30:00+00" \
--target-action=promote restore
sudo systemctl start postgresqlBarman
Barman (Backup and Recovery Manager) runs on a separate backup server and manages one or more PostgreSQL servers from there. It is a good fit when you want a central place that backs up many servers and a clear separation between the database hosts and the backup host. Its main features are:
- Backups through
pg_basebackupover the streaming protocol, or through rsync over SSH. - WAL collection by streaming with
pg_receivewal, which can give a recovery point close to the most recent committed transaction, or byarchive_commandshipping. - Retention policies expressed as a number of backups or a recovery window, for example
RECOVERY WINDOW OF 7 DAYS. - A
barman recovercommand that restores to a target time, xid, LSN or named restore point and writes the recovery settings. - Cloud variants for backing up to object stores.
Barman's streaming option matters for the recovery point. With plain archive_command, the WAL of the current segment is not in the archive until the segment is completed or archive_timeout forces a switch. Streaming receives WAL as it is generated, so less data can be lost if the database host is destroyed.
WAL-G
WAL-G is a command-line tool written in Go. It is a successor to WAL-E and is common in container and cloud environments. It is configured mainly through environment variables and has no central server or catalog daemon. Its main features are:
- Storage in S3, GCS, Azure and other object stores, as well as the local file system.
- Compression, with several algorithms, and encryption.
- Delta backups, which copy only pages changed since a previous backup.
- Parallel upload and download, which matters for large clusters.
wal-pushandwal-fetchcommands that fit directly intoarchive_commandandrestore_command.
# postgresql.conf
archive_mode = on
archive_command = 'wal-g wal-push %p'
# recovery settings
restore_command = 'wal-g wal-fetch %f %p'
recovery_target_time = '2026-11-27 14:30:00+00'
recovery_target_action = 'promote'WAL-G's backup-fetch command downloads a base backup into an empty data directory. You then create recovery.signal and set the recovery targets as you did in the manual procedure. That makes it closer to the manual workflow than pgBackRest's one-command restore.
Comparing them
| Aspect | pgBackRest | Barman | WAL-G |
|---|---|---|---|
| Where it runs | Database host, repository host, or both | Dedicated backup server | Database host |
| Main storage | POSIX, S3, GCS, Azure | Local disk on the backup server, plus cloud options | Object stores, local disk |
| Incremental backups | Yes, file level, with differential and incremental types | Yes, with rsync file-level deduplication | Yes, page-level delta |
| WAL transport | `archive-push`, optionally asynchronous | Streaming or `archive_command` | `wal-push` |
| Restore helper | `restore` writes recovery settings | `recover` writes recovery settings | `backup-fetch`, then manual settings |
| Catalog and retention | Built in | Built in, central | Commands such as `delete`, run by you |
| Typical fit | General production use | Many servers, central operations | Cloud and container deployments |
Treat the table as a summary, not as a feature guarantee. Check the current documentation of the version you plan to deploy, because options change between releases.
Decision criteria
Choose by the constraints you actually have:
- Where must the backups live? If the only acceptable place is an object store and there is no backup server, pgBackRest or WAL-G fit well. If you have a dedicated backup host and want a central view, Barman fits well.
- How many servers? For one or a few clusters, any of the three works. For dozens, a central tool such as Barman reduces repeated configuration, while pgBackRest and WAL-G need the same configuration deployed to each host.
- How large is the data? For multi-terabyte clusters, incremental backups and parallel transfer save hours. Compare the backup types each tool offers against your backup window.
- How small must the data loss window be? If
archive_timeoutof a few minutes is not acceptable, look at streaming WAL (Barman withpg_receivewal) or synchronous replication to a standby, in addition to archiving. - Who will run the restore at 3 a.m.? A single documented restore command reduces mistakes under pressure. This favors tools with a restore helper.
- Which platform do you run on? Managed PostgreSQL services provide their own backup and point-in-time restore. You use these tools on self-managed instances.
Failure modes and gotchas
- Treating the tool as a replacement for testing. A configured tool can still produce a repository you cannot restore from, for example because of a wrong encryption key or a retention rule that expired needed WAL. Run test restores on a schedule, exactly as the earlier chapter on testing described.
- Ignoring
pg_stat_archiver. The tool'sarchive_commandruns inside PostgreSQL's archiver, sofailed_countandlast_failed_walstill tell you when archiving breaks. Pair that with the tool's owncheckorverifycommand. - Losing the encryption key or credentials. An encrypted repository is unreadable without its passphrase or key. Store them separately from the repository.
- Keeping the repository next to the database. A repository on the same disk or host as the cluster does not protect you against loss of that disk or host.
- Mixing tools on one archive. Do not run two tools that both set
archive_command. A cluster has onearchive_command, and a second tool will either overwrite the first or produce gaps in the WAL sequence. - Version mismatches. Restoring to a different PostgreSQL major version is not possible with physical backups. Keep the same major version and a compatible architecture for the restore host.
- Forgetting timelines. After a recovery, the new timeline starts. Each tool handles
recovery_target_timelinein its own way. Confirm that the generated settings match what you intend, especially when restoring a backup that is not on the latest timeline.
Migrating from a manual setup
A safe order for moving from scripts to a tool is:
- Install the tool on a test host and restore a copy of production to prove the workflow.
- Take a new full backup with the tool, and keep the old archive in place.
- Switch
archive_commandat a quiet moment, then runSELECT pg_switch_wal();and checkpg_stat_archiverand the tool'scheckcommand. - Run a point-in-time test restore from the tool's repository to a time after the switch.
- Retire the old scripts only after the new repository holds at least one verified backup and an unbroken run of WAL.
Exercise
Your team runs 40 PostgreSQL clusters on virtual machines. You have one spare server with a large disk, and you need a short recovery point without losing committed work if a database host is destroyed. Which tool would you evaluate first, and which feature supports that choice?
Show answer
Barman. It runs on a dedicated backup server that can manage all 40 clusters centrally, and its WAL streaming with pgreceivewal receives WAL as it is generated instead of waiting for a segment to complete or for archivetimeout to force a switch. pgBackRest could also work, but the central server and streaming receive match this scenario most directly.
Exercise
After moving to a backup tool, pg_stat_archiver shows failedcount rising and lastfailed_wal stuck on the same segment. The tool's backups still complete. What does this mean, and what should you do?
Show answer
Archiving of WAL is failing even though base backups run, so point-in-time recovery past that segment is not possible and pgwal on the server will keep growing. Read the PostgreSQL log for the archivecommand error, run the tool's check command, fix the cause (credentials, repository space, permissions, or a missing stanza), and confirm that archivedcount increases and failedcount stops rising. Then take a new backup and test a restore.