DBAtlas · Database operations atlas

Configure pgBackRest retention and run expire

PostgreSQLBackup & PITR

Command

# /etc/pgbackrest/pgbackrest.conf [global] - count based:
repo1-retention-full-type=count
repo1-retention-full=2
repo1-retention-diff=6
# Time-based alternative (at least a 14-day PITR window):
# repo1-retention-full-type=time
# repo1-retention-full=14

# Expire runs automatically after each backup; to trigger it manually:
sudo -u postgres pgbackrest --stanza=<stanza> --log-level-console=info expire

What it does

Defines how many full/diff backups (count) or how many days of full backups (time) to keep; expire deletes backups outside the policy, the diff/incr backups depending on them, and WAL archive no longer needed.

When to use it

To keep repository size under control and guarantee the RPO/PITR window requirement (e.g. being able to go back 14 days).

Caution

The PITR window is bounded by the oldest retained full backup; with weekly fulls and retention-full=2, you can go back at most about 2 weeks. repo1-retention-archive follows full retention by default; setting it lower leaves older backups usable only up to their consistency point. Expire cannot be undone.

Open in DBAtlas →

Related