PostgreSQL backups with pgBackRest

pgBackRest gives self-hosted PostgreSQL full, differential and block incremental backups, retention control, encryption and restores from a standby. This page covers how to plan and set it up so your recovery targets hold.

On this page

PostgreSQL backups with pgBackRest: what it does and when your team needs it

If your self-hosted PostgreSQL estate has a recovery point objective and a recovery time objective but no backup tool you have proven with a restore, PostgreSQL backups with pgBackRest is one of the first options to evaluate. pgBackRest is an open-source backup and restore tool for PostgreSQL that takes full, differential and block incremental backups, archives WAL so you can restore to a point in time, and writes everything to one or more repositories that can sit on a dedicated host or in object storage. The question for your team is less whether the tool can do these things and more whether you want to own the configuration, scheduling, retention, encryption and restore runbooks yourself, or hand that design to a partner and keep the knowledge in-house.

Scripts built on pg_basebackup and copies of the WAL directory can work for a single small instance, but they usually fall short once you run several clusters. The gaps tend to appear in the same places: expiring old backups without deleting the chain a restore depends on, keeping WAL continuous across failovers, encrypting repositories, and running parallel transfers on large databases. pgBackRest handles these as configured behavior, which makes it easier to review and audit. It also adds restore from a standby, which lets you take backup load off the primary. The trade-off is that the tool is a dependency your team must understand, upgrade and monitor, so you should be prepared to own its configuration and failure modes.

Before choosing, confirm three things in your own environment: where your repositories will live and who can reach them, which recovery point and recovery time targets the tool must meet, and whether your team can run restore drills on a schedule. If the answer to the third question is no, the backup tool will not be the main risk. The pgBackRest configuration reference lists the settings that control retention, encryption and parallelism, and reading it against your targets is a good first step before any build work starts.

Backup types, retention and repository options and when each fits

This table compares the backup types, repository locations, retention modes, encryption and parallelism settings that shape a pgBackRest design. Read each row against your recovery point and recovery time targets, then check the trade-off column before settling on a configuration.

OptionWhat it doesTrade-offWhen it fits
Full backupCopies the entire cluster each time it runsSimplest to restore from, but largest to store and slowest to writeSmall clusters, or as the anchor for differential and incremental chains
Differential backupCopies changes since the last full backupRestores need the full backup plus one differential, and the set grows until the next fullMid-size clusters where weekly fulls are affordable and daily copies must stay small
Block incremental backupCopies only changed blocks since the prior backup of any typeSmallest backups and fastest runs, but more chained pieces to verify and keep consistentLarge databases where storage or backup window is the main constraint
Dedicated repository hostStores backups on a separate server you run, reached over SSH or TLSYou own patching, disk sizing and access controls for that hostTeams with their own data center storage and a network path that stays inside their control
Object storage repositoryStores backups in an S3-compatible or similar bucketStorage is elastic and easy to replicate, but latency and egress shape restore speedOff-site copies, or environments where a second site needs fast access to backups
Count-based retentionKeeps a number of full backups, set with repo1-retention-fullWith repo1-retention-full=2, three complete full backups must exist before the oldest expiresPredictable storage use when backup frequency is steady
Time-based retentionKeeps backups for a number of days, with the value measured in daysStorage use varies with backup frequency, so confirm the retained count in a test runCompliance periods expressed in days, such as a stated number of days of recoverability
Encryption of the repositoryEncrypts backup data before it leaves the database hostAdds key handling duties, and losing the passphrase makes backups unreadableOff-site or shared repositories where the storage operator should not read data
Parallel processesRuns several backup or restore workers at onceShorter runs, but more CPU, disk and network load during the window and on production I/OLarge clusters where the backup window or restore time is tight and capacity was tested first

Setting up pgBackRest for production in order

