PostgreSQL Backup with pgBackRest: Full, Incremental & Point-in-Time Recovery

pg_dump is a fine tool for small databases, but it takes a logical snapshot: restores are slow on large data, and you can only go back to the moment the dump ran. Production PostgreSQL needs physical backups plus continuous WAL archiving, which lets you restore to any point in time, such as one second before somebody ran DELETE without a WHERE.

pgBackRest is the most widely used open-source tool for exactly that. This guide sets it up on PostgreSQL 18 on Rocky Linux 10: stanza creation, WAL archiving, full and differential backups, encryption, retention, scheduling, verification, restore, and point-in-time recovery.

Table of Contents

  1. Project status in 2026: read this first
  2. How pgBackRest works
  3. Backup types compared
  4. Prerequisites
  5. Step 1: Install pgBackRest
  6. Step 2: Create the repository and configuration
  7. Step 3: Configure PostgreSQL for archiving
  8. Step 4: Create the stanza and check
  9. Step 5: Take backups
  10. Step 6: Schedule backups
  11. Step 7: Restore and point-in-time recovery
  12. Off-site repositories: S3 and a dedicated repo host
  13. Monitoring and verification
  14. SELinux and firewall notes
  15. Troubleshooting
  16. FAQ

1. Project status in 2026

pgBackRest had an unusual year, and anyone choosing a backup tool should know it.

Date (2026)Event
19 JanRelease 2.58.0
27 AprThe maintainer announced that pgBackRest was no longer being maintained and archived the repository, citing lack of sponsorship after the end of corporate funding
4 and 7 MayUpdates saying a sponsor coalition was likely to fund continued work; the maintainer reminded users that the current release worked and there were no critical outstanding bugs
18 MayAnnouncement: pgBackRest will continue, funded by a coalition of sponsors rather than a single company
20 JulRelease 2.59.0 with PostgreSQL 19 (beta) support
OctFurther releases published; check the official release page for the current number

What this means for you:

  • The project is active again and supports PostgreSQL 18 (support arrived in 2.55.0).
  • It is free and open source under the MIT license.
  • The episode shows the risk of single-maintainer projects. Keep your restore procedure documented and tested, and watch the project’s news page. Percona stated at the time that it would continue to support pgBackRest for its customers.
  • Alternatives exist (Barman, WAL-G, pg_basebackup plus WAL archiving). The concepts in this guide carry over.

2. How pgBackRest works

  PostgreSQL server (primary)                       Repository (disk, remote host, or S3)
 +--------------------------------------+          +---------------------------------------+
 |  data directory  /var/lib/pgsql/data |          |  /var/lib/pgbackrest                  |
 |                                      |          |                                       |
 |  WAL segments --> archive_command ---+--------> |  archive/main/   (WAL stream)         |
 |   (continuous)    pgbackrest         |          |                                       |
 |                   archive-push       |          |  backup/main/    (full + diff + incr) |
 |                                      |  backup  |    20261124-020000F                   |
 |  pgbackrest backup  ----------------+--------> |    20261124-020000F_20261125-020000D  |
 +--------------------------------------+          +---------------------------------------+
                                                      |
                              restore (latest, or to a time / LSN / named restore point)
                                                      v
                                          new data directory + WAL replay = recovered database

Key terms:

TermMeaning
StanzapgBackRest’s name for one PostgreSQL cluster and its backup/archive configuration
RepositoryWhere backups and archived WAL are stored
ArchiveThe continuous stream of WAL files that makes PITR possible
Backup setA full, differential or incremental backup
PITRPoint-in-time recovery: restore a backup, then replay WAL up to a chosen moment

3. Backup types compared

TypeContainsRestore needsUse
FullEverythingItselfWeekly or monthly baseline
DifferentialChanges since the last fullLast full + this diffDaily
IncrementalChanges since the last backup of any typeFull + diff (if any) + all incrementals in the chainFrequent, small backups

A common schedule: full weekly, differential daily. Retention is based on counts of full backups, and WAL is kept as long as any retained backup needs it.

4. Prerequisites

RequirementDetail
PostgreSQL18 installed and running, see PostgreSQL 18 on Rocky Linux 10.2
DiskRepository space of at least 1x to 2x the database size for a start, ideally on a different disk or host than the data
Accesssudo and the postgres OS user
TimeSynchronized (chrony), because backup labels and PITR use timestamps

