$linuxjunkies
>

pg_basebackup(1)

Take a base backup of a PostgreSQL cluster without connecting to the database server.

UbuntuDebianFedoraArch

Synopsis

pg_basebackup [OPTION]... [DIRECTORY]

Description

pg_basebackup is used to take base backups of a running PostgreSQL database cluster. The backup is performed without blocking other clients from accessing the database, and automatically incorporates all changes to the database cluster made during the backup.

The backup must be taken from a superuser or a role with the appropriate replication privileges. A connection to the server in recovery mode is not supported.

The resulting backup can be used to set up a new standby server or restore a database cluster to a previous state.

Common options

FlagWhat it does
-D, --pgdata=DIRECTORYWrite the output to the specified directory; required unless -F tar is used
-F, --format=plain|tarOutput format: plain (default, directory structure) or tar (tar archives)
-h, --host=HOSTNAMEServer host or socket directory; defaults to local socket
-U, --username=USERNAMEPostgreSQL user for connection; defaults to current OS user
-P, --progressDisplay progress information during backup
-v, --verboseEnable verbose output
-R, --write-recovery-confWrite recovery.conf file for use as a standby server
-X, --wal-method=fetch|streamInclude WAL: fetch (copy after backup) or stream (stream during backup)
-z, --gzipCompress tar output with gzip; implies -F tar
-Z, --compress=0-9Compress tar output with specified level (0-9); implies -F tar
-c, --checkpoint=fast|spreadSet checkpoint mode: fast (immediate) or spread (default, over time)
--max-rate=RATELimit transfer rate to RATE KB/s

Examples

Take a plain backup to /var/lib/postgresql/backup using the replication user

pg_basebackup -D /var/lib/postgresql/backup -U replication -h localhost

Create a tar backup and pipe through gzip to compress, connecting to remote host

pg_basebackup -D /backup -F tar -h db.example.com -U postgres | gzip > backup.tar.gz

Take backup with recovery.conf for standby setup and stream WAL during backup

pg_basebackup -D /var/lib/postgresql/backup -U replication -R -X stream

Backup with progress display, verbose output, and rate-limited to 10 MB/s

pg_basebackup -D /backup -U replication -P -v --max-rate=10000

Create a compressed tar archive backup from a remote PostgreSQL server

pg_basebackup -F tar -z -D /backup -U replication -h 192.168.1.50

Take backup with fast checkpoint and fetch WAL segments after backup completes

pg_basebackup -D /backup -U replication -c fast -X fetch

Related commands