STK-70Default Open source
Use pg_dump and pgBackRest for Postgres backups
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.
Review by
2027-04-30
How to do it
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, and copies go off the machine as Back up off the machine says. Choose something else when you use a managed Postgres, and keep its built-in recovery plus your own nightly pg_dump.
Examples
Shell example
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
# /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
How to 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.
Sources
Related rules
- OPS-44 Set recovery targets in Operations and observability
- OPS-45 Back up off the machine in Operations and observability
For agents: this playbook is free to use under CC 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.