Logical backups with pg_dump and pg_dumpall

pg_dump gives a consistent snapshot of one database and pg_dumpall adds roles and tablespaces, but dumps are slow to restore at scale and do not replace point-in-time recovery. This page explains where each fits.

On this page

When is a pg_dump backup enough for PostgreSQL?

If your recovery point objective is measured in hours and your recovery time objective allows a long restore, a logical pg_dump backup may meet the target. Start by writing down both numbers, then check whether a dump taken at the interval you need can be restored inside the window you have. A dump is only useful against those targets, so the decision is about the numbers, not the tool.

pg_dump captures one database as a consistent snapshot as of the moment the dump starts, using a single transaction snapshot. It does not capture the data files themselves. It writes SQL or a custom archive that replays schema and data through CREATE and COPY statements at restore time. pg_dumpall adds what pg_dump skips: cluster-wide objects such as roles and tablespace definitions, plus every database in the cluster, which you need when a rebuild must recreate users and permissions. Plan to run both: a pg_dump per database for the data, and a pg_dumpall --globals-only run for roles and tablespaces, which you should confirm against the PostgreSQL backup documentation for your server version.

A dump is a logical copy, so it cannot give you a point in time between dumps. Anything written after the snapshot is lost unless you have a separate mechanism such as archived WAL. Teams usually need dumps for small or medium databases, for moving data between major versions or hosts, for keeping a schema-only copy for review, or as a second, independent copy alongside physical backups. This page covers logical dumps only. Physical base backups and WAL archiving are covered in the sibling topics on backup tools and disaster recovery planning.

Which pg_dump format and scope fits each recovery need

This table compares the pg_dump output formats and the single-database versus whole-cluster scope, showing what each captures, how it restores and whether it runs in parallel. Read each row against your recovery need, then confirm the details against the pg_dump documentation for your PostgreSQL version.

OptionWhat it capturesRestore and parallel jobsRecovery needs it fits
Plain SQL (pg_dump default)One database as SQL statements, schema and dataReplayed with psql. No parallel restore from the file itselfSmall databases, readable diffs, moving a schema into a new environment
Custom format (-Fc)One database in PostgreSQL's compressed archive format, selectable by objectRestored with pg_restore, which can pick objects and run parallel jobsRoutine logical backups of one database where selective restore matters
Directory format (-Fd)One database as a directory with one file per table, compressed by defaultpg_restore reads it with parallel jobs. pg_dump can also dump in parallelLarge single databases where dump and restore time must shrink with more cores
Tar format (-Ft)One database as a tar archive, no compression by defaultRestored with pg_restore. Parallel restore is not available from tarCompatibility with tools that expect tar. Confirm the parallel limits for your version
pg_dump for one databaseOne database, its objects and data, consistent as of the snapshot taken at startRestores into one database. Roles and tablespaces are not includedRecovering or moving a single application database
pg_dumpall for the whole clusterRoles, tablespaces and every database in plain SQLRestored with psql. Cannot run in parallel and must be replayed as one scriptRebuilding cluster-wide roles and tablespaces alongside database dumps
Dumps plus physical backupsLogical dumps capture objects. Physical backups capture the whole data directoryLogical restores are slower for large data. Physical restores need matching server versionsObject-level recovery from dumps and full-cluster or point-in-time recovery from physical backups

Where a logical dump stops being enough

A logical dump is a point-in-time copy of logical objects, so its protection is limited by how often it runs, how long it takes to restore and what it cannot see across a whole cluster. The four limits below are the usual reasons teams pair pg_dump with physical backups and WAL archiving.

No recovery between dumps

A dump restores the database as it was when the dump started. Every transaction committed after that point is lost unless it can be replayed from somewhere else. If the business accepts losing up to a day of writes, a nightly dump may fit. If a single hour of lost orders or payments is unacceptable, you need continuous WAL archiving so a base backup can be rolled forward to a chosen moment. Check the recovery point target against your dump schedule before relying on dumps alone.

Continuous archiving docs

Restore time grows with data

