Logical Backups (pg_dump, mysqldump) vs Physical Backups
Choose logical dumps vs physical base backups for restore speed and flexibility.
In plain words
One kind of backup saves instructions to rebuild the data; the other saves an exact copy of the database files.
Think of it like…
A logical backup is a recipe book: you can cook any dish again anywhere, but cooking a feast takes hours. A physical backup is a photo-perfect frozen copy of the whole kitchen: restoring it is fast, but it only fits an identical kitchen.
Where you’ve seen it
A 2 TB production database is backed up nightly with pg_basebackup plus continuous WAL archiving, so it can be restored to any minute within 14 days. Separately, a weekly pg_dump of the small billing schema lets the team restore one table, or load it into a newer PostgreSQL version, without touching anything else.
Words you’ll hear
- Logical backup
- SQL or archive export of schema and data; portable and selective.
- Physical backup
- A copy of the data files; same major version and platform needed.
- RPO / RTO
- How much data you can lose / how long recovery may take.
- Restore test
- Regularly restoring a backup to prove it works.
Visual diagram
Theory & example queries
Logical backups
pg_dump takes a consistent snapshot of one database without blocking normal reads and writes, and writes it as plain SQL or in custom or directory format, which pg_restore can restore in parallel (-j) and selectively (one schema or table). mysqldump does the same for MySQL; use --single-transaction for a consistent InnoDB dump without locking.
Because a logical restore re-inserts data and rebuilds every index, it gets slow for large databases: hours for hundreds of gigabytes. Its strengths are portability (restore into a different major version or platform), selectivity, and readability, which make it ideal for small databases, migrations and extra protection for critical tables.
pg_dump -Fd -j 4 -f /backups/shop_2026-11-20 shop then pg_restore -j 4 -d shop_restore /backups/shop_2026-11-20
Physical backups and testing
pg_basebackup copies the cluster's data files while it runs; combined with continuous WAL archiving it enables point-in-time recovery to any moment after the base backup. Restores are roughly as fast as copying files, but only to the same PostgreSQL major version and platform, and they cover the whole cluster rather than one table. Tools like pgBackRest, Barman and Percona XtraBackup (for MySQL) add compression, incremental backups and retention management. Managed services (RDS, Cloud SQL) automate snapshots and PITR.
Whatever the method, schedule restore tests: restore into a scratch instance, run sanity checks, and time it against your RTO. Keep copies off the primary server and in another location (the 3-2-1 rule: three copies, two media, one off-site), and remember that a replica isn't a backup, because a DROP TABLE replicates within seconds.
pg_basebackup -D /backups/base_2026-11-20 -Ft -z -X stream with archive_mode = on and an archive_command (or pgBackRest) shipping WAL segments to storage.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Set RPO and RTO
Agree how much data loss and how much downtime are acceptable; these decide the method.
RPO 5 min · RTO 1 hour
When to use it & trade-offs
What it is
A logical backup (pg_dump, mysqldump) exports the database as SQL statements or a portable archive: schema plus data, rebuilt on restore. A physical backup (pg_basebackup, Percona XtraBackup, storage snapshots) copies the actual data files. Logical backups are flexible and portable; physical backups restore large databases much faster and, with archived WAL, allow point-in-time recovery.
Why it matters: Backups are only useful if you can restore from them within the time the business can tolerate. Choosing the type determines how long a restore takes, whether you can recover a single table, and whether you can roll back to five minutes before a mistake. It's a standard production-readiness and DBA interview topic.
When to reach for it
- Disaster recovery plans
- Restoring an accidentally deleted table
- Moving data between versions or providers
When to avoid or be careful
- Treating a read replica as a backup
- Keeping backups only on the database server
- Never testing a restore
Logical vs physical backups vs snapshots
Strengths: Portable across versions; selective; human-readable.
Watch out: Slow to restore large databases; no point-in-time recovery on its own.
Strengths: Fast restore; point-in-time recovery.
Watch out: Same major version and platform; whole cluster only.
Strengths: Fast, automated, often with PITR.
Watch out: Provider-specific; still need restore testing.
Interview signals & numbers to know
When this topic comes up
- “How would you back up this database?”
- “Someone dropped a table, how do we recover?”
- RPO / RTO
- pg_dump vs pg_basebackup
- Disaster recovery
Benchmarks & rules of thumb
- 3-2-1
- backup copies, media, off-site
- -j
- parallel jobs for pg_dump / pg_restore
- Same major version
- required for physical restores
Common mistakes & follow-ups
Common interview mistakes
- Relying on nightly pg_dump for a 3 TB database and discovering a restore takes a day.
- Keeping backups on the same disk as the database.
- Assuming backups work because the backup job reports success, without ever restoring one.
Likely interviewer follow-ups
- When would you choose pg_dump over pg_basebackup?
- What's the difference between RPO and RTO?
- Why isn't a replica a backup?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Logical Backups (pg_dump, mysqldump) vs Physical Backups with hands-on SQL practice and interview Q&A.