Sub topic 14
When to use pgBackRest or Barman
This chapter assumes you have read the earlier chapters. You should know how pg_basebackup, WAL archiving, and point-in-time recovery (PITR) work, and you should be comfortable editing postgresql.conf and running commands as the postgres OS user. The chapter compares two tools that automate those mechanisms. It explains when to adopt one and what the setup looks like. It does not cover every option.
What these tools add
You can build a complete physical backup system from the pieces covered so far. You need pg_basebackup, an archive_command, a restore_command, a cron job, and a cleanup script. Each piece works. The gaps appear when you combine them:
- Retention must keep every WAL segment needed by the oldest base backup you still hold. Deleting WAL by age alone can silently break an older backup.
- A bare
cpinarchive_commanddoes not verify that the file reached durable storage or that the archive is still healthy. - Nobody notices a stuck archive until the disk holding
pg_walfills up. - Restoring means assembling the right base backup, the right WAL range, and the right recovery settings by hand, usually during an outage.
pgBackRest and Barman are two widely used open-source tools that handle these jobs. Both wrap the same PostgreSQL mechanisms you already know: base backups, WAL archiving, and recovery settings. Neither replaces them. Both are separate projects from PostgreSQL itself, so you install them from your distribution or from the PostgreSQL community package repositories.
How the two tools are organized
pgBackRest and Barman differ mainly in where they run and who initiates the work.
pgBackRest is a single program that runs on the database host. It can also run on a dedicated repository host, reached over SSH or TLS. The database's archive_command calls it to push WAL, and you call it to take backups and to restore. A pgBackRest stanza is the named configuration for one PostgreSQL cluster, and a repository is where backups and WAL are stored.
Barman is a server-side tool that normally runs on a separate backup server. It pulls data from PostgreSQL. It can take base backups with pg_basebackup over the replication protocol or with rsync over SSH. It receives WAL either by streaming it (pg_receivewal behavior) or by having PostgreSQL push it with archive_command. Each protected database is a server entry in Barman's configuration.
Feature comparison
| Area | pgBackRest | Barman |
|---|---|---|
| Where it runs | Database host, optionally with a repository host | Dedicated backup server (pull model) |
| Backup types | Full, differential, incremental | Full with `pg_basebackup`; incremental through rsync hard links |
| WAL handling | `archive-push` from `archive_command` | Streaming replication or `archive_command` |
| Parallelism | `process-max` for backup, restore, and archiving | Configurable parallel jobs for backup and recovery |
| Object storage | S3-compatible, Azure, and GCS repositories | Cloud tools (`barman-cloud-*`) for S3, Azure, and GCS |
| Retention | Full and differential counts, or by time | Redundancy count or recovery window |
| Encryption | Built-in repository encryption | Relies on storage and cloud-side encryption |
| Backup from a standby | Supported | Supported |
Check the documentation for your installed versions. Both projects add features regularly, and some table entries (such as incremental backup methods) depend on the version and on your PostgreSQL major version.
A minimal pgBackRest setup
On the database host, create /etc/pgbackrest/pgbackrest.conf:
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
compress-type=zst
process-max=4
[main]
pg1-path=/var/lib/postgresql/16/mainThen point PostgreSQL's archiving at it in postgresql.conf. Changing archive_mode requires a restart.
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'Create the stanza, verify the setup, and take the first backup as the postgres user:
pgbackrest --stanza=main stanza-create
pgbackrest --stanza=main check
pgbackrest --stanza=main --type=full backup
pgbackrest --stanza=main infocheck is the important step. It confirms that archiving is configured correctly and that a WAL segment can be pushed and found. Run it again after every configuration change.
repo1-retention-full=2 keeps two full backups. pgBackRest expires older backups and removes only the WAL that those backups no longer need. This is the retention safety your own script would have to reimplement.
To do the PITR from the earlier chapter, stop PostgreSQL and restore with a target:
pgbackrest --stanza=main --delta --type=time \
--target="2026-11-27 10:15:00+00" --target-action=promote restore--delta reuses files already in the data directory when their checksums match, which is faster than restoring into an empty directory. pgBackRest writes the recovery settings (restore_command, the target, and recovery.signal) for you. You start PostgreSQL afterward and it replays WAL to the target.
A minimal Barman setup
On the backup server, define the PostgreSQL server in /etc/barman.d/pg.conf:
[pg]
description = "Production database"
conninfo = host=pg1.example.com user=barman dbname=postgres
streaming_conninfo = host=pg1.example.com user=streaming_barman dbname=postgres
backup_method = postgres
streaming_archiver = on
slot_name = barman
create_slot = auto
retention_policy = RECOVERY WINDOW OF 7 DAYSThe barman role needs enough privileges to run backups, and streaming_barman needs the REPLICATION attribute. Both need matching entries in pg_hba.conf. The Barman documentation lists the exact grants for your PostgreSQL version.
Then check the configuration and run a backup:
barman check pg
barman backup pg
barman list-backups pgTo recover to a point in time onto a remote host, use SSH to reach the target machine:
barman recover pg latest /var/lib/postgresql/16/main \
--remote-ssh-command "ssh [email protected]" \
--target-time "2026-11-27 10:15:00+00"Barman writes the recovery configuration on the target. You start PostgreSQL there and let it replay WAL.
Choosing between them
Neither tool is better in general. These criteria usually decide the choice:
- Where the backup process should live. If you want the backup server to pull data and hold the catalog, so that a compromised database host cannot touch its own backups, Barman's model fits. If you want to push backups straight to object storage from each database host, pgBackRest's model is simpler.
- Database size and speed. pgBackRest's parallel, compressed backups and its differential and incremental types suit multi-terabyte clusters where full backups are too slow. Barman can do similar work but depends more on your chosen backup method.
- Number of servers. Barman is built to manage many PostgreSQL servers from one place. pgBackRest handles many clusters too, but each one needs its own stanza and configuration.
- Operational familiarity. Pick the tool your team can run during an incident. A tool nobody has restored with is a risk.
- Managed services. If your cloud provider offers managed backups, you may not need either tool. These tools need access to the data directory or the replication protocol, which hosted services often restrict.
Common mistakes
- Never testing a restore. Both tools report success when a backup finishes, but only a restore proves it works. Schedule test restores, as covered in the verification chapter, and try a PITR as well.
- Skipping
checkafter changes. A mistyped stanza name inarchive_commandleaves PostgreSQL retrying and accumulating WAL. - Keeping the repository on the same disk as the database. A disk or host failure then destroys both the data and its backups. Use a separate host or object storage.
- Mixing retention policies. If you also run a cleanup script on the repository directory, you can delete WAL that a retained backup needs. Let the tool manage expiry.
- Ignoring version upgrades. The tool version on the restore host must be able to read what the backup host wrote. Keep versions aligned, and read the release notes before upgrading.
Exercise
Your team runs 15 PostgreSQL servers, wants the backup system on a separate host that pulls data, and wants a central catalog of all backups. Which tool fits the stated design more naturally, and what command confirms its setup for one server named orders?
Show answer
Barman fits more naturally. It runs on a dedicated backup server, pulls base backups and WAL from each database server, and is designed to manage many servers from one place. For the server named orders, barman check orders confirms connectivity, WAL archiving or streaming, and the other prerequisites.
Exercise
Your pgBackRest stanza is named main. After editing archive_command, how do you confirm that WAL archiving works, and why must you do this before relying on the next backup?
Show answer
Run pgbackrest --stanza=main check as the postgres user. It verifies that a WAL segment can be pushed to the repository and found again. Without a working archive, PostgreSQL keeps unarchived WAL in pg_wal, which can fill the disk, and the backups cannot be used for point-in-time recovery.