A logical restore replays every INSERT or COPY and then rebuilds indexes and constraints, so restore duration rises with data volume and index count. Restore a copy of your largest database on comparable hardware and time it, including ANALYZE afterward. If that time is longer than your recovery time target, the dump is a poor primary restore path for that database. A physical base backup restored with its WAL usually avoids the rebuild step.

The gap since the last dump

The window between the last successful dump and a failure is where data is most exposed, and it is easy to miss when dumps run from cron without monitoring. A failed dump that logs an error but exits quietly can leave the newest backup days old. Track the timestamp and size of each dump, alert on missing or undersized files, and confirm that the schedule still covers the window your recovery point target allows.

No cluster-wide snapshot

pg_dump captures one database in a single consistent snapshot, but separate databases are dumped at different moments. pg_dumpall covers roles and tablespaces, yet it still runs one database after another, so cross-database references can drift between dumps. When applications depend on several databases changing together, a physical base backup of the whole cluster, combined with WAL, gives one consistent recovery point. Confirm which databases must be consistent with each other before choosing the method.

High availability docs

Setting up a consistent pg_dump backup that restores

This sequence produces a single-database dump taken from one consistent snapshot, with a recorded checksum, an off-site copy and proof from a test restore that the dump can be rebuilt on a separate instance.

  1. Confirm version and databases in scope

    The DBA or platform engineer records the PostgreSQL server version, the output of the pg_dump client version, and the list of databases to protect. Run psql -l to list databases and SELECT version(); to confirm the server version. Match the pg_dump binary to the server major version, because pg_dump is designed to work with the server it connects to and newer client versions handle older servers best. Record the list in the backup runbook. The step is done when the list of databases, the server version and the client version are written down and agreed with the data owner.

  2. Create a dedicated least-privilege backup role

    The DBA creates a separate login role for the backup job, not a superuser or the application account. Grant CONNECT on each target database and USAGE on the schemas to be dumped, and use default privileges only where needed. Authenticate the role with SCRAM-SCRAM-SHA-256 password or certificate, and add a matching rule to pg_hba.conf that allows the backup host only. Confirm the role can dump, but cannot write, by running a dump as that role and attempting an INSERT that should fail. The step is done when the role's privileges are documented and the test write is denied.

  3. Choose the output format and parallelism

    The engineer selects the format for the dump. The directory format (-Fd) is the option that supports parallel jobs with -j, and it writes one file per table plus a table of contents. The custom format (-Fc) is a single compressed file that can be restored with pg_restore, but it does not support parallel dump. Plain SQL (-Fp) is readable but slow to restore for large databases. Set the job count to suit the host and the database size, and confirm that the chosen format and job count are written into the job definition. The step is done when the command is saved and reviewed with the chosen format named explicitly.

  4. Run the dump from a consistent snapshot

    The backup job runs pg_dump against one database with the chosen format, for example pg_dump -Fd -j 4 -f /backups/appdb.dir appdb. pg_dump takes its own snapshot at the start of the run, so all tables reflect the same point in time without locking the whole server. Schedule the job outside peak write periods where possible, and capture the start time, end time and exit status in the job log. Check that the exit code is zero and that the output directory contains a toc.dat file. The step is done when the job reports success and the log holds the start time, end time and exit status.

  5. Record checksums and dump metadata

    The engineer generates a checksum for every file in the dump, then writes a manifest with the database name, server version, pg_dump version, format, start and end time, and the list of schemas and roles included. Run pg_restore --list against the dump to save the table of contents alongside the manifest. Store the manifest next to the dump, not in the same folder as the application data. Verify the checksums by recomputing them and comparing results. The step is done when the checksum file and the manifest both pass a second recomputation.

  6. Copy the dump to a separate location

    The operator copies the dump directory and its manifest to a storage location that is separate from the database host, such as a backup server or an object storage bucket in another account or site. Choose credentials for the copy job that differ from the database backup role, and confirm the destination enforces its own retention and access controls. Recompute the checksums on the destination copy and compare them to the originals. The step is done when the destination copy matches the source checksums and the transfer log shows no errors.

  7. Run a test restore into a non-production instance

    The DBA restores the dump with pg_restore -j 4 -d restore_test /backups/appdb.dir into a separate instance that matches the source major version. Confirm that the restore exits without errors, then compare row counts for the largest tables, and compare object counts for tables, indexes, sequences, views and functions between the source and the restored database. Record the restore duration, since it determines how long a recovery takes. The step is done when row counts and object counts match the source and the restore time is recorded in the runbook.

