Home › Documentation › Agents › PostgreSQL
PostgreSQL
Applies to PostgreSQL 13 to 17 on Linux. PostgreSQL on Windows is supported for logical backups only. Requires the Server plan.
Two methods
| Logical | Physical | |
|---|---|---|
| Mechanism | pg_dump per database | Base backup plus WAL archiving |
| Point-in-time restore | No | Yes |
| Restore to a different major version | Yes | No |
| Suitable for | Databases up to about 200 GB | Any size |
| Default schedule | Daily | Weekly base backup, continuous WAL |
Logical backups
sudo cbk config set postgresql.enabled true
sudo cbk config set postgresql.method logical
sudo cbk postgresql select --all
The agent connects over the local socket as the postgres operating system user. Roles and tablespaces are captured with pg_dumpall --globals-only alongside each run.
Physical backups
sudo cbk config set postgresql.method physical
Then add to postgresql.conf and reload:
archive_mode = on
archive_command = 'cbk postgresql archive-wal %p'
wal_level = replica
Changing archive_mode requires a restart of PostgreSQL. The agent takes a base backup weekly and uploads each WAL segment as it is completed. If the agent cannot upload, segments accumulate in pg_wal; monitor free space.
Replicas
Base backups can be taken from a streaming replica to reduce load on the primary. WAL archiving must be configured on whichever server is the primary.
Restoring
See Database restore.
Exclude the data directory from file backup
If the server also has file-level sources, exclude the PostgreSQL data directory (for example /var/lib/postgresql). A file-level copy of a running cluster is not a usable backup.
Known issue
The "transferred" figure for PostgreSQL jobs shows the size before compression. See Known issues.