Sub topic 14
When to Use pgBackRest or Barman
This chapter assumes you understand PostgreSQL databases, roles, WAL, base backups, and point-in-time recovery (PITR). It also assumes you can run commands on a Linux server and edit PostgreSQL configuration.
pgBackRest and Barman are backup management tools for PostgreSQL. They automate tasks that are easy to get wrong when you combine pg_basebackup, WAL archiving, shell scripts, and cron jobs. Both can manage physical backups, continuous WAL archives, retention, compression, encryption, and restore operations.
Why use a backup manager?
The built-in PostgreSQL commands are useful building blocks:
pg_dumpcreates logical backups of individual databases.pg_basebackupcreates a physical copy of a PostgreSQL cluster.- WAL archiving preserves changes after a base backup.
psqlandpg_restorerestore logical dumps.
These commands do not, by themselves, provide a complete backup policy. You must decide how to name backups, remove expired files, detect failed WAL uploads, check backup integrity, and copy data to another location.
A backup manager keeps this state and performs these checks consistently.
pgBackRest and Barman compared
Both tools support full backups, incremental or differential backups, WAL archiving, compression, retention, and remote repositories. Their operational models differ.
| Concern | pgBackRest | Barman |
|---|---|---|
| Main model | Backup and restore tool closely integrated with PostgreSQL | Backup server that manages one or more PostgreSQL servers |
| Typical strength | Fast, scripted backups with parallel processing | Centralized administration and reporting |
| Repository design | Local or remote repositories, including object storage options | Usually a dedicated backup host with configured server entries |
| Operations | Command-line driven | Command-line driven, with centralized server status |
| Good fit | Teams wanting a compact, high-performance backup system | Teams managing several PostgreSQL servers from one backup host |
Choose pgBackRest when you want high-throughput backups, parallel restore, or a repository design that can include object storage. Choose Barman when a central backup server should monitor and manage many PostgreSQL instances.
The choice also depends on your team's existing automation and support practices. A tool that operators already know is often safer than a theoretically better tool that nobody can diagnose.
A small pgBackRest workflow
A pgBackRest configuration names a PostgreSQL stanza, which is a registered backup configuration for one cluster. The following example uses a local repository:
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-compress-type=zstd
start-fast=y
[main]
pg1-path=/var/lib/postgresql/16/mainAfter creating the stanza, check the configuration and take a full backup:
pgbackrest --stanza=main check
pgbackrest --stanza=main stanza-create
pgbackrest --stanza=main backup --type=full
pgbackrest --stanza=main infoThe PostgreSQL server must archive WAL through pgBackRest. A typical setting is:
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'Restart requirements depend on the setting. archive_mode requires a server restart.
A small Barman workflow
Barman normally runs on a separate backup host. Its configuration identifies the PostgreSQL server and the directory used for backups:
[main]
description = "Production PostgreSQL"
conninfo = host=db.example.com user=barman dbname=postgres
backup_method = postgres
streaming_archiver = on
backup_directory = /var/lib/barman/mainCommon administrative commands include:
barman check main
barman backup main
barman list-backup main
barman recover main latest /srv/postgresql/recoveredThe exact configuration depends on whether Barman receives WAL through streaming replication, an archive command, or both. Follow one design consistently and monitor that WAL is arriving.
Common mistakes
- Keeping backups on the same disk as the database does not protect against disk failure.
- Setting retention without checking the required recovery window can delete needed backups.
- Encrypting the repository without securely storing the encryption key can make every backup unusable.
- Monitoring only the base-backup job can miss a broken WAL archive.
- Mixing manual archive commands with a backup manager can create gaps or duplicate ownership of the archive process.
Exercise
You operate five PostgreSQL servers and want one dedicated host to report backup status for all of them. Which tool is the natural starting point, and what must you still verify?
Show answer
Barman is a natural starting point because it centralizes multiple servers. You must still verify base backups, continuous WAL arrival, retention behavior, repository protection, and a real restore.