How dumps, archives and restore tests fit together

The diagram starts at the production cluster, where pg_dump writes per-database dump files and pg_dumpall adds cluster-wide roles and tablespace definitions. Dumps cross a trust boundary into separate backup storage, and a scheduled restore test loads them into a clean instance. The parallel physical path, a base backup plus archived WAL, supports point-in-time recovery. Check that the restore test succeeds, since an unrestored dump is only an unproven file.

Dumps, physical backups and the restore test that proves them.

Using dumps alongside physical backups and point-in-time recovery

A logical dump cannot take you to an arbitrary moment on its own. Point-in-time recovery combines a base backup with archived WAL files, and the WAL archive is what lets you replay changes up to the second before a failure. A pg_dump file is a snapshot of one moment, so it can restore the database to the time the dump ran and nothing finer. Teams with a recovery point objective tighter than their dump interval need physical backups with continuous WAL archiving, and the dump becomes a supplement rather than the primary recovery path.

The common pattern keeps physical backups for fast whole-cluster recovery and point-in-time needs, and uses dumps for the jobs physical copies do poorly. A dump restores one database without restoring the whole cluster, it gives you a logical copy that does not depend on the binary storage format, and it is the usual route for a migration between major versions. Confirm with your own restore tests how long each path takes at your data volume, since the answer depends on your hardware and schema. Keep the dump schedule and the physical schedule documented together so that nobody restores from the wrong one during an incident.

pg_dumpall covers things a single-database dump misses, including roles and tablespace definitions, which sit at the cluster level. Physical copies of the cluster carry these objects too, but restoring a single database from a physical backup is not a simple operation, so the dump often remains the practical tool for that case. Plan the restore order explicitly: restore cluster globals first, then create tablespaces and roles, then restore each database, and confirm that sequence against the PostgreSQL continuous archiving docs and your own environment before you depend on it.

Protecting dump files, credentials and restore access

A logical dump is a complete, portable copy of your data, and it is often easier to copy off a server than a physical backup. The controls below treat every dump, role definition and restore session as sensitive material, and they connect to how you monitor, retain and audit the jobs that produce them.

Encrypt and restrict dump files

A custom or directory-format dump contains every row of the database it covers, including data your application may protect with column-level rules or application encryption. Write dumps to a location only the backup account and a small restore group can read, and encrypt them before they leave the database host. Check that encryption keys are stored apart from the dump files, and that copies on shared storage or laptops are covered by the same policy.

Handle role definitions in pg_dumpall output

The output of pg_dumpall includes role definitions, including password hashes for roles that have them. Treat that output as a credential store, not as ordinary data, and keep it under the same access controls as the rest of the dump. Confirm with your own environment whether role passwords are included in the file you produce, and whether restores into a new cluster need those roles recreated before database objects load.

Separate backup and application credentials

Use a dedicated role for dump jobs, with read access granted only to the schemas it must export and no ability to change data. Store its password or certificate in the backup system's secret store, not in application configuration or shell history. Rotate that credential on a schedule separate from application credentials, so that a leaked application secret cannot also read every dump.

Monitor dump failures and duration

A dump job can exit with an error, produce a truncated file, or run longer each month as the database grows, and none of these failures show up unless someone checks. Alert on non-zero exit codes, on missing output files, and on run times that drift past the window your schedule allows. Record file size and checksum for each run so that a suddenly smaller dump is noticed.

Set retention and deletion rules

Decide how long each dump is kept, how many generations are retained, and who approves early deletion, and write those rules into the backup policy. Dumps stored in object storage should use lifecycle rules that match the policy, and deletions should be logged. Keep in mind that dumps taken before a data-retention or erasure request may still hold data you are obliged to remove, so ask your legal or privacy team how those copies are handled.

Run restores under named accounts

Restores are high-impact actions, so each one should run under a named person's account, not a shared administrator login. Keep the command output, the restore target, the start and end times and the person who approved the restore in a log that is retained outside the database host. These logs show auditors that restores were tested and authorized, and they give your team a timing baseline for recovery targets.

