What is recommended way to do a PostgreSQL database backup: pg_dump or pg_basebackup?
Jun 30
There are two different tools in PostgreSQL server:
pg_dumppg_basebackup
What is the difference between these tools?
Which one to use to create database backup?
1 answer
Accepted answer · original discussion
Jun 30
pg_dump creates a logical backup, that is a series of SQL statements that, when executed, create a new database that is logically like the original one.
pg_basebackup creates a physical backup, that is a copy of the files that constitute the database cluster. You have to use recovery to make such a backup consistent.
The main differences are:
pg_dumptypically takes longer and creates a smaller backup.With
pg_dumpyou can back up one database or parts of a database, whilepg_basebackupalways backs up the whole cluster.A backup created by
pg_dumpis complete, while you need WAL archives to restore a backup created withpg_basebackup(unless you used the default option-X stream, in which case the backup contains the WAL segments required to make the backup consistent).With a logical backup you can only restore the state of the database at backup time, while with a physical backup you can restore any point in time after the end of the backup, provided you archived the required WAL segments.
You need
pg_basebackupto create a standby server,pg_dumpwon't do.A dump taken with
pg_dumpcan be restored on a database running on an arbitrary operating system, as long as the PostgreSQL version is equal or higher than the version ofpg_dump. In contrast, apg_basebackupcan only be restored with the same database version and on the same platform as the original.
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.