pgBackRest is an open-source backup and restore tool for PostgreSQL that takes physical backups of a database cluster, archives its write-ahead log and restores the cluster to any consistent moment covered by that archive. In the field of Backup & recovery within Databases, it is one of the most widely deployed answers to a hard question: how to protect a multi-terabyte PostgreSQL cluster with predictable recovery time and verifiable integrity.
Unlike a logical tool such as pg_dump, pgBackRest copies data files at the block and file level, so a restore produces an exact physical replica of the original cluster. Its design centers on parallel processing, multiple backup types, repository encryption and cloud object storage, which makes it a common choice for production fleets rather than single small databases.
How pgBackRest protects a PostgreSQL cluster
pgBackRest works by combining periodic physical backups with continuous WAL archiving. A backup captures the data directory while the server keeps running, and the archived write-ahead log records every change made after that backup started. Replaying the log on top of a restored backup brings the cluster to a consistent state or to a chosen recovery target.
The central configuration unit is the stanza, which describes one PostgreSQL cluster: its data directory, port, host and the repositories that hold its backups. Every command, from stanza-create to restore, names the stanza it acts on. PostgreSQL hands each completed WAL segment to pgBackRest through the archive_command setting, typically pgbackrest --stanza=main archive-push %p, and the archive-get command fetches segments back during recovery.
Each backup records a manifest listing every file, its size, its timestamp and a SHA-1 checksum. The manifest allows later backups to detect what changed, lets restores verify every file, and makes it possible to rebuild only damaged or modified files with a delta restore.
The main commands and their roles are summarized below.
| Command | Purpose | Typical use |
|---|---|---|
| stanza-create | Initializes repository storage for a cluster | Once, during setup |
| check | Confirms configuration and that WAL archiving works | After setup and after changes |
| backup | Takes a full, differential or incremental backup | Scheduled, for example nightly |
| archive-push / archive-get | Stores and retrieves WAL segments | Called by PostgreSQL automatically |
| restore | Rebuilds the data directory from a backup | Recovery, cloning, replica builds |
| expire | Removes backups and WAL beyond retention | Runs after each backup |
| verify | Checks repository files against checksums | Periodic integrity audits |
Backup types and retention in pgBackRest
pgBackRest offers three backup types that trade backup time and storage against restore complexity. A full backup copies the whole cluster, a differential backup copies files changed since the last full backup, and an incremental backup copies files changed since the most recent backup of any type. Every restore still needs the full backup at the root of the chain.
| Backup type | What it copies | Depends on | Trade-off |
|---|---|---|---|
| Full | Every file in the cluster | Nothing | Slowest and largest, simplest to restore |
| Differential | Changes since the last full | One full backup | Grows over the week, short chain |
| Incremental | Changes since the last backup | Full plus prior backups | Smallest, longest dependency chain |
By default change detection works at file level using size and timestamp, with an optional checksum-based mode for stricter detection. Recent releases add block incremental backups, which store only changed blocks inside large table files and reduce storage for databases with large, sparsely updated tables.
Retention is set per repository, for example repo1-retention-full=2 keeps two full backups and everything that depends on them. The expire command then removes older backups and the WAL they no longer need. Retention therefore defines the recovery window: point-in-time recovery is possible only back to the oldest retained backup.
Repositories, performance and security features
A repository is the storage location where pgBackRest keeps backups and archived WAL. It can be a local or mounted filesystem, a dedicated backup host reached over SSH or the TLS-based pgBackRest server, or object storage such as Amazon S3, Azure Blob Storage, Google Cloud Storage and S3-compatible services. Up to four repositories can be configured per stanza, which supports a local copy for fast restores alongside an offsite cloud copy for disaster recovery.
Performance comes from parallel worker processes set by process-max, which compress, checksum and transfer files concurrently. Compression supports gzip, lz4, zstd and bzip2; lz4 favors speed, while zstd usually gives a better ratio at moderate CPU cost. Asynchronous archiving queues WAL pushes in the background so that a busy primary does not stall when the archive target is slow.
For confidentiality, repositories can use client-side AES-256-CBC encryption with a passphrase, so backups remain unreadable even if the bucket is exposed. pgBackRest also validates PostgreSQL page checksums during backup when they are enabled, which surfaces silent storage corruption before it spreads into every retained backup.
The following settings have the greatest influence on behavior.
| Setting | Typical value | What it affects |
|---|---|---|
| process-max | 2 to 16 | Parallelism and CPU load on the source host |
| compress-type | lz4 or zst | Backup speed versus repository size |
| repo1-retention-full | 2 to 4 | Recovery window and storage cost |
| archive-async | y | WAL throughput on write-heavy primaries |
| repo1-cipher-type | aes-256-cbc | Encryption of stored backups |
| backup-standby | y | Offloads file reads to a replica |
pgBackRest compared with related PostgreSQL tools
pgBackRest belongs to the physical backup family and fills the gap between the built-in pg_basebackup and enterprise suites. pg_dump produces a logical backup of a single database that is portable across versions but cannot support point-in-time recovery. pg_basebackup takes a full physical copy, and from PostgreSQL 17 it can also take incremental backups, but it leaves retention, repositories and WAL management to the operator.
| Tool | Backup level | Point-in-time recovery | Built-in retention |
|---|---|---|---|
| pgBackRest | Physical, full/diff/incr | Yes, with integrated WAL archive | Yes |
| pg_basebackup | Physical, full or incremental | Yes, with separate archiving | No |
| pg_dump | Logical, per database | No | No |
| Barman | Physical, full and incremental | Yes, with WAL streaming | Yes |
The practical difference is operational completeness: pgBackRest manages archiving, retention, verification and multi-repository storage in one tool, while simpler utilities require scripts around them. Teams that only need a nightly copy of a small database may find pg_dump sufficient, but strict recovery point objectives usually call for a physical tool with continuous archiving.
Restoring with pgBackRest and common mistakes
A restore stops PostgreSQL, rebuilds the data directory from the selected backup and writes the recovery settings so that the server replays archived WAL on startup. The --type=time option with --target selects a timestamp for point-in-time recovery, while --delta rewrites only files whose checksums differ, which can cut restore time dramatically on a large cluster that is mostly intact.
Most failures come from configuration and process, not from the tool itself. The table below lists frequent problems.
| Symptom | Likely cause | Fix |
|---|---|---|
| Backup waits for WAL and times out | archive_command not set or failing | Run the check command and read the PostgreSQL log |
| Recovery window shorter than expected | Retention too low | Raise full retention or add a second repository |
| Restore much slower than backup | Single process or remote repository | Raise process-max and keep a local repository |
| Backups unusable after key loss | Encryption passphrase not stored safely | Keep the passphrase in a separate secrets vault |
| Untested backups | No restore drills | Schedule regular test restores to a scratch host |
The most important rule is that a backup is proven only by a restore. Regular restore drills, the verify command and monitoring of archive lag together turn pgBackRest from a copying tool into a dependable recovery process.
Put simply
pgBackRest is a safety system for PostgreSQL databases. It regularly takes a complete copy of the database files and, in between, keeps a running diary of every change. If something goes wrong, it puts back the last copy and replays the diary up to the moment just before the problem.
Think of a photographer who saves a full photo album every Sunday and writes down every edit made during the week. Losing the album on Thursday is not a disaster, because Sunday’s copy plus the notes rebuild Thursday morning exactly. The key point is simple: backups only count once a restore has been tested.
In practice
An online retailer runs a 4 TB PostgreSQL cluster with one primary and two replicas. The database team configures pgBackRest with a weekly full backup on Sunday, daily differential backups and asynchronous WAL archiving. Repository one sits on a local backup server for fast restores, and repository two is an encrypted S3 bucket in another region with four weeks of retention. Backups read files from a replica to spare the primary.
One afternoon a faulty deployment deletes most rows from the orders table at 14:32. The team restores the cluster to a separate host with a time target of 14:31 and uses a delta restore on a recent clone, so only changed files are rewritten. Within about 90 minutes the missing orders are exported from the recovered copy and reinserted into production. The outcome is no lost orders and a clear audit trail of exactly which data was recovered.