How to back up a PostgreSQL database on Linux (pg_dump + restic)
Understand the moving parts of a reliable PostgreSQL backup on Linux: logical dumps, encrypted off-site storage, retention, monitoring, and restore evidence.

Logical dumps vs physical backups
There are two broad ways to back up PostgreSQL. A logical backup exports database objects as SQL or an archive. It is portable across architectures, supports selective restore in archive formats, and is generally suited to moving forward to a newer PostgreSQL version. The exact source-to-target version and installed extensions still need testing.
A physical backup copies the PostgreSQL cluster in a database-consistent way and is the basis for point-in-time recovery when combined with continuous write-ahead log archiving. For many small single-server applications, scheduled logical dumps are a manageable starting point; tighter recovery-point targets may require the physical route.
Take a consistent dump with pg_dump
pg_dump creates a consistent export even while normal readers and writers continue to use the database. A custom-format archive is compressed by default and supports flexible, selective recovery through pg_restore.
Credential handling, client-server version compatibility, timeouts, and partial-output cleanup belong to the backup job. A command that works once in an interactive shell is not yet safe automation.
Include cluster-level dependencies
One pg_dump covers one database, not cluster-wide roles and tablespaces. Inventory those dependencies and decide whether to export them with PostgreSQL tooling or recreate them from controlled configuration. Extensions need the right package and compatible version on the recovery target before their objects can be restored.
Ownership and privileges are part of application behavior. A restore that contains every table can still fail at runtime when the service account no longer owns a sequence or lacks permission on a schema. Add authentication and representative application queries to the acceptance check.
Encrypt and store the dump off-host with restic
A dump left on the same server as the database does not help if the disk fails, the host is compromised, or someone drops the wrong table. Copy it to storage you control, encrypted, and keep previous versions. restic encrypts on the client, deduplicates, and retains each snapshot.
- Initialize a repository against a supported remote storage target.
- Back up the dump directory on a schedule.
- Apply a reviewed retention policy and schedule repository cleanup separately.
- Store a protected recovery copy of the restic password away from the server; the repository cannot be decrypted without it.
Automate it and set retention
A complete scheduled job creates a consistent dump, publishes it only after success, encrypts it off-host, applies retention without overlapping other repository work, and reports both failure and absence.
Retention should reflect how long deletion or corruption can go unnoticed. Monitoring must live outside the database host so a failed machine cannot silence the same signal intended to report it.
Test the restore
A backup that has never been restored is not proven. Periodically restore into a scratch database and check that the data is intact, and note how long it takes so your recovery estimate reflects a real run.
Validate schema, extensions, ownership expectations, representative row counts, and application behavior. Production replacement should be a separate reviewed step after the rehearsal passes.
Use a PostgreSQL target at the intended recovery version and retain the restore logs. Warnings about missing roles, ownership, extensions, or unsupported settings are evidence to resolve, not cosmetic noise. Repeat the test after major database or extension upgrades.
Where Rested fits
Rested coordinates database-aware runs, protected user-owned storage, retention, multi-server visibility, failure history, and guided recovery without requiring teams to maintain per-host scheduler glue. Docker and network PostgreSQL sources are supported.
Technical basis
First-party references
Technical claims and limitations in this guide were checked against these primary sources. Confirm version-specific behavior when designing a production recovery process.
Related from Rested
Common questions
Frequently asked questions
How does a pg_dump + restic backup work?
pg_dump exports a consistent logical copy of the database; restic encrypts that dump on the host and uploads it to your own S3-compatible storage, keeping deduplicated, versioned snapshots you can prune with a retention policy.
Can I back up a Postgres database running in Docker?
Yes. Connect through the container or an exposed database endpoint, then protect the resulting dump as an encrypted off-host backup. Rested includes a guided source type for PostgreSQL running in Docker.
How do I restore a custom-format dump?
Custom archives are restored with pg_restore, while plain SQL dumps are replayed with psql. Rehearse into an isolated target and validate the application before considering a production cutover.
Can pg_dump provide point-in-time recovery?
No. A logical dump recovers to the state captured by that dump. Point-in-time recovery requires a physical base backup and a continuous write-ahead log archive designed and tested for that purpose.