Backup, Restore & Replication
The difference between having a backup and having a tested restore process is the difference that matters during an actual incident.
Advanced
# dump a single database to a compressed custom-format file
pg_dump -Fc -d mydb -f mydb.dump
# restore it into a fresh (already-created) database
pg_restore -d mydb_restored mydb.dump
# a plain SQL dump — human-readable, restorable with psql instead of pg_restore
pg_dump -d mydb -f mydb.sql
pg_dump produces a logical backup — effectively "the SQL statements needed to recreate this data," portable across PostgreSQL versions and even OS platforms. It's consistent (a snapshot as of one instant) without blocking concurrent writes, but restoring a large database this way is slow, since it's re-inserting and re-indexing everything from scratch.pg_basebackup, or a filesystem/volume snapshot). Much faster to restore for a large database, since it's not replaying SQL, but it's version- and platform-specific, and typically larger since it isn't just the logical data. Tools like pgBackRest and WAL-G manage physical backups plus continuous WAL archiving in production.DELETE"), not just to the moment of the last full backup. This is the real disaster-recovery answer to "someone dropped a table in production" — a nightly-only backup schedule with no WAL archiving means losing everything since the last backup.# on the replica's postgresql.conf / standby.signal (PG 12+)
primary_conninfo = 'host=primary-server port=5432 user=replicator password=...'
| Term | Meaning |
|---|---|
| Synchronous replication | primary waits for the replica to confirm before considering a commit durable — stronger guarantee, adds latency |
| Asynchronous replication | primary commits immediately, replica catches up shortly after — a small window of possible data loss on failover |
| Replication lag | how far behind the replica currently is — worth monitoring directly, since a badly lagging "real-time" replica can be a silent problem |