This sequence takes a PostgreSQL primary from no backups to a configured pgBackRest stanza with archiving, a first full backup, schedules, retention, encryption and a proven test restore. Each step ends with a check so the next step starts from a known state.

  1. Install pgBackRest on database and repository hosts

    Install the same pgBackRest version on the primary, each standby and the repository host, using the packages your platform team has approved. Confirm the installed version matches on every host by running the version command on each one, because mismatched versions cause avoidable problems later. Confirm the PostgreSQL service account can run the binary and that the repository host has the disk or object storage access you planned. Done means every host reports the same version and the service account can execute it without errors.

  2. Configure the stanza and repository

    Write the pgBackRest configuration file on each database host and on the repository host, defining the repository location, the PostgreSQL data directory and the stanza name for this cluster. Set the repository path or object storage bucket, and keep credentials in a file readable only by the service account. Create the stanza on the repository side, then run the check command on the primary to confirm the configuration and the stanza agree. Done means the check command completes without errors for the stanza.

  3. Enable WAL archiving on the primary

    Set archive_mode and archive_command on the primary to hand WAL segments to pgBackRest, using the archive-push operation for this stanza, then restart PostgreSQL because archive_mode requires a restart. Consider which standby will take backups, since the setting that archives WAL is applied on the primary. Switch the WAL segment once and check that a new file appears in the repository and that the archive status in the stanza information command shows the segment archived. Done means archived WAL reaches the repository without errors in the log.

  4. Take the first full backup

    Run a full backup for the stanza, either on the primary or on a standby if you plan to back up from a standby, and confirm the backup completes without errors. Read the stanza information output to check that the backup type is full, that its label appears, and that the WAL needed to make it consistent is present in the repository. This first backup is the base for every later differential and incremental backup, so do not move on until it is listed as complete. Done means the info command shows one full backup with no errors reported.

  5. Set full, differential and incremental schedules

    Schedule full, differential and incremental backups with cron, a systemd timer or your scheduler, and keep the frequencies in a runbook so the schedule can be reviewed. Agree the frequency with your recovery point target, because the interval between backups and the WAL archive together set how much data could be lost. Stagger jobs so backups do not overlap with each other or with heavy batch work. Done means the first scheduled runs have completed and the info output lists each backup type with a recent timestamp.

  6. Configure retention and encryption

    Set repository retention for full backups and for differential backups, choosing count or time retention deliberately. With the default count retention, repo1-retention-full=2 means three complete full backups must exist before the oldest is expired, and with time retention the value is measured in days. Enable repository encryption with a passphrase held in your secrets system, and store that passphrase separately from the backups so a restore is still possible if a host is lost. Check the configuration reference for the exact retention and cipher keys in your version, then confirm with the info command that expiry runs as expected. Done means retention and encryption settings are documented and an expire run reports the expected removals.

  7. Run a test restore

    Restore the latest backup to a separate host or a clean directory that is not the production data path, using the restore command with the stanza, and start that instance to confirm it reaches a consistent state. Test a point-in-time restore to a target time between two backups, and confirm the recovered data matches what you expect. Time the run and record the result, then compare it with your recovery time target. Done means the test instance starts, accepts connections and the recorded restore steps and timing are saved for the next drill.

Protecting backup repositories, keys and credentials

A pgBackRest repository holds every base backup and WAL segment needed to rebuild your database, so whoever can read, change or expire it can also undo your recovery plan. The cards below cover the controls that keep the repository, its encryption keys and its access paths separate from the database servers they protect.

Repository encryption and key handling

Enable repository encryption with repo1-cipher-type and a passphrase set in repo1-cipher-pass, so backup files are unreadable to anyone who obtains the repository without the key. Keep the passphrase out of the shared pgbackrest.conf file where other operators can read it, and store a copy in a separate secrets system. Losing the passphrase makes every backup in that repository unrecoverable, so confirm who holds a copy and test a restore using only that copy.

pgBackRest configuration reference

Separate credentials for the repository

Give the repository its own credentials, such as an object storage access key or an SSH key for the repository host, that the database server cannot use to read backups it did not write. Where the storage platform allows it, scope each key to a single bucket or path prefix. Ask your storage team how keys are rotated and who can issue new ones, because a shared key across environments removes the separation.

Network access between database and repository

Restrict traffic between the database hosts and the repository host or object storage endpoint to the ports and addresses pgBackRest needs, and deny everything else. For a dedicated repository host, limit SSH access to the pgBackRest connection from the database servers. Confirm that the repository path does not pass through hosts that serve application traffic, and log connections to the repository endpoint.

Least-privilege access for the backup user

