skip to content

With pgBackRest protecting a 5 TB SaaS analytics PostgreSQL cluster, how would you design two repositories, one in object storage, to meet its RPO and RTO?

level: principalimportance: should knowfreq 27%

answer

  1. one near, one far
  2. WAL goes everywhere, backups do not
  3. per-repository schedules and retention
  4. client-side encryption is fixed
  5. read a versioned bucket as of a time

basics

~20 s

Make repo1 a nearby repository for fast restores with short retention, and repo2 an encrypted object-store repository for off-site, longer retention. archive-push feeds both, ideally asynchronously; schedule backups, retention and verify per repository; restore from the nearest one.

solid answer

~50 s

Start from the two numbers. The RPO depends on how far archiving lags. The RTO depends on copy time plus WAL replay, so it favours a nearby repository and recent backups. In pgBackRest, `archive-push` writes WAL to **every** configured repository, but `backup` goes to repo1 unless `--repo` is given, so each repository gets its own backup schedule and its own `repoN-retention-*`. A good split: **repo1** on a dedicated backup host or volume near the cluster, with block incremental and short retention, for fast and delta restores. **repo2** in object storage, encrypted client-side (`repo2-cipher-type=aes-256-cbc`), with longer retention and ideally versioning so `repo-target-time` can read it as of a past time. Enable `archive-async` so an unreachable repo2 does not hold WAL back for repo1. Run `verify` against each repository, and remember the cipher cannot be changed once the stanza exists.

code

ini · 25 lines
ini
[global]
repo1-path=/backup/pgbackrest
repo1-retention-full=2
repo1-bundle=y
repo1-block=y

repo2-type=s3
repo2-path=/analytics
repo2-s3-bucket=pgbackrest-analytics-offsite
repo2-s3-endpoint=s3.example.net
repo2-s3-region=eu-central
repo2-cipher-type=aes-256-cbc
repo2-cipher-pass=<long random passphrase>
repo2-retention-full-type=time
repo2-retention-full=35
repo2-bundle=y
repo2-block=y

compress-type=zst
process-max=8
archive-async=y
spool-path=/var/spool/pgbackrest

[analytics]
pg1-path=/var/lib/postgresql/18/main

go deeper

for a junior

Recall that pgBackRest supports several repositories, repo1 to repoN, and that WAL is pushed to all of them while backups go to one at a time.

for a middle

Explain per-repository options: separate backup schedules with --repo, separate retention, client-side encryption, and why archive-async matters with two repos.

for a senior

Show the failure handling: one repository down, a full pg_wal, a mixed info status, weak subkeys after 2.59.3, and verify run against each repository.

for a principal

Own the trade-offs: repository placement against failure domains, retention and cost per tier, restore-repository choice for RTO, and drills that prove them.

