PostgreSQL backups: pg_dump vs pg_basebackup and point-in-time recovery

pg_dump makes a logical backup of one database: SQL definitions and data that you can restore selectively and load into newer PostgreSQL versions. pg_basebackup makes a physical copy of an entire running cluster's files. Only a physical base backup combined with continuously archived write-ahead log (WAL) supports point-in-time recovery (PITR), which can restore a cluster to any moment after the base backup ended. Many production setups use both: physical backups with WAL for recovery, and periodic dumps for portability and selective restores.

This guide compares the two tools against the official PostgreSQL documentation, which describes three approaches: SQL dumps, file-system-level backups and continuous archiving. Commands are examples for a server you administer; adapt paths, users and hosts to your environment.

What is the difference between pg_dump and pg_basebackup?

pg_dump connects as a client and exports one database as SQL or as an archive for pg_restore. It can restore individual tables or schemas, its output generally loads into newer PostgreSQL versions, and the documentation names it as the only method that works across machine architectures. pg_basebackup copies the data files of the whole cluster over a replication connection. It cannot back up individual databases or objects, its output is tied to the same PostgreSQL major version, and together with archived WAL it is the foundation for point-in-time recovery and standby servers.

Can pg_dump be used for point-in-time recovery?

No. A dump represents the database as it was when pg_dump began, so it can only return you to that moment. The PostgreSQL documentation states that pg_dump and pg_dumpall do not produce file-system-level backups and cannot be used as part of a continuous-archiving solution. To recover to a time between backups, you need a physical base backup plus a continuous sequence of archived WAL files from the start of that backup to your target time.

Is pg_dump safe to run on a live database?

Yes. pg_dump makes consistent exports while the database is in use and does not block other readers or writers. The documented exceptions are operations that need an exclusive lock, such as most forms of ALTER TABLE, which wait until the dump finishes. A dump still adds read load and holds a long-running transaction, so schedule large dumps for quieter periods and watch their effect on the server.

Which PostgreSQL backup method should I use?

Start from how much data you can afford to lose and how quickly you must recover. If losing everything since the last nightly backup is acceptable and the database is small enough to restore in your time limit, scheduled pg_dump archives with tested restores may be enough. If you need to recover to just before a bad deployment or accidental deletion, set up WAL archiving with regular base backups. Keep logical dumps as well when you need table-level restores or major-version migrations.

Logical vs physical backups at a glance

pg_dump (logical)pg_basebackup + WAL archive (physical)
ScopeOne database per run; roles and tablespaces need pg_dumpall --globals-onlyThe entire cluster, including every database
Restore granularityWhole database, or selected tables and schemas with pg_restoreWhole cluster only
Version portabilityLoads into newer PostgreSQL versions and other architecturesSame major version only
Point-in-time recoveryNoYes, to any time after the base backup ended
Server requirementsA normal client connection with read accessA replication connection, REPLICATION privilege, max_wal_senders and, for PITR, WAL archiving
Restore workRe-executes SQL, reloads data and rebuilds indexesCopies files, then replays WAL up to the target

Logical backups with pg_dump

Prefer the custom (-Fc) or directory (-Fd) format over plain SQL for backups. According to the pg_dump reference, both are compressed by default, allow selecting and reordering items during restore, and support parallel restoration. The directory format is the only one that supports parallel dumps with -j.

# Database contents in custom format
pg_dump -Fc -d app -f app-2026-11-14.dump

# Cluster-wide roles and tablespaces, which pg_dump does not include
pg_dumpall --globals-only -f globals-2026-11-14.sql

# Large database: directory format with four parallel jobs
pg_dump -Fd -j 4 -d app -f app-2026-11-14.dir

To restore, recreate the roles first, create an empty database from template0, then restore into it:

psql -f globals-2026-11-14.sql postgres
createdb -T template0 app_restore
pg_restore -d app_restore -j 4 app-2026-11-14.dump

# Restore only one table from the same archive
pg_restore -d app_restore -t orders app-2026-11-14.dump

The SQL dump chapter adds three points worth building into your runbook. Objects keep their original ownership only if those roles already exist. For plain SQL dumps restored with psql, set ON_ERROR_STOP or use --single-transaction so an error does not leave a half-restored database. After any restore, run ANALYZE so the query planner has statistics.

Dumps load into newer PostgreSQL versions, but not reliably into older major versions, even when the dump came from that older version. Use the pg_dump from the newer release when you migrate.

Physical backups and point-in-time recovery

Continuous archiving combines a file-system-level base backup with a copy of every WAL segment written afterwards. Replaying that WAL on top of the base backup can bring the cluster to any point after the backup ended.