A repository on the same disk as the database is not a backup. It is a convenience copy. Put at least one repository on separate storage, and ideally off-site (section 12).

5. Step 1: Install pgBackRest

pgBackRest is distributed through the PostgreSQL community (PGDG) repositories and many distributions. On Rocky Linux 10 the common route is PGDG:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm

If you installed PostgreSQL from the native AppStream packages, avoid mixing PostgreSQL server packages from PGDG. Install only pgbackrest from PGDG’s common repository, and disable the PostgreSQL-version repositories:

sudo dnf config-manager --disable 'pgdg1*'
dnf repolist --all | grep -i pgdg
sudo dnf install -y --enablerepo=pgdg-common pgbackrest
pgbackrest version

Verify that pgdg-common provides the package (dnf info pgbackrest) and that the version matches what you intend to run. Pin the version in change control; do not let an unattended update change your backup tool.

6. Step 2: Create the repository and configuration

sudo mkdir -p /var/lib/pgbackrest /etc/pgbackrest /var/log/pgbackrest
sudo chown postgres:postgres /var/lib/pgbackrest /var/log/pgbackrest
sudo chmod 750 /var/lib/pgbackrest

# Generate an encryption passphrase and store it OFF the server too
openssl rand -base64 48

Create /etc/pgbackrest/pgbackrest.conf:

[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-retention-diff=7
repo1-cipher-type=aes-256-cbc
repo1-cipher-pass=PASTE_THE_GENERATED_PASSPHRASE_HERE
repo1-bundle=y
repo1-block=y

process-max=2
start-fast=y
compress-type=zst
log-level-console=info
log-level-file=detail
log-path=/var/log/pgbackrest

[main]

pg1-path=/var/lib/pgsql/data

sudo chown postgres:postgres /etc/pgbackrest/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
OptionMeaning
repo1-pathLocal repository location
repo1-retention-full=2Keep two full backups (and their dependent diff/incr)
repo1-retention-diff=7Keep seven differentials
repo1-cipher-*Encrypt the repository. Lose the passphrase and you lose the backups
repo1-bundle / repo1-blockBundle small files and enable block-level incremental backups; check pgbackrest help backup on your version
process-maxParallel processes; raise carefully on busy servers
start-fast=yForce an immediate checkpoint at backup start
[main]The stanza name; pg1-path is the data directory

For the native packages the data directory is /var/lib/pgsql/data. With PGDG PostgreSQL packages it is /var/lib/pgsql/18/data.

Store the passphrase in a password manager and in a sealed envelope or vault. Do not keep the only copy on the server being protected.

7. Step 3: Configure PostgreSQL for archiving

Add these settings to /var/lib/pgsql/data/postgresql.conf (or a file included from it):

archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'
wal_level = replica
max_wal_senders = 3
archive_timeout = 60

archive_mode requires a restart:

sudo systemctl restart postgresql.service
sudo -u postgres psql -c "SHOW archive_mode;" -c "SHOW archive_command;"

archive_timeout = 60 forces a WAL switch at least once a minute on quiet servers, so your recovery point objective (RPO) is bounded even when there is little write activity.

8. Step 4: Create the stanza and check

sudo -u postgres pgbackrest --stanza=main stanza-create
sudo -u postgres pgbackrest --stanza=main check

check forces a WAL switch, archives it, and confirms the whole chain works. Do not skip it: a silently failing archive_command is the most common way backups turn out to be useless.

sudo -u postgres pgbackrest info

9. Step 5: Take backups

# First backup must be a full backup
sudo -u postgres pgbackrest --stanza=main --type=full backup

# Later: differential and incremental
sudo -u postgres pgbackrest --stanza=main --type=diff backup
sudo -u postgres pgbackrest --stanza=main --type=incr backup

sudo -u postgres pgbackrest info

Example info output (abridged):

stanza: main
    status: ok
    wal archive min/max (18): 000000010000000000000010/000000010000000000000019

    full backup: 20261124-020000F
        timestamp start/stop: 2026-11-24 02:00:00 / 2026-11-24 02:03:41
        database size: 5.2GB, database backup size: 5.2GB
        repo1: backup size: 1.3GB

Look for status: ok, an advancing WAL range, and a reasonable compression ratio. Add a test table and insert rows between backups so you can prove restores later.

10. Step 6: Schedule backups

A systemd timer is easier to monitor than cron.

# /etc/systemd/system/pgbackrest-full.service
[Unit]
Description=pgBackRest full backup
After=postgresql.service

[Service]
Type=oneshot
User=postgres
ExecStart=/usr/bin/pgbackrest --stanza=main --type=full backup
# /etc/systemd/system/pgbackrest-full.timer
[Unit]
Description=Weekly pgBackRest full backup

[Timer]
OnCalendar=Sun *-*-* 02:00:00
Persistent=true
RandomizedDelaySec=300

[Install]
WantedBy=timers.target

Create the equivalent pgbackrest-diff.service and .timer with --type=diff and OnCalendar=Mon..Sat *-*-* 02:00:00, then:

sudo systemctl daemon-reload
sudo systemctl enable --now pgbackrest-full.timer pgbackrest-diff.timer
systemctl list-timers 'pgbackrest*'

Check the binary path with command -v pgbackrest. Make sure a failed unit raises an alert (see Prometheus Alertmanager guide for notifications).

11. Step 7: Restore and point-in-time recovery

Practice this before you need it. Ideally restore onto a separate test server.

Restore the latest state

sudo systemctl stop postgresql.service

# Delta restore: reuse files that already match, restore only what differs
sudo -u postgres pgbackrest --stanza=main --delta restore

sudo systemctl start postgresql.service
sudo -u postgres psql -c "SELECT pg_is_in_recovery();"

For a restore into an empty data directory, remove --delta. pgBackRest writes the recovery settings and the recovery.signal file; PostgreSQL replays archived WAL and then opens for connections.

Point-in-time recovery

Scenario: a developer dropped a table at 10:42. Recover to 10:41:00.

sudo systemctl stop postgresql.service

sudo -u postgres pgbackrest --stanza=main --delta \
  --type=time "--target=2026-11-24 10:41:00+07" \
  --target-action=promote \
  restore

sudo systemctl start postgresql.service
sudo journalctl -u postgresql.service -n 40 --no-pager
OptionMeaning
--type=timeRecover to a timestamp. Use the server’s time zone or an explicit offset
--type=lsn / --type=nameRecover to an LSN or a named restore point created with pg_create_restore_point()
--type=immediateStop as soon as the backup is consistent
--target-action=promoteOpen the database read-write once the target is reached
--set=<label>Restore from a specific backup set instead of the latest

Choose the target just before the mistake. If recovery stops too early or too late, restore again with a different target; the repository is unchanged.

After a PITR, take a new full backup so the new timeline is protected.

Restore only part of the cluster

You can restore specific databases with --db-include, and relocate directories with --link-map or --tablespace-map. Use these on a scratch host first.

12. Off-site repositories

Keep more than one copy:

[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2

repo2-type=s3
repo2-path=/pgbackrest
repo2-s3-bucket=my-pg-backups
repo2-s3-endpoint=s3.example.com
repo2-s3-region=ap-southeast-3
repo2-s3-key=ACCESS_KEY
repo2-s3-key-secret=SECRET_KEY
repo2-retention-full=4
repo2-cipher-type=aes-256-cbc
repo2-cipher-pass=ANOTHER_LONG_PASSPHRASE

Run backups to a chosen repo with --repo=2, and WAL is pushed to all repositories. Use bucket policies, versioning, and object lock if available, and store credentials in a file readable only by postgres.

Dedicated repository host: for stronger isolation, run the repository on a separate backup server over SSH or TLS, so a compromised database server cannot delete its own backups. This is the recommended design for important systems and is described in the project’s user guide.

For cold, long-term copies, you can export backup sets to tape; see Linear Tape-Open (LTO) Explained.

13. Monitoring and verification

CheckCommand or signalFrequency
Stanza healthpgbackrest info shows status: okDaily, alert if not
Archive workingSELECT * FROM pg_stat_archiver; shows no growing failed_countContinuously
Repository integritypgbackrest --stanza=main verifyWeekly
Restore testRestore to a scratch server and run queriesAt least monthly
Last backup ageAlert if the last full or diff is older than the schedule allowsContinuously
Repository free spaceDisk usage alert at 80%Continuously
sudo -u postgres psql -c "SELECT archived_count, failed_count, last_archived_wal, last_failed_wal FROM pg_stat_archiver;"
sudo -u postgres pgbackrest --stanza=main verify

Export pg_stat_archiver metrics and backup age to your monitoring system. See Prometheus and Grafana on Rocky Linux 10.

14. SELinux and firewall notes

  • SELinux: archive_command runs inside the PostgreSQL process domain, so the repository and log paths must be writable from that context. If archiving fails with permission errors while file permissions look right, check sudo ausearch -m AVC -ts recent and fix labels as described in the SELinux troubleshooting guide. Prefer a targeted label on the repository directory over a custom policy module.
  • Remote repository host or TLS server: open only the required port to the database server’s address with a rich rule; see the firewalld guide.
  • S3 repositories: allow outbound HTTPS to the endpoint.

15. Troubleshooting

SymptomLikely causeFix
archive_command fails; WAL piles up in pg_walpgBackRest error, repo full, wrong stanzajournalctl -u postgresql, /var/log/pgbackrest/; fix and verify with check; watch disk usage of pg_wal
ERROR: [055]: unable to load info file or stanza not foundStanza not created or wrong namestanza-create; confirm --stanza=main in archive_command
WAL segment ... was not archived before the 60000ms timeoutArchiving slow or failingCheck pg_stat_archiver; raise archive-timeout only after fixing the cause
backup command requires option: pg1-pathConfig not loaded or stanza section missingCheck /etc/pgbackrest/pgbackrest.conf and run as postgres
unable to find primary cluster - cannot proceedPostgreSQL stopped, wrong socket or pathStart PostgreSQL; check pg1-path, pg1-socket-path
permission denied writing to the repositoryDirectory owner or SELinuxchown postgres:postgres; check ausearch -m AVC
archive_mode shows off after editingNo restartRestart PostgreSQL (reload is not enough)
cipher ... passphrase mismatch / cannot decryptWrong or changed repo1-cipher-passUse the original passphrase; the passphrase of an existing repo cannot be changed in place
database system identifier does not matchCluster re-created or restored from another serverstanza-upgrade or a new stanza; do not reuse a stanza for a different cluster
Backup very slowSingle process, slow disk, or networkRaise process-max, use compress-type=zst, enable block incremental, check I/O
Restore: PostgreSQL refuses to startData directory not empty (no --delta), wrong permissionsUse --delta or empty the directory; restore as postgres; check postgresql.auto.conf
PITR stops at the wrong timeTime zone or target formatUse an explicit offset; inspect logs for “recovery stopping before commit”
Disk fills after restore failureWAL replay needs spaceProvision space for WAL; clean up failed attempts
pgbackrest: command not found in timerPath differs in systemdUse the full path from command -v pgbackrest
After PostgreSQL major upgrade, backups failStanza tied to the old versionRun pgbackrest stanza-upgrade after upgrading the cluster, then take a new full backup

16. FAQ

Is pgBackRest still maintained?
Yes. It was announced as unmaintained in April 2026, then a coalition of sponsors funded its continuation in May 2026, and new releases followed.

pgBackRest or pg_dump?
Use both when it makes sense. pgBackRest gives fast physical backups and PITR for production. pg_dump is useful for logical exports, partial restores, and upgrades between major versions.

Does pgBackRest support PostgreSQL 18?
Yes, since release 2.55.0, and later releases add support for newer versions as they appear.

How often should I run backups?
A weekly full and daily differential is a common start, with WAL archived continuously. Tighten it according to your recovery point and recovery time objectives.

Can I back up from a standby?
Yes. pgBackRest can take backups from a standby to reduce load on the primary; see PostgreSQL Streaming Replication on Rocky Linux 10 for the replication setup.

What if I lose the encryption passphrase?
The encrypted repository cannot be read, and there is no recovery. Keep the passphrase in at least two secure places.

Do backups include roles and global objects?
Yes. A physical backup includes the whole cluster, including roles and all databases.

Can I use pgBackRest for n8n or other PostgreSQL-backed apps?
Yes. Any application using PostgreSQL benefits. For application-level export routines, see n8n Backup, Upgrade & Disaster Recovery Strategy.

(Visited 22 times, 1 visits today)

You may also like