The PostgreSQL role that pgBackRest uses needs replication and backup privileges, not superuser rights, so review its grants against the pgBackRest user guide for your version. Restrict which hosts this role can log in from in pg_hba.conf, and use certificate or SCRAM authentication instead of a shared password. Run pgBackRest under a dedicated operating system account that owns only the configuration file and the spool directory.

Who can expire or delete backups

Retention settings such as repo1-retention-full determine when old backups are removed, so a change to these values or a manual expire run can delete recovery points. Limit the accounts that can run expire or edit retention to a small operations group, and record each change in your change system. Where object storage supports versioning or object lock, enable it so that a deletion by a compromised operator account can be reversed within the retention window your storage policy sets.

Full backups kept
2

Restoring from a standby and when to choose it

When the primary server is lost, the usual goal is to bring a working primary back with as little data loss and delay as your targets allow. A hot standby that already holds recent WAL is often the fastest source, because promoting it avoids copying a full backup back to new hardware. The decision to promote is not made by PostgreSQL. The server does not detect that the primary has failed or tell the standby to take over, so your failover tooling or an operator has to decide and act. The PostgreSQL failover documentation describes promoting a standby as a separate step that external software must trigger.

  • Detection: confirm the primary is really down and not partitioned, since promoting a standby while the old primary still accepts writes creates split-brain.
  • Promotion path: promote the standby, then point applications and any remaining standbys at the new primary.
  • Repository access: pgBackRest stanzas and archive settings must be reconfigured so the new primary archives to the same repository without overwriting history.
  • Rebuilding the old primary: treat it as a new standby, not a server that rejoins unchanged.
  • Fallback: if no standby is current, restore from the repository to new hardware and accept the longer recovery time.

Before relying on this path, confirm with your own runbook how promotion, fencing and client redirection are automated in your environment.

Limits to confirm in your environment before you rely on pgBackRest

pgBackRest is only as dependable as the platform under it. The cards below list the versions, transport, storage and recovery targets to verify in your own environment before you set a backup schedule or retention policy. Each check connects to how fast and how reliably your backups can be taken and restored.

PostgreSQL major version support

Confirm every PostgreSQL major version in your fleet is still inside its support window under the PostgreSQL versioning policy. Version 14 is listed as supported until November 12, 2026, and version 18 until November 14, 2030. A backup tool is only worth standardizing on if the server versions it protects will still receive fixes while your retention period runs. Plan any upgrade before a backup chain spans a major version change.

Versioning policy

pgBackRest and PostgreSQL version compatibility

Check the pgBackRest release you plan to deploy against each PostgreSQL major version in use, including the minor release level of your primary and standbys. Confirm that the same pgBackRest version runs on the repository host, the database hosts and any restore target, because mismatched versions can block restores. Record the tested combination in your runbook so an upgrade of either side is planned as a change.

Network throughput to the repository

Measure the sustained bandwidth between each database host and the repository host or object storage endpoint during a full backup window. Parallel processes multiply load on the network and the disks, so the throughput you observe in a test sets the practical limit on backup duration. Include the path your standby uses, since a restore from a standby depends on the same link being fast enough to meet your targets.

Storage performance on repository and database hosts

Confirm the IOPS and throughput of the repository volume and the data volumes under load, not only their capacity. Compression, checksums and block incremental processing shift work onto CPU and disk at the same time that the database serves traffic. Run a timed full backup on production-sized data to see whether the chosen parallelism leaves enough headroom for queries.

Object storage behavior

If the repository lives in S3-compatible object storage, verify how the provider handles consistency, multipart uploads, lifecycle rules, versioning and request rate limits. Some providers or gateways behave differently from AWS S3 in these areas, so test them rather than assume. Confirm which operations your credentials can perform, since retention expiry and cleanup need delete rights that a restore-only account should not have.

Restore time against your recovery target

Time a full restore from the repository, and a restore from a standby, into an isolated host of comparable size. Compare the measured duration, including WAL replay to your chosen recovery point, with the recovery time objective the business has agreed. If the measured time misses that target, change the design (faster storage, closer repository, more parallel processes or a warm standby) before you rely on the schedule.

How the database host, repository and standby fit together