## Start from the two numbers The definitions of RPO and RTO belong to the engine-neutral recovery-objectives topic. Here the question is how pgBackRest's repository model serves them: - **RPO** is bounded by how much WAL has not yet reached a repository. Asynchronous, parallel `archive-push` and an alert on archive lag keep that small. - **RTO** is the time to copy a backup back plus the time to replay WAL from that backup to the target. A repository close to the cluster, recent backups and delta restore cut the first part. A more recent backup cuts the second. ## What pgBackRest does with two repositories - **WAL**: `archive-push` always pushes to **all** configured repositories. If one is unreachable, WAL still goes to the others. That only works well with `archive-async=y`; otherwise the healthy repository can get only one segment ahead of the failing one. WAL that reaches no repository stays in `pg_wal`. - **Backups**: `backup` writes to the highest-priority repository (repo1) unless you pass `--repo`. Each repository needs **its own schedule**, which is useful because backup types and retention should differ. - **Setup and expiry**: `stanza-create` creates the stanza in every repository. `expire` applies each repository's own `repoN-retention-*` options. - **Restore**: without `--repo`, restore takes the latest backup from the first repository that has backups. For a time target, it searches the repositories in order for a backup that covers that time. Name the repository you want. - **Health**: `info` reports a stanza status of `mixed` when one repository is unhealthy. ## A layout for the analytics cluster | | repo1 | repo2 | |---|---|---| | where | dedicated backup host or volume, outside the database host's failure domain | object storage in another region or account | | purpose | fast and delta restores, standby rebuilds | off-site copy, longer history, ransomware recovery | | backups | weekly full plus daily diff, block incremental | weekly full plus diffs, block incremental to reduce upload volume | | retention | `repo1-retention-full=2` | `repo2-retention-full-type=time`, about 35 days | | protection | filesystem permissions, run as `postgres` | `repo2-cipher-type=aes-256-cbc`, bucket versioning and object lock | ## Protecting the repositories themselves - **Encryption is client-side** and is fixed once the stanza is created and checked: you cannot change `repoN-cipher-type` or its passphrase in place. Store the passphrase outside the database host, because a restore without it is impossible. - **2.59.3** fixed weak encryption subkeys and salts that were generated when OpenSSL could not get randomness from the operating system. A repository found to have a weak subkey in `archive.info` or `backup.info` needs the stanza created in a **new** repository. Upgrading does not replace a weak subkey. - **Versioned storage**: with versioning (and ideally object lock) enabled on the bucket, `repo-target-time` lets restore, verify and other readers see repo2 **as it was at a past time**. That recovers from deletion or corruption by accident or malware. It requires `--repo`. - **Verify per repository** on a schedule. On object storage, a verify reads every object, so budget for the requests and the transfer. ## Watching whether the design still holds - `pgbackrest info --output=json` per repository gives the last backup's stop time and the newest archived WAL. Alert when either falls behind the RPO, or when the stanza status is `mixed`. - The asynchronous `archive-push` log shows errors per repository before `pg_wal` growth becomes a disk alert. - Repository size against retention: with count-based retention, each repository briefly holds one extra full before expiry, so capacity must allow N+1. - Restore duration from each repository, measured in drills, is the only honest RTO figure. Re-measure it when the data grows. ## Trade-offs to decide 1. **Placement of repo1**: on the database host it is fastest, but it shares that host's failure domain. A dedicated backup host costs a machine plus pgBackRest's remote configuration (`pg1-host` on the repository side). 2. **Full cadence on repo2**: fulls to object storage are the expensive upload. Block incremental keeps diffs small, but long chains lengthen restores. 3. **Retention split**: short on repo1, where restores are fast, and long on repo2, where copies are cheap and safe. The PITR window differs per repository. 4. **Which repository restores first**: the nearby one for speed, the off-site one when the nearby one is suspect. Only a drill from each repository shows the real RTO.

  • With two pgBackRest repositories and archive-async off, what happens to WAL when the object store is unreachable?
    archive-push still tries every repository, but each `archive_command` call fails while repo2 is down. The healthy repo1 can then get only one segment ahead of repo2, and PostgreSQL keeps the unarchived WAL in `pg_wal`, which grows. With `archive-async=y`, pgBackRest keeps pushing to the reachable repository. Only WAL that reaches no repository at all stays behind in `pg_wal`.
  • What did pgBackRest 2.59.3 change for encrypted repositories, and what is the remedy if you were affected?
    Earlier versions did not check for an error when generating random data. If OpenSSL could not read OS randomness, encryption subkeys and salts were built from memory contents. 2.59.3 reports that error instead. Because the subkeys in `archive.info` and `backup.info` are created once by `stanza-create`, upgrading does not replace a weak one. The remedy is creating the stanza in a new repository, plus a new full backup.
  • How does pgBackRest's repo-target-time help after backups in an object-store repository are deleted or overwritten?
    On storage with versioning enabled, pgBackRest can read the repository as it was at a given time. Commands such as restore, verify and info then see the objects as they existed before the damage. `--repo` must name the repository. Object lock on S3, or soft delete on GCS and Azure, keeps those old versions from being removed too.

  • Every pgBackRest backup is written to all configured repositories automatically.
  • archive-push sends WAL only to repo1 and lets repo2 copy it later.
  • Retention is one global setting shared by every repository.
  • Encryption can be switched on for an existing stanza by editing pgbackrest.conf.
  • Relying on the bucket's server-side encryption makes repo-cipher-type redundant.
  • Restore always picks the repository with the newest backup.

Assumes pgBackRest 2.59 (2.59.3), which fixed weak encryption subkeys on encrypted repositories; repo-target-time for versioned storage has been available since 2.54.