How restore time changes the plan for large databases

Restore time from a logical dump is not a fixed property of pg_dump. It depends on the data volume, how long the indexes take to rebuild, how many constraints must be validated, how many database objects the restore has to create, and how much parallelism the restore job can use. Each of these varies between environments, so a restore that took a given time on another team's database says little about yours. Before you decide that a dump can meet your recovery time target, run a test restore of your own most recent dump onto hardware that resembles production, and time the whole process from starting the restore to the application passing its health checks, not just the end of the pg_restore command.

Compare that measured figure with your recovery time objective, and build in margin for the things a test restore often misses: a restore that runs during a real incident may compete for disk and network with other recovery work, and the dump file itself must first be copied to the restore host. If the measured time is too long, the usual levers are the directory format, which lets pg_dump and pg_restore run multiple jobs through the --jobs option, and the way you order and defer index and constraint creation. Confirm which of these options, and which flags for parallel dump and restore, are available for your PostgreSQL version in the pg_dump documentation and the pg_restore reference before you rely on them in a runbook.

Treat the result as a decision input rather than a permanent answer. If a logical restore cannot meet the target at your data size, that is the point to plan physical backups for the large databases and keep dumps for portability, selective restores and smaller databases. Record the measured restore duration, the dump size, the PostgreSQL version and the hardware used, and repeat the test after significant growth or a major upgrade, because all of these change the result. Ask your team to confirm the restore runbook includes the time to fetch the dump, the time to create roles and tablespaces, and the time to verify row counts and application behavior.

Limits to confirm in your environment

A logical dump is only as good as the assumptions behind it. The cards below list the facts to confirm in your own environment before a pg_dump schedule becomes your recovery plan, from the server version to whether the copy you restore actually meets your targets.

PostgreSQL version and support end

Confirm the exact major version of every source server and the date its support ends under the PostgreSQL versioning policy. A dump taken from an unsupported version may still restore, but the upgrade you will need later, and the security fixes you will not receive, add risk that a backup plan should account for. Record the version next to each database in your inventory, and schedule the upgrade before the end date rather than during an incident.

Supported major version listed
14
Versioning policy

Objects the dump actually covers

A pg_dump run captures one database, including its schema, data and objects inside it, but not everything on the server. Confirm which extensions, large objects, event triggers, publications, subscriptions and per-database settings your application depends on, and test that each one appears in the output. Cluster-wide items such as roles and tablespaces need pg_dumpall or a separate step. Anything missing from your list is missing from your recovery.

Primary or replica as the source

Decide whether the dump runs against the primary or a hot standby. A dump on the primary holds a consistent snapshot but adds read load and long-running transactions on the server that serves writes. A dump on a standby moves that load away, but depends on replication lag and on the standby having the same data you expect to recover. Measure the load of a full run on a representative copy, and confirm that the snapshot time is written down with the file.

Storage for dump files

Estimate the size of each dump file and the number of retained generations before you choose a destination. Parallel directory format writes many files at once, and compressed output can still fill a volume during a large run. Confirm free space for the peak of concurrent dumps plus retention, and check that the destination is separate from the database volume so a full disk does not stop the server. Ask who owns capacity alerts for that location.

Restore target version compatibility

Confirm the version of the server you will restore into, and test that a dump from your source version loads there. Dumps made with a newer pg_dump generally cannot be restored with an older pg_restore, so keep the client tools aligned with the source server. Major upgrades after the dump change the target, so re-run the restore test on each new major version before you retire the old one.

Upgrading docs

Fit to recovery point and time targets

Compare the dump schedule with your recovery point objective and recovery time objective. A nightly dump means up to a day of data loss between runs, and restore time for a large database can exceed the recovery time target on its own. Time a full restore into a clean server, record the result, and decide whether the dump is the primary recovery path or a complement to physical backups with WAL archiving.

Questions teams ask before running logical backups

What does a pg_dump backup cost in effort and infrastructure?