The diagram starts at the primary, which writes WAL to its archive and sends backups to a pgBackRest repository host or object storage across a trust boundary. A standby receives changes by streaming replication and can be used as a backup source, so backup load stays off the primary. The restore path runs from the repository back to a new primary. Check that the repository credentials sit outside the database network and that a restore has been tested from each path.

Primary, standby and repository paths, with the trust boundary between the database network and the repository.

Questions teams ask before setting up pgBackRest

What does a pgBackRest setup cost, and which parts are one-time versus recurring?

Most of the cost is labor, plus the storage and network that hold backups. The one-time work is design and first build: choosing repository hosts or object storage, writing the configuration, setting the schedule and encryption, and running the first full backup and restore test. The recurring work is storage growth, monitoring backup jobs, reviewing retention as data grows, rerunning restore tests, and applying pgBackRest and PostgreSQL updates. Cost rises with database size, change rate (which drives how much WAL and incremental data accumulate), how many days of recovery you keep, how many copies you store and in which regions, and how formal the evidence must be for auditors. Ask any quote to separate build, handover and ongoing operations, and to state which storage costs you pay directly to your cloud or data center provider.

How long does a first pgBackRest setup take?

The duration depends on the number of database clusters, their size, the number of environments (development, staging and production are often handled differently), the storage model, and how much of the restore process must be proven before go-live. A single cluster with object storage already available is a much smaller job than a fleet of clusters that need repository hosts, network rules, encryption keys and a documented restore runbook. Time is also spent waiting on access approvals, change windows and the first full backup, which runs for as long as the database takes to read. Ask for a timeline in the written scope that lists these dependencies separately, so the schedule does not hide them.

What must our team provide before a pgBackRest engagement starts?

You need to provide several things before work begins:

  • Access to the PostgreSQL servers, with a privileged account for configuration and a named owner who can approve changes.
  • A storage location for the repository, either a repository host with disk you control or an object storage bucket, plus credentials scoped to that location.
  • Network paths between database servers, repository hosts and storage endpoints, including firewall rules and DNS.
  • Key management for repository encryption, with a decision on who holds the passphrase or key.
  • A maintenance window for the first restore test and for any change that requires a PostgreSQL restart.
  • Your recovery point and recovery time targets, and the people who will sign off on a restore.
Can our in-house team set up pgBackRest without a partner?

Yes, a team with working PostgreSQL administration skills can install and configure pgBackRest, because the tool is open source and its configuration reference is public. The risk is rarely the first successful backup. It is the untested restore, the retention setting that expires copies sooner than expected, the missing alert for a failed job, or the key that nobody can find during an incident. Before deciding, check whether your team has time to run a restore drill against a timed target, keep the configuration under version control, and handle upgrades on a schedule. If those tasks are already covered, an in-house build is a reasonable choice.

When should we hire a partner for pgBackRest instead of building it ourselves?

Consider a partner when the recovery targets are tight, the environment spans several clusters or regions, backups must be encrypted and separated from production credentials, or auditors will ask for evidence of tested restores. A partner is also useful when the team lacks capacity to build, document and rehearse the process within a planned window. DeployOpen plans, implements, hardens, backs up, documents and supports self-hosted open-source platforms inside your own cloud accounts, data centers or air-gapped networks, and delivers the work under a written, fixed scope. It does not issue audit reports or certifications; independent auditors do that. Ask for a scope that includes a restore test and a handover, not only installation.

Which choices in pgBackRest affect security and compliance evidence?

The main decisions are where repositories live, how they are encrypted, who holds the keys, and whether backup credentials are separate from database credentials. Repository encryption protects copies at rest, but only if key custody is controlled and documented. Retention settings determine how far back you can recover and what evidence you can produce. Access to backup storage should be narrower than access to the database itself, so an attacker who controls a database server cannot delete its backups. Record these choices in the design, because auditors will ask who can restore data and how that access is logged. Controls mapped to frameworks such as PCI DSS or the HIPAA Security Rule should be confirmed with your assessor, since DeployOpen prepares evidence but does not attest to compliance.

How do retention settings and backup types change what we can restore?

