---
title: "Use pg_dump and pgBackRest for Postgres · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/operations-tools/postgres-backups
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use pg_dump and pgBackRest for Postgres backups

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Operations tools](https://agentwranglers.se/playbook/stack/operations-tools)
- Rule: Take a nightly `pg_dump` of every Postgres database, and add pgBackRest for point-in-time recovery once losing a day of data costs too much.
- Cost: Open source. Both tools are free. The storage that holds the copies is paid.
- How: `pg_dump` ships with Postgres under the PostgreSQL licence. Postgres 18.6 is current, and version 18 is supported until November 2030. A dump restores into any newer version, so it is also your way out. pgBackRest reached 1.0 in April 2016 and is under MIT. Version 2.60.0 came out on 18 October 2026. It adds parallel, encrypted backups to S3, Azure or GCS, and replays WAL to any point in time. The targets come from [Set recovery targets](https://agentwranglers.se/playbook/operations/disaster-recovery/recovery-targets), and copies go off the machine as [Back up off the machine](https://agentwranglers.se/playbook/operations/disaster-recovery/off-site-backups) says. Choose something else when you use a managed Postgres, and keep its built-in recovery plus your own nightly `pg_dump`.
- Check: The newest backup is younger than the recovery point objective. A restore into an empty server, run in the last 3 months, finished faster than the recovery time objective.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```sh
pg_dump --format=custom --file="orders-$(date +%F).dump" "postgresql://backup@db.example.com/orders"
pg_restore --list "orders-$(date +%F).dump" > /dev/null
```

### INI example

```ini
# /etc/pgbackrest/pgbackrest.conf
[global]
repo1-type=s3
repo1-s3-bucket=backups-example
repo1-s3-endpoint=s3.eu-north-1.amazonaws.com
repo1-s3-region=eu-north-1
repo1-cipher-type=aes-256-cbc
repo1-retention-full=4

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

## Sources

- [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html)
- [PostgreSQL versioning policy](https://www.postgresql.org/support/versioning/)
- [pgBackRest](https://pgbackrest.org/)

## Related rules

- [Set recovery targets](https://agentwranglers.se/playbook/operations/disaster-recovery/recovery-targets) in Operations
- [Back up off the machine](https://agentwranglers.se/playbook/operations/disaster-recovery/off-site-backups) in Operations

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/operations-tools/postgres-backups">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use PagerDuty for paging and keep schedules as code](https://agentwranglers.se/playbook/stack/operations-tools/pagerduty)
- Next: [Avoid paging tools that are shutting down](https://agentwranglers.se/playbook/stack/operations-tools/ending-paging-tools)
- [Operations tools](https://agentwranglers.se/playbook/stack/operations-tools)
