PostgreSQL backup and restore: choose a method and verify recovery
Choose a PostgreSQL backup method based on what you need to recover. For moving one database to another server or a newer version, or restoring selected objects, `pg_dump` is flexible. For quickly copying an entire database cluster, a physical backup such as `pg_basebackup` is a better fit. A backup file’s existence does not prove that it can be restored; perform a test restore and check that required data and permissions are present.
This guide follows the PostgreSQL 19 documentation, released on November 19, 2026, and focuses on a logical backup and restore of one database. The core ideas are similar in other major versions, but check the documentation for the tools you actually run. Continuous WAL archiving and point-in-time recovery (PITR) are separate topics; this guide covers them only as a selection criterion.
Decide what you need to recover
Choose the method after deciding how much you must restore: one database, individual objects, or the whole cluster including roles and tablespaces. The acceptable amount of data loss and the time available for recovery also matter. For example, if you keep only one daily dump, changes since that dump are not recoverable from that dump alone. Continuous WAL archiving can support recovery to a chosen point, but it adds operational and storage complexity.
| Method | Scope and strength | Limit to consider |
|---|---|---|
pg_dump / pg_restore | A logical dump of one database; flexible for selective restore or moving data to another major version. | Does not include cluster-wide roles or tablespaces. PostgreSQL docs say it is generally not the right choice for regular production backups except in simple cases. |
pg_dumpall | Writes the cluster’s databases and global objects such as roles and tablespaces to SQL scripts. | Each database dump is internally consistent, but the snapshots across databases are not synchronized. Restore may require elevated privileges. |
pg_basebackup | Makes a physical copy of the entire cluster from a running server; useful for a whole-cluster recovery or as a standby’s starting point. | Cannot select individual databases or tables and is tied to server versions and storage layout. Point-in-time recovery also needs the required WAL archive. |
| File-system copy | Can copy the entire data directory after stopping the server, or use a valid, synchronized storage snapshot. | A normal file copy of a live data directory is not guaranteed consistent. Multiple disks and tablespaces may require simultaneous snapshots. |
PostgreSQL groups these approaches as SQL dump, file-system-level backup, and continuous archiving. PostgreSQL 19: Backup and Restore overview
What does pg_dump include?
pg_dump exports the schema and data of one database into a logically consistent dump. The dump represents a snapshot from when the command starts; the database can generally continue serving other reads and writes while it runs. In addition to plain SQL, it offers custom (-Fc) and directory (-Fd) archive formats. Custom format is compressed and can be inspected with pg_restore, which can select or reorder objects during restore. PostgreSQL 19: pg_dump
For example, create a restore-ready dump of one orders database:
pg_dump -Fc -f orders.dump orderspg_dump does not export all databases at once, nor does it save cluster-wide objects such as roles and tablespaces. If those objects are needed for cluster recovery, consider saving them separately with pg_dumpall --globals-only. Restoring global objects may require elevated privileges, so first inspect the effect in an isolated recovery environment instead of applying them casually to an existing cluster. A full pg_dumpall script contains per-database dumps that are each consistent, but they are not snapshots from the same synchronized instant. PostgreSQL 19: pg_dumpall
How do you restore a dump into a new database?
Test the restore in a separate database or isolated server so that the source is not overwritten. This example restores a custom-format archive into a new database. In a real environment, you may also need to specify the host, port, connection role, and privileges.
# Check that the archive table of contents can be read.
pg_restore --list orders.dump
# If you need original object ownership and grants, create the required roles first.
# Create a test database from the clean default template.
createdb -T template0 orders_restore
# Stop on a restore error so that failure is visible.
pg_restore --exit-on-error --verbose -d orders_restore orders.dumppg_restore --list checks that the archive table of contents is readable; it does not test a database restore. Use pg_restore for non-plain archive formats. For a plain SQL dump, use psql -X and create the destination database first. Restoring original object owners or grants can fail if those roles do not exist on the destination. If the intended result is for a new role to own the restored objects, consider an option such as --no-owner, then verify access controls and application behavior separately. PostgreSQL 19: pg_restore
When do you need a whole-cluster backup?
pg_basebackup makes a physical copy of the entire database cluster from a running PostgreSQL server. Consider it for fast whole-cluster recovery or as the starting point for a standby. It cannot select an individual database or table. The connection must use a role with REPLICATION privilege or a superuser, and pg_hba.conf must allow replication connections. PostgreSQL 19: pg_basebackup
An example command is:
pg_basebackup -h db.example.net -U backup_role -D /backups/cluster-copy
pg_verifybackup /backups/cluster-copyThe target directory must be empty, and you should consider the load and network use on a production server. pg_verifybackup can check the backup manifest, file list and checksums, and whether some WAL needed for recovery is present and readable. It cannot perform every check a running server makes during recovery, so PostgreSQL still recommends a test restore in a separate environment. WAL parsing also requires tools from the matching major version. A file-system-level backup requires the server to be fully stopped or a consistent, simultaneous snapshot that covers data, WAL, and tablespaces. Simply copying a live data directory is not a safe backup. PostgreSQL 19: pg_verifybackup · PostgreSQL 19: File System Level Backup
Combining a base backup with continuous WAL archiving can recover the cluster to a later or chosen point. This requires an unbroken set of required WAL files and correct archive and restore configuration. The details are a separate procedure; treat point-in-time recovery as a distinct design. PostgreSQL 19: Continuous Archiving and PITR
How can you tell whether recovery worked?
A successful backup message or a large file is not enough evidence. Regularly restore into an isolated environment and check the result:
Confirm the command exited without errors and review server logs and warnings from PostgreSQL tools.
Check that critical tables and indexes exist, and validate important business invariants. Compare known row counts or totals where appropriate, but a simple count of every table does not prove correctness.
Connect using the application role and check permissions, sequences, extensions, and required queries. Object ownership or extension setup may not be ready automatically in a new environment.
Check whether `ANALYZE` is needed after restore. If optimizer statistics are missing or inadequate, the data may exist while query plans and performance differ from expectations.
Record the actual recovery time and steps. `pg_verifybackup` can help check physical backup integrity, but it does not replace a restore exercise.
Restore commands execute against the destination. In particular, --clean can drop objects before restoring them, and restoring a dump from an untrusted source can run arbitrary code chosen by the source superusers. Confirm the target server before running a restore, and inspect untrusted dumps in an isolated environment. PostgreSQL 19: pg_restore security and options
A checklist for choosing and operating a backup
Use your recovery needs to make the choice:
**Need to move or selectively restore one database:** start with `pg_dump -Fc` and `pg_restore`.
**Need roles or tablespaces too:** dump global objects separately, then check required privileges and paths before restoring them.
**Need a physical copy of the whole cluster or faster whole-cluster recovery:** consider `pg_basebackup`, verify its manifest, and restore it on a separate server.
**Need to recover to a particular point in time:** a base backup alone is not enough; configure continuous WAL archiving and verify a separate PITR procedure.
**Considering a raw file copy:** do not copy the data directory as-is unless the server is stopped or a consistent simultaneous storage snapshot is available.
Backup intervals determine how much recent data may be lost; restore speed determines how much downtime the service may face. Set those limits first, then validate the method with a restore drill that includes real data and permissions.
Scope and sources
The commands and behavior here follow the PostgreSQL 19 documentation checked on November 23, 2026. Shell examples use POSIX syntax; connection credentials, TLS, and password-file setup are omitted because they depend on the environment. No database, backup, or restore was executed for this article. PITR configuration and commands are out of scope. Other PostgreSQL major versions and managed services may differ; check the documentation for your deployment.
[PostgreSQL 19: Backup and Restore overview](https://www.postgresql.org/docs/19/backup.html)
[PostgreSQL 19: SQL Dump and Restore](https://www.postgresql.org/docs/19/backup-dump.html)
[PostgreSQL 19: `pg_dump`](https://www.postgresql.org/docs/19/app-pgdump.html)
[PostgreSQL 19: `pg_dumpall`](https://www.postgresql.org/docs/19/app-pg-dumpall.html)
[PostgreSQL 19: `pg_restore`](https://www.postgresql.org/docs/19/app-pgrestore.html)
[PostgreSQL 19: `pg_basebackup`](https://www.postgresql.org/docs/19/app-pgbasebackup.html)
[PostgreSQL 19: `pg_verifybackup`](https://www.postgresql.org/docs/19/app-pgverifybackup.html)
[PostgreSQL 19: File-System-Level Backup](https://www.postgresql.org/docs/19/backup-file.html)
[PostgreSQL 19: Continuous Archiving and PITR](https://www.postgresql.org/docs/19/continuous-archiving.html)