Retention decides how many complete backups and how much WAL history remain available. In pgBackRest, the full-backup retention setting, repo1-retention-full, is a count by default: with a value of 2, three complete full backups must exist before the oldest is expired. When time-based retention is used, the value is measured in days instead. Full, differential and block incremental backups trade storage and backup time against restore speed, because a restore may need several backups in a chain. Choose the schedule from your recovery point target and the restore time you can accept, then test a restore from the oldest copy you intend to keep. Confirm the exact behavior for your pgBackRest version in the configuration reference before you set values.

What to ask for in a quote for pgBackRest implementation

A quote for a pgBackRest implementation is only as useful as the written scope behind it, so ask for that scope to name each decision explicitly rather than assuming it. DeployOpen works from a written, fixed scope and does not publish a price list, so the quote follows from the items you agree on in writing before work starts. Confirm that the scope covers the repository design: how many repository hosts or object storage targets are included, which repository holds the primary copy and which holds any secondary copy, and where the repository runs relative to the database servers. Ask for the repo1-type and related settings the team will configure, and confirm who owns the storage accounts and credentials.

Confirm that the scope also records the retention and encryption decisions as values, not as a phrase like "standard retention." For count-based retention, the repo1-retention-full value determines how many complete full backups are kept, and the pgBackRest configuration reference explains how time-based retention is measured in days instead. Ask who signed off on those numbers, how encryption keys are generated and stored, and who holds them. Then ask for the restore test evidence: a restore run from a standby, a point-in-time recovery to a named target, the measured elapsed time, and the log output kept for your records. Ask for the runbooks, the handover session, and a retest date after any change to the configuration.

Finally, confirm the handover and retest terms in writing. Ask which operational tasks move to your team, which remain under a retainer, and what happens if a schedule or retention setting changes later. A useful check before signing is to ask the provider to name the document that lists every item above, the person who approves changes to it, and the test that would prove the restore still works six months after go-live. Items left out of the written scope are the ones most likely to be missing when a recovery is needed.

How DeployOpen scopes and delivers pgBackRest work

The sequence below moves from written recovery targets to a tested, documented backup setup in your own infrastructure, so you know what was built, how it restores, and who runs it afterward.

  1. Scope recovery targets and environment in writing

    We start by recording your recovery point and recovery time targets, the PostgreSQL major versions and clusters in scope, the hosts and networks available, and where repositories may live. You review the written scope, including what is excluded, before work begins. The step closes when the scope document is agreed and signed off by the people who own the recovery targets.

  2. Design repositories, schedules and retention

    We design the repository layout: dedicated repository hosts or object storage, the full, differential and block incremental backup schedule, retention settings, encryption, and parallelism for your database sizes. Retention is set by count or by time, and the design explains what each setting keeps on disk. The step closes with a written design that your storage, security and database teams have reviewed.

  3. Configure pgBackRest on your infrastructure

    Our engineers install and configure pgBackRest on the database primary and standbys and on the repository hosts or object storage accounts you control. Credentials are scoped to the repository, and WAL archiving is enabled so point-in-time recovery is possible. The step closes when the first full backup completes and the archive shows WAL segments reaching the repository.

  4. Schedule backups and monitor their results

    We wire the agreed schedule into cron or your scheduler, set up alerts for failed or missed backups and for repository growth, and confirm the job logs are retained. Where the backup runs from a standby, we check that the standby configuration matches the design. The step closes when a deliberate failure triggers the alert in your monitoring system.

  5. Run restore tests against the targets

    We perform full restores, point-in-time restores and a restore from a standby into an isolated environment, and time each one against the recovery time target agreed in the first step. We also record the recovery point reached. Any gap between the measured results and the targets is written up with a fix. The step closes with a restore report showing measured times and the outcome of each test.

  6. Hand over runbooks and train operators

    We deliver runbooks for routine checks, backup failure, point-in-time recovery, restore from a standby and repository migration, and walk your operators through them. The runbooks name the commands, the configuration files and the owners of each action. The step closes when your team performs one supervised restore from the runbook without assistance.

  7. Agree on ongoing support if you want it

    If you want continued help, we offer retainer support covering pgBackRest upgrades, periodic restore drills, schedule and retention reviews and changes after PostgreSQL upgrades. Retainers are priced from the written scope of that support, and you can run the setup entirely in-house instead. The step closes when the support terms are agreed or the handover is marked complete.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.