1. Turn on WAL archiving

Set these in postgresql.conf. Changing archive_mode requires a server restart.

wal_level = replica
archive_mode = on
archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
archive_timeout = 60

The archive command must return a zero exit status only when the file is safely stored; PostgreSQL then recycles the segment. A local directory, as in the documentation's example, protects against little. In production, archive to separate storage and test the command before you take your first base backup.

WAL is archived only when a segment is complete, so on a quiet server recent transactions can wait a long time before reaching the archive. archive_timeout forces a segment switch after the given number of seconds when there has been activity; the documentation describes settings of about a minute as usually reasonable and recommends streaming replication when you need data copied off the primary faster than that.

2. Take base backups

Create a role with the REPLICATION attribute, allow it in pg_hba.conf and make sure max_wal_senders leaves room for the backup. Then run:

pg_basebackup -h db.internal -U replicator \
  -D /backups/base/2026-11-14 -Ft -z -X stream -P

-X stream is the default and includes the WAL needed to make this backup consistent on its own. For PITR you still need the continuous archive afterwards. Since PostgreSQL 17, pg_basebackup --incremental can copy only changed blocks relative to an earlier backup's manifest; an incremental backup must be combined with its predecessors using pg_combinebackup before it can be restored. See the pg_basebackup reference for every option.

3. Recover to a point in time

  1. Stop the server and move the damaged data directory aside instead of deleting it.
  2. Restore the base backup into an empty data directory owned by the PostgreSQL user.
  3. In postgresql.conf, set restore_command to fetch archived WAL, for example restore_command = 'cp /mnt/server/archivedir/%f %p', and set recovery_target_time, for example '2026-11-14 09:41:00+00'.
  4. Create an empty recovery.signal file in the data directory and start the server.
  5. Recovery replays WAL and, by default, pauses at the target (recovery_target_action = pause). Inspect the data. If it is right, run SELECT pg_wal_replay_resume(); to end recovery; if not, start again from step 1 with a different target.

The target must be later than the end of the base backup. The restore_command must return a nonzero exit status for files missing from the archive, because PostgreSQL will ask for segments that do not exist. Target settings and their exact formats are documented under recovery target settings.

Dedicated tools such as pgBackRest, Barman and WAL-G manage base backups, WAL archiving and retention for you. Use their own documentation; the PostgreSQL mechanics above are what they automate.

RPO and RTO: what each method gives you

The recovery point objective (RPO) is how much recent data you can afford to lose. The recovery time objective (RTO) is how long recovery may take. Write both down before choosing tools, because they decide the design.

Measure your actual restore time on production-sized data; estimates from database size alone are unreliable.

Retention: keep what a restore needs

A base backup is useless for PITR without every WAL segment from its start onwards, and WAL is useless without a base backup to replay it onto. Expire WAL only when no retained base backup depends on it. For dumps, keep a pattern that matches how late you might notice a problem, for example several daily copies plus weekly and monthly ones.

Store at least one copy outside the database host and account, restrict who can delete it, and encrypt backups that contain personal data. Estimate the space for a retention scheme with the backup retention storage calculator; it adds independent file sizes and does not predict deduplicated or compressed storage.

Test restores before you need them

A completed backup job proves that a file was written, not that you can recover from it. On a schedule, and after any backup configuration change:

  1. Restore the latest backup into an isolated instance that cannot reach production.
  2. Check that the restore completed without errors, roles and permissions are correct, and row counts or key queries match expectations.
  3. Run a basic application smoke test against the restored data.
  4. Record how long the restore took and compare it with your RTO.
  5. For PITR, also restore to a chosen timestamp and confirm the data stops where you expected.

If you schedule dumps with cron, check the timing in the cron expression guide and alert on missing successful runs, not only on failures. When a recovery decision involves a deployment, the rollback decision and evidence worksheet helps keep data recovery separate from an application rollback.

What DeployifyNow database backups do

DeployifyNow managed databases include scheduled and on-demand backups on paid plans; managed databases are outside the current free browser pilot. See pricing for current plan details. For a managed PostgreSQL, MySQL or MariaDB database, the product:

These are logical dumps. DeployifyNow does not offer WAL archiving or point-in-time recovery today, so your recovery point is the most recent completed backup and your worst-case data loss is about one schedule interval. If you need PITR, run PostgreSQL with continuous archiving yourself as described above. The backup and restore steps in the product documentation describe the current workflow, and the guide to deploying a Docker Compose app to a VPS with HTTPS covers backing up a database you host yourself.

Sources

All PostgreSQL references point to the current documentation, which covered PostgreSQL 18 when this guide was checked.