The software is free under the PostgreSQL License, so the cost is the staff time to script, schedule and monitor the dumps, plus storage for the dump files and the compute to run them. Costs rise with database size, dump frequency and retention, because each retained dump is a full copy of the data in the chosen format. Storage is usually the largest recurring line item, and it grows with every dump kept. Ask any partner quote to separate one-time build work (scripts, scheduling, alerting, restore runbook) from recurring work (monitoring, retention changes, version updates of the client tools).

How long do setup and a first restore test take, and what drives that time?

Setup time depends on how many databases the cluster holds, how many schedules and retention rules you need, and how well the existing backup host and storage are already defined. The first restore test often takes longer than the setup, because it exposes missing roles, extensions, tablespace paths and application-side assumptions. Restore duration scales with dump size and the number of parallel jobs your hardware allows, so a test on a small staging copy does not predict production timing. Ask for the restore test to run against a copy of production-sized data, and for the measured restore time to be recorded against your recovery time target.

What does the work need from our internal team?

Your team needs someone who owns the database schema and application, someone who can grant access to the database host and the backup storage, and someone who can approve the restore runbook. The team also needs to define which databases, roles and tablespaces must be recoverable, and who decides on retention and encryption. Plan for time from a DBA or platform engineer during build and at least one restore drill. Without a named owner for restore tests, dumps tend to run for months without anyone confirming they can be restored.

Can our team build and test dump backups without outside help?

Yes, if your team already runs PostgreSQL in production and has someone comfortable with shell scripting, cron or a scheduler, and object or file storage. The skills that are most often missing are restore testing under time pressure, handling roles and globals with pg_dumpall, and documenting a runbook that someone else can execute at night. An outside partner is most useful when the scope spans several clusters, when recovery targets are tight, or when evidence for an assessment must be produced. Decide which of these tasks your team will own after the build.

When should we add physical backups to our dump strategy?

Add physical backups when logical dumps can no longer meet your recovery point or recovery time target, which usually happens as databases grow, or when you need point-in-time recovery. PostgreSQL's continuous archiving documentation describes how a base backup combined with archived WAL files supports point-in-time recovery, which a dump alone cannot provide. Many teams keep dumps as a secondary, portable copy for selective restores and migrations while physical backups handle fast full recovery. Compare the restore time of each method against your targets before deciding which role each one plays.

How do dumps interact with major version upgrades?

A dump taken with pg_dump or pg_dumpall is one of the migration paths named in PostgreSQL's upgrade documentation, since a major upgrade can restore the dump into a new server. The dump's restore time then becomes part of your upgrade downtime, so measure it on production-sized data before scheduling. Dump format and the client version should match the target server, and the dump should be taken after the final application writes are stopped if you need a consistent result. Confirm the chosen upgrade method with your team before relying on dumps as the rollback path.

How DeployOpen scopes and delivers PostgreSQL backup work

DeployOpen plans, builds, tests and documents pg_dump and pg_dumpall backup jobs inside infrastructure you control, so the dumps match your recovery targets and sit alongside your physical backups. Every engagement starts from a written scope that names the databases, roles, storage locations and restore tests included.

How we scope

  • We inventory which databases, global roles and tablespaces need logical copies, and which are covered by physical backups.
  • We agree the dump schedule, formats, retention periods and off-site storage locations in writing before any build starts.
  • Engagements are fixed-scope, and the written scope names the restore test and handover deliverables, with ongoing support available as a retainer.

How we build

  • We script per-database dumps using the directory format with parallel jobs, sized to your hosts and storage capacity.
  • We schedule pg_dumpall for global objects such as roles and tablespaces, and store its output separately from database dumps.
  • We run timed test restores into a separate environment to measure how long a full restore takes for your largest database.

How we hand over

  • You receive the backup scripts, scheduler configuration, retention settings and credentials handling, stored in your own version control.
  • You receive a restore runbook that states the order of steps, the commands used and the checks that confirm a restored database is usable.
  • You receive the test restore results, including measured restore durations and any gaps you must confirm before relying on logical copies.

How we support

  • Ongoing support can cover monitoring of dump jobs, failed run alerts and periodic restore drills against your recovery time targets.
  • Re-testing is scheduled when PostgreSQL major versions change, since dump and restore behavior must match the server version in use.
  • Upgrades to backup tooling and changes to database size are reviewed so restore durations stay current with what your team expects.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.