Backup & Restore Foundations
Backup and restore is the foundational discipline underneath every other PostgreSQL recovery capability, from undoing a single bad DELETE to standing a cluster back up in another region.
This page builds the mental model of what a backup actually captures, how a restore turns that capture back into a running instance, and why the method you pick sets a hard ceiling on what later recovery work can achieve.
Summary
- Core Idea: A backup is a captured, self-consistent representation of cluster state that a restore process can turn back into a running PostgreSQL instance.
- Why It Matters: Every later recovery objective, from a dropped table to a lost region, is bounded by what your backups actually captured and how quickly they can be replayed.
- Key Concepts: logical backup, physical backup, consistency point, write-ahead log (WAL), restore, backup catalog.
- When to Use: Every production cluster needs a backup strategy in place before the first schema migration and before the first byte of customer data lands.
- Limitations / Trade-offs: A backup that has never been restored is only a hypothesis, and the method you choose trades restore speed against restore granularity.
- Related Topics: point-in-time recovery, disaster recovery tiers, WAL archiving, streaming replication.
Foundations
At its simplest, a backup is a copy of data taken at a known moment that a restore can use to recreate that moment on a different or later instance.
PostgreSQL supports two fundamentally different ways of making that copy, and the distinction between them shapes almost every decision in this section of the docs.
A logical backup, produced by pg_dump or pg_dumpall, asks the running database to describe its objects and data as SQL statements or an archive of that intent, so restore replays those statements against a fresh, possibly different, PostgreSQL instance.
A physical backup, produced by pg_basebackup or a tool like pgBackRest, instead copies the actual data files on disk, so restore places those files back and lets PostgreSQL's own crash-recovery machinery bring them to a consistent state.
Because a physical backup is just a copy of files that are actively being written to, it needs a way to guarantee the copy is internally coherent even though different files were copied at slightly different instants.
That guarantee comes from the write-ahead log, PostgreSQL's append-only record of every change, which the restored instance replays forward from the moment the backup started until the copy reaches a consistent state.
A logical backup sidesteps that problem entirely by asking the database to produce a self-consistent snapshot at the SQL level, using the same MVCC machinery that gives any long-running query a stable view of data.
The consistency point is the moment a backup becomes trustworthy: for a logical dump it is the instant the snapshot was taken, and for a physical backup it is the point after WAL replay catches the file copy up to a coherent state.
Restore, in both cases, is not a single action but a pipeline of locating the backup, verifying it, loading or copying it, and then bringing PostgreSQL through whatever recovery steps return it to a serving state.
A backup catalog is simply the record of what backups exist, when they were taken, and how to retrieve them, and without one a valid backup sitting in storage is indistinguishable from a corrupt one.
Mechanics & Interactions
Physical backup tools do not actually need to freeze the filesystem or stop writes, because PostgreSQL exposes a low-level API that brackets the copy operation and lets WAL fill the gap.
-- Conceptual shape of what pg_basebackup and pgBackRest do under the hood
SELECT pg_backup_start('nightly-base', fast => true);
-- ... external tool copies data files while writes continue ...
SELECT pg_backup_stop(); -- returns the WAL end position needed to replayCalling pg_backup_start does not pause the cluster; it marks the WAL position where the backup begins so recovery knows where replay must start, and pg_backup_stop records where replay must end for the copy to become consistent.
This is why a physical backup is inseparable from WAL: the files alone are an inconsistent jumble of different moments, and only replaying the WAL segments generated during the copy window turns them into a single coherent snapshot.
A logical backup has no equivalent gap to fill, because pg_dump opens one transaction with a repeatable-read snapshot and reads every object through that same frozen view, so nothing outside the dump itself needs replaying.
That difference cascades into restore behavior: restoring a physical backup always reconstructs the entire cluster as it existed at the consistency point, while restoring a logical backup can target a single table, a single schema, or the whole database, because it was never anything more than a sequence of independent SQL operations.
Backups also interact with replication in a way that surprises newcomers, because a streaming replica is not a backup at all, only a continuously moving copy that faithfully applies every mistake the primary makes, including a dropped table or a corrupted row.
A replica protects against hardware failure, while only an independent backup, taken and retained on its own schedule, protects against operator error or logical corruption, and conflating the two is one of the most common gaps in an otherwise well-run cluster.
The backup method you choose also determines what later recovery tooling can do with it, because point-in-time recovery requires a physical base backup plus a continuous WAL archive, and it cannot be built from a logical dump alone.
Advanced Considerations & Applications
At scale, the choice of backup method becomes an economic and operational trade-off as much as a technical one, weighing restore precision against storage cost and operational complexity.
| Approach | Strength | Weakness | Best Fit |
|---|---|---|---|
Logical (pg_dump) | Selective, portable across versions and platforms | Restore is slow at multi-terabyte scale | Object-level recovery, cross-version migration |
| Physical base backup | Fast full-cluster restore, foundation for PITR | All-or-nothing, needs matching major version | Full cluster recovery, replica bootstrap |
| Continuous WAL archive | Enables recovery to any point in time | Useless without a base backup to anchor it | Undoing recent operator error precisely |
| Storage/volume snapshot | Very fast to take and restore | Crash-consistent only, not application-consistent | Fast recovery paired with WAL for correctness |
A cluster running pgvector 0.8+ or PostGIS 3.5+ extensions adds another wrinkle, because a physical restore brings the extension binaries and data together automatically, while a logical restore requires the target instance to already have matching extension versions installed before the dump will load cleanly.
Backup retention is itself an architectural decision, because keeping only the minimum required by policy leaves no margin for slow-discovered corruption, while keeping everything indefinitely turns storage cost into an unbounded liability.
Encryption and access control belong to the backup design from the start, not as an afterthought, because a backup is functionally a complete copy of production data sitting in a location that is often less scrutinized than the primary database itself.
The single most consequential decision in this whole space is treating backup and restore as one workflow rather than two, because an untested restore path is not a smaller risk than no backup at all, it is the same risk wearing a disguise.
Common Misconceptions
- "A replica is a backup." A streaming replica protects against hardware and node failure, but it faithfully replicates deletes, corruption, and bad migrations, so it cannot substitute for an independently retained backup.
- "If the backup job succeeded, the backup works." A backup job exiting with status zero only proves the copy completed, not that the data inside it is complete, uncorrupted, or restorable under time pressure.
- "Logical and physical backups are interchangeable." They protect against different failure modes and support different recovery operations, so most production systems need both rather than picking one.
- "More frequent backups always mean better protection." Backup frequency only bounds your recovery point for that backup type, and without WAL archiving in between, frequency alone cannot close small recovery gaps.
- "Restore speed doesn't matter until an incident happens." Restore speed is a function of data volume, hardware, and tooling that should be measured ahead of time, because discovering it during an outage is the worst possible moment to learn it.
FAQs
What's the real difference between a logical and a physical backup?
A logical backup describes database objects and data as SQL-level operations that a target instance replays, while a physical backup copies the actual on-disk files that PostgreSQL reads directly.
Why can't I just rely on my streaming replica instead of backups?
- A replica applies every change the primary makes, including mistakes
- It offers no protection against a dropped table, bad migration, or logical corruption
- It shares infrastructure risk with the primary far more often than an independently stored backup
What actually makes a physical backup "consistent"?
Replaying the WAL segments generated between pg_backup_start and pg_backup_stop turns the raw file copy, taken at slightly different instants across files, into a single coherent snapshot.
Does pg_dump lock the database while it runs?
No, pg_dump takes a repeatable-read snapshot and reads through that frozen view, so writers and other readers continue uninterrupted for the duration of the dump.
Can I restore a logical backup to an older PostgreSQL version?
Generally yes for reasonably close versions, which is one of logical backup's main strengths, but always test the restore against the actual target version rather than assuming compatibility.
Why do backups need their own retention policy separate from WAL?
WAL retention determines how far back PITR can reach, while backup retention determines how many independent full recovery points exist, and conflating the two leaves gaps when either one is trimmed.
Is a filesystem or volume snapshot a valid backup?
Only if it is paired with WAL replay to reach application consistency, because a snapshot alone is crash-consistent, meaning it looks like the instance was powered off rather than cleanly stopped.
What is a "backup catalog" and do I need one?
Yes, it is the record of what backups exist, where they live, and how to retrieve them, and tools like pgBackRest maintain one automatically so operators are never guessing during an incident.
How does the extension ecosystem (pgvector, PostGIS) affect backup choice?
Physical backups carry extension data and binaries together automatically, while logical restores require the target instance to already have matching extension versions installed before the dump will load.
Why is an untested backup considered risky rather than just "unproven"?
The failure modes that break a restore, such as a missing WAL segment or a corrupted archive, are silent until the moment you actually need the backup, at which point there is no time left to discover them.
Does encrypting backups change how restore works?
It adds a decryption step before the copy or dump can be read, so restore tooling and key access must be planned and drilled just as carefully as the backup process itself.
Where do point-in-time recovery and disaster recovery fit relative to this page?
Point-in-time recovery is built on top of a physical base backup plus continuous WAL archiving, and disaster recovery tiers describe how backup and replication choices combine to meet a business-defined RTO and RPO.
Related
- Backup Basics - the concrete logical-vs-physical recipe this page's mental model supports
- pg_dump & pg_restore - format and parallelism detail for logical backups
- Backup Verification - proving the restore path actually works
- PITR Basics - how a physical backup plus WAL becomes a rewindable timeline
- DR Basics - how backup strategy feeds RPO and RTO targets
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, and PostGIS 3.5+.