pg_probackup
pg_probackup — manage backup and recovery ofPostgres Pro database clusters
Synopsis
pg_probackup
version
pg_probackup
help
[command
]
pg_probackup
init
-B
backup_dir
--skip-if-exists
pg_probackup
add-instance
-B
backup_dir
-D
data_dir
--instance
instance_name
--skip-if-exists
pg_probackup
del-instance
-B
backup_dir
--instance
instance_name
pg_probackup
set-config
-B
backup_dir
--instance
instance_name
[option
...]
pg_probackup
set-backup
-B
backup_dir
--instance
instance_name
-i
backup_id
[option
...]
pg_probackup
show-config
-B
backup_dir
--instance
instance_name
[option
...]
pg_probackup
show
-B
backup_dir
[option
...]
pg_probackup
backup
-B
backup_dir
--instance
instance_name
-b
backup_mode
[option
...]
pg_probackup
restore
-B
backup_dir
--instance
instance_name
[option
...]
pg_probackup
checkdb
-B
backup_dir
--instance
instance_name
-D
data_dir
[option
...]
pg_probackup
validate
-B
backup_dir
[option
...]
pg_probackup
merge
-B
backup_dir
--instance
instance_name
-i
backup_id
[option
...]
pg_probackup
delete
-B
backup_dir
--instance
instance_name
{-i
backup_id
|--delete-wal
|--delete-expired
|--merge-expired
} [option
...]
pg_probackup
archive-push
-B
backup_dir
--instance
instance_name
--wal-file-path
wal_file_path
--wal-file-name
wal_file_name
[option
...]
pg_probackup
archive-get
-B
backup_dir
--instance
instance_name
--wal-file-path
wal_file_path
--wal-file-name
wal_file_name
[option
...]
pg_probackup
catchup
-b
catchup_mode
--source-pgdata
=path_to_pgdata_on_remote_server
--destination-pgdata
=path_to_local_dir
[option
...]
Description#
pg_probackup is a utility to manage backup and recovery ofPostgres Pro database clusters. It is designed to perform periodic backups of thePostgres Pro instance that enable you to restore the server in case of a failure.pg_probackup supports PostgreSQL 11 or higher.
Overview#
As compared to other backup solutions,pg_probackup offers the following benefits that can help you implement different backup strategies and deal with large amounts of data:
Incremental backup: with three different incremental modes, you can plan the backup strategy in accordance with your data flow. Incremental backups allow you to save disk space and speed up backup as compared to taking full backups. It is also faster to restore the cluster by applying incremental backups than by replaying WAL files.
Incremental restore: speed up restore from a backup by reusing valid unchanged pages available in PGDATA.
Validation: automatic data consistency checks and on-demand backup validation without actual data recovery.
Verification: on-demand verification ofPostgres Pro instance with the
checkdb
command.Retention: managing WAL archive and backups in accordance with retention policy. You can configure retention policy based on recovery time or the number of backups to keep, as well as specify time to live (TTL) for a particular backup. Expired backups can be merged or deleted.
Parallelization: running
backup
,restore
,merge
,delete
,validate
, andcheckdb
processes on multiple parallel threads.Compression: storing backup data in a compressed state to save disk space.
Deduplication: saving disk space by excluding non-data files (such as
_vm
or_fsm
) from incremental backups if these files have not changed since they were copied into one of the previous backups in this incremental chain.Remote operations: backing upPostgres Pro instance located on a remote system or restoring a backup remotely.
Backups from a standby: avoiding extra load on the primary by taking backups from a standby server.
External directories: backing up files and directories located outside of thePostgres Pro data directory (
PGDATA
), such as scripts, configuration files, logs, or SQL dump files.Backup catalog: getting the list of backups and the corresponding meta information in plain text orJSON formats.
Archive catalog: getting the list of all WAL timelines and the corresponding meta information in plain text orJSON formats.
Partial restore: restoring only the specified databases.
Catchup: cloning aPostgres Pro instance for a fallen-behind standby server to“catch up” with the primary.
To manage backup data,pg_probackup creates abackup catalog. This is a directory that stores all backup files with additional meta information, as well as WAL archives required for point-in-time recovery. You can store backups for different instances in separate subdirectories of a single backup catalog.
Usingpg_probackup, you can take full or incrementalbackups:
FULL backups contain all the data files required to restore the database cluster.
Incremental backups operate at the page level, only storing the data that has changed since the previous backup. It allows you to save disk space and speed up the backup process as compared to taking full backups. It is also faster to restore the cluster by applying incremental backups than by replaying WAL files.pg_probackup supports the following modes of incremental backups:
DELTA backup. In this mode,pg_probackup reads all data files in the data directory and copies only those pages that have changed since the previous backup. This mode can impose read-only I/O pressure equal to a full backup.
PAGE backup. In this mode,pg_probackup scans all WAL files in the archive from the moment the previous full or incremental backup was taken. Newly created backups contain only the pages that were mentioned in WAL records. This requires all the WAL files since the previous backup to be present in the WAL archive. If the size of these files is comparable to the total size of the database cluster files, speedup is smaller, but the backup still takes less space. You have to configure WAL archiving as explained inSetting up continuous WAL archiving to make PAGE backups.
PTRACK backup. In this mode,Postgres Pro tracks page changes on the fly. Continuous archiving is not necessary for it to operate. Each time a relation page is updated, this page is marked in a special PTRACK bitmap. Tracking implies some minor overhead on the database server operation, but speeds up incremental backups significantly.
pg_probackup can take only physical online backups, and online backups require WAL for consistent recovery. So regardless of the chosen backup mode (FULL, PAGE or DELTA), any backup taken withpg_probackup must use one of the followingWAL delivery modes:
ARCHIVE. Such backups rely oncontinuous archiving to ensure consistent recovery. This is the default WAL delivery mode.
STREAM. Such backups include all the files required to restore the cluster to a consistent state at the time the backup was taken. Regardless ofcontinuous archiving having been set up or not, the WAL segments required for consistent recovery are streamed via replication protocol during backup and included into the backup files. That's why such backups are calledautonomous, orstandalone.
Limitations#
pg_probackup currently has the following limitations:
The remote mode is not supported on Windows systems.
On Unix systems, forPostgres Pro, a backup can be made only by the same OS user that has started thePostgres Pro server. For example, ifPostgres Pro server is started by user
postgres
, thebackup
command must also be run by userpostgres
. To satisfy this requirement when taking backups in theremote mode using SSH, you must set--remote-user
option topostgres
.ThePostgres Pro server from which the backup was taken and the restored server must be compatible by theblock_size andwal_block_size parameters and have the same major release number. Depending on cluster configuration,Postgres Pro itself may apply additional restrictions, such as CPU architecture orlibc/icu versions.
Quick Start#
To quickly get started withpg_probackup, complete the steps below. This will set up FULL and DELTA backups in the remote mode and demonstrate some basicpg_probackup operations. In the following, these terms are used:
backup
—Postgres Pro role used to connect to thePostgres Pro cluster.backupdb
— database used to connect to thePostgres Pro cluster.backup_host
— host with the backup catalog.backup_user
— user onbackup_host
running allpg_probackup operations./mnt/backups
— directory onbackup_host
where the backup catalog is stored.postgres_host
— host with thePostgres Pro cluster.postgres
— user onpostgres_host
under whichPostgres Pro cluster processes are running./var/lib/pgpro/std-16/data
—Postgres Pro data directory onpostgres_host
.
Steps to perform:#
Installpg_probackup on both
backup_host
andpostgres_host
.Set up an SSH connection from
backup_host
topostgres_host
.Configure your database cluster forSTREAM backups.
Initialize the backup catalog:
backup_user@backup_host:~$ pg_probackup init -B /mnt/backupsINFO: Backup catalog '/mnt/backups' successfully initialized
Add a backup instance called
mydb
to the backup catalog:backup_user@backup_host:~$ pg_probackup add-instance \ -B /mnt/backups \ -D /var/lib/pgpro/std-16/data \ --instance=node \ --remote-host=postgres_host \ --remote-user=postgresINFO: Instance 'node' successfully initialized
Make a FULL backup:
backup_user@backup_host:~$ pg_probackup backup \ -B /mnt/backups \ -b FULL \ --instance=node \ --stream \ --compress-algorithm=zstd \ --remote-host=postgres_host \ --remote-user=postgres \ -U backup \ -d backupdbINFO: Backup start, pg_probackup version: 2.7.3, instance: node, backup ID: SBOL6J, backup mode: FULL, wal mode: STREAM, remote: true, compress-algorithm: zstd, compress-level: 1WARNING: pgpro_edition() function is old-style and will be removed in future major release, use pgpro_edition GUC variable instead.INFO: This PostgreSQL instance was initialized with data block checksums. Data block corruption will be detectedINFO: Database backup startINFO: wait for pg_backup_start()INFO: PGDATA size: 96MBINFO: Current Start LSN: 0/8000028, TLI: 1INFO: Start transferring data filesINFO: Data files are transferred, time elapsed: 2sINFO: wait for pg_stop_backup()INFO: pg_stop_backup() successfully executedINFO: stop_stream_lsn 0/9000000 currentpos 0/9000000INFO: backup->stop_lsn 0/8004E40INFO: Getting the Recovery Time from WALINFO: Syncing backup files to diskINFO: Backup files are synced, time elapsed: 1sINFO: Validating backup SBOL6JINFO: Backup SBOL6J data files are validINFO: Backup SBOL6J resident size: 53MBINFO: Backup SBOL6J completed
List the backups of the instance:
backup_user@backup_host:~$ pg_probackup show \ -B /mnt/backups \ --instance=node============================================================================================================================================= Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status ============================================================================================================================================= node 17 SBOL6J 2024-04-09 18:18:21.970314+03 FULL STREAM 1/0 4s 37MB 16MB zstd 2.57 0/8000028 0/8004E40 OK
Make an incremental backup in the DELTA mode:
backup_user@backup_host:~$ pg_probackup backup \ -B /mnt/backups \ -b DELTA \ --instance=node \ --stream \ --compress-algorithm=zstd \ --remote-host=postgres_host \ --remote-user=postgres \ -U backup \ -d backupdbINFO: Backup start, pg_probackup version: 2.7.3, instance: node, backup ID: SBOL6N, backup mode: DELTA, wal mode: STREAM, remote: true, compress-algorithm: zstd, compress-level: 1WARNING: pgpro_edition() function is old-style and will be removed in future major release, use pgpro_edition GUC variable instead.INFO: This PostgreSQL instance was initialized with data block checksums. Data block corruption will be detectedINFO: Database backup startINFO: wait for pg_backup_start()INFO: Parent backup: SBOL6JINFO: PGDATA size: 96MBINFO: Current Start LSN: 0/9000028, TLI: 1INFO: Parent Start LSN: 0/8000028, TLI: 1INFO: Start transferring data filesINFO: Data files are transferred, time elapsed: 1sINFO: wait for pg_stop_backup()INFO: pg_stop_backup() successfully executedINFO: stop_stream_lsn 0/A000000 currentpos 0/A000000INFO: backup->stop_lsn 0/9000190INFO: Getting the Recovery Time from WALINFO: Syncing backup files to diskINFO: Backup files are synced, time elapsed: 0INFO: Validating backup SBOL6NINFO: Backup SBOL6N data files are validINFO: Backup SBOL6N resident size: 17MBINFO: Backup SBOL6N completed
Add or modify some parameters in thepg_probackup configuration file, so that you do not have to specify them each time on the command line:
backup_user@backup_host:~$ pg_probackup set-config \ -B /mnt/backups \ --instance=node \ --remote-host=postgres_host \ --remote-user=postgres \ -U backup \ -d backupdb
Check the configuration of the instance:
backup_user@backup_host:~$ pg_probackup show-config \ -B /mnt/backups \ --instance=node# Backup instance informationpgdata = /var/lib/pgpro/std-16/datasystem-identifier = 7355886958826772732xlog-seg-size = 16777216# Connection parameterspgdatabase = backupdbpghost = postgres_hostpguser = backup# Archive parametersarchive-timeout = 5min# Logging parameterslog-level-console = INFOlog-level-file = OFFlog-format-console = PLAINlog-format-file = PLAINlog-filename = pg_probackup.loglog-rotation-size = 0TBlog-rotation-age = 0d# Retention parametersretention-redundancy = 0retention-window = 0wal-depth = 0# Compression parameterscompress-algorithm = nonecompress-level = 1# Remote access parametersremote-proto = sshremote-host = postgres_hostremote-user = postgres
Note that the parameters not modified via
set-config
retain their default values.Make another incremental backup in the DELTA mode, omitting the parameters stored in the configuration file earlier:
backup_user@backup_host:~$ pg_probackup backup \ -B /mnt/backups \ -b DELTA \ --instance=node \ --stream \ --compress-algorithm=zstdINFO: Backup start, pg_probackup version: 2.7.3, instance: node, backup ID: SBOL6P, backup mode: DELTA, wal mode: STREAM, remote: true, compress-algorithm: zstd, compress-level: 1WARNING: pgpro_edition() function is old-style and will be removed in future major release, use pgpro_edition GUC variable instead.INFO: This PostgreSQL instance was initialized with data block checksums. Data block corruption will be detectedINFO: Database backup startINFO: wait for pg_backup_start()INFO: Parent backup: SBOL6NINFO: PGDATA size: 96MBINFO: Current Start LSN: 0/A000028, TLI: 1INFO: Parent Start LSN: 0/9000028, TLI: 1INFO: Start transferring data filesINFO: Data files are transferred, time elapsed: 1sINFO: wait for pg_stop_backup()INFO: pg_stop_backup() successfully executedINFO: stop_stream_lsn 0/B000000 currentpos 0/B000000INFO: backup->stop_lsn 0/A000190INFO: Getting the Recovery Time from WALINFO: Syncing backup files to diskINFO: Backup files are synced, time elapsed: 0INFO: Validating backup SBOL6PINFO: Backup SBOL6P data files are validINFO: Backup SBOL6P resident size: 17MBINFO: Backup SBOL6P completed
List the backups of the instance again:
backup_user@backup_host:~$ pg_probackup show \ -B /mnt/backups \ --instance=node================================================================================================================================================ Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status ================================================================================================================================================ node 17 SBOL6P 2024-04-09 18:18:26.630175+03 DELTA STREAM 1/1 1s 1147kB 16MB zstd 1.00 0/A000028 0/A000190 OK node 17 SBOL6N 2024-04-09 18:18:25.015713+03 DELTA STREAM 1/1 2s 1160kB 16MB zstd 1.04 0/9000028 0/9000190 OK node 17 SBOL6J 2024-04-09 18:18:21.970314+03 FULL STREAM 1/0 4s 37MB 16MB zstd 2.57 0/8000028 0/8004E40 OK
Restore the data from the latest available backup to an arbitrary location:
backup_user@backup_host:~$ pg_probackup restore \ -B /mnt/backups \ -D /var/lib/pgpro/std-16/staging-data \ --instance=nodeINFO: Validating parents for backup SBOL6PINFO: Validating backup SBOL6JINFO: Backup SBOL6J data files are validINFO: Validating backup SBOL6NINFO: Backup SBOL6N data files are validINFO: Validating backup SBOL6PINFO: Backup SBOL6P data files are validINFO: Backup SBOL6P WAL segments are validINFO: Backup SBOL6P is valid.INFO: Restoring the database from the backup starting at 2024-04-09 18:18:25+03 on localhostINFO: Start restoring backup files. PGDATA size: 112MBINFO: Backup files are restored. Transferred bytes: 112MB, time elapsed: 2sINFO: Restore incremental ratio (less is better): 100% (112MB/112MB)INFO: Syncing restored files to diskINFO: Restored backup files are synced, time elapsed: 1sINFO: Restore of backup SBOL6P completed.
Installation and Setup#
Once you havepg_probackup installed, complete the following setup:
Initialize the backup catalog.
Add a new backup instance to the backup catalog.
Configure the database cluster to enablepg_probackup backups.
Optionally, configure SSH for runningpg_probackup operations in the remote mode.
Initializing the Backup Catalog#
pg_probackup stores all WAL and backup files in the corresponding subdirectories of the backup catalog.
To initialize the backup catalog, run the following command:
pg_probackup init -Bbackup_dir
wherebackup_dir
is the path to the backup catalog. If thebackup_dir
already exists, it must be empty. Otherwise,pg_probackup returns an error.
The user launchingpg_probackup must have full access to thebackup_dir
directory.
pg_probackup creates thebackup_dir
backup catalog, with the following subdirectories:
wal/
— directory for WAL files.backups/
— directory for backup files.
Once the backup catalog is initialized, you can add a new backup instance.
Adding a New Backup Instance#
pg_probackup can store backups for multiple database clusters in a single backup catalog. To set up the required subdirectories, you must add a backup instance to the backup catalog for each database cluster you are going to back up.
To add a new backup instance, run the following command:
pg_probackup add-instance -Bbackup_dir
-Ddata_dir
--instance=instance_name
[remote_options
]
Where:
data_dir
is the data directory of the cluster you are going to back up. To set up and usepg_probackup, write access to this directory is required.instance_name
is the name of the subdirectories that will store WAL and backup files for this cluster.remote_options are optional parameters that need to be specified only if
data_dir
is located on a remote system.
pg_probackup creates theinstance_name
subdirectories under thebackups/
andwal/
directories of the backup catalog. Thebackups/
directory contains theinstance_name
pg_probackup.conf
configuration file that controlspg_probackup settings for this backup instance. If you run this command with theremote_options, the specified parameters will be added topg_probackup.conf
.
For details on how to fine-tunepg_probackup configuration, seethe section called “Configuringpg_probackup”.
The user launchingpg_probackup must have full access tobackup_dir
directory and at least read-only access todata_dir
directory. If you specify the path to the backup catalog in theBACKUP_PATH
environment variable, you can omit the corresponding option when runningpg_probackup commands.
Note
ForPostgres Pro 11 or higher, it is recommended to use thegroup access feature, so that backups can be done by any OS user in the same group as the cluster owner. In this case, the user should have read permissions for the cluster directory.
Configuring the Database Cluster#
Althoughpg_probackup can be used by a superuser, it is recommended to create a separate role with the minimum permissions required for the chosen backup strategy. In these configuration instructions, thebackup
role is used as an example.
For security reasons, it is recommended to run the configuration SQL queries below in a separate database.
postgres=# CREATE DATABASE backupdb;postgres=# \c backupdb
To perform abackup, the following permissions for rolebackup
are required only in the databaseused for connection to thePostgres Pro server.
ForPostgres Pro versions 11 — 14:
BEGIN;CREATE ROLE backup WITH LOGIN;GRANT USAGE ON SCHEMA pg_catalog TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.current_setting(text) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.set_config(text, text, boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_is_in_recovery() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_start_backup(text, boolean, boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_stop_backup(boolean, boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_create_restore_point(text) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_switch_wal() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_last_wal_replay_lsn() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_current() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_current_snapshot() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_snapshot_xmax(txid_snapshot) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_control_checkpoint() TO backup;COMMIT;
ForPostgres Pro 15 or higher:
BEGIN;CREATE ROLE backup WITH LOGIN;GRANT USAGE ON SCHEMA pg_catalog TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.current_setting(text) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.set_config(text, text, boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_is_in_recovery() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_backup_start(text, boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_backup_stop(boolean) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_create_restore_point(text) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_switch_wal() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_last_wal_replay_lsn() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_current() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_current_snapshot() TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.txid_snapshot_xmax(txid_snapshot) TO backup;GRANT EXECUTE ON FUNCTION pg_catalog.pg_control_checkpoint() TO backup;COMMIT;
In thepg_hba.conf file, allow connection to the database cluster on behalf of thebackup
role.
Sincepg_probackup needs to read cluster files directly,pg_probackup must be started by (or connected to, if used in the remote mode) the OS user that has read access to all files and directories inside the data directory (PGDATA
) you are going to back up.
Depending on whether you plan to takestandalone orarchive backups,Postgres Pro cluster configuration will differ, as specified in the sections below. To back up the database cluster from a standby server, runpg_probackup in the remote mode, or create PTRACK backups, additional setup is required.
For details, see the sectionsSetting up STREAM Backups,Setting up continuous WAL archiving,Setting up Backup from Standby,Configuring the Remote Mode,Setting up Partial Restore, andSetting up PTRACK Backups.
Setting up STREAM Backups#
To set up the cluster forSTREAM backups, complete the following steps:
If the
backup
role does not exist, create it with theREPLICATION
privilege whenConfiguring the Database Cluster:CREATE ROLE backup WITH LOGIN REPLICATION;
If the
backup
role already exists, grant it with theREPLICATION
privilege:ALTER ROLE backup WITH REPLICATION;
In thepg_hba.conf file, allow replication on behalf of the
backup
role.Make sure the parametermax_wal_senders is set high enough to leave at least one session available for the backup process.
Set the parameterwal_level to be higher than
minimal
.
If you are planning to take PAGE backups in the STREAM mode or perform PITR with STREAM backups, you still have to configure WAL archiving, as explained in the sectionSetting up continuous WAL archiving.
Once these steps are complete, you can start taking FULL, PAGE, DELTA, and PTRACK backups in theSTREAM WAL mode.
Note
If you are planning to rely on.pgpass for authentication when running backup in STREAM mode, then .pgpass must contain credentials forreplication
database, used to establish connection via replication protocol. Example: pghost:5432:replication:backup_user:my_strong_password
Setting up Continuous WAL Archiving#
Making backups in the PAGE backup mode, performingPITR and making backups with theARCHIVE WAL delivery mode requirecontinuous WAL archiving to be enabled. To set up continuous archiving in the cluster, complete the following steps:
Make sure thewal_level parameter is higher than
minimal
.If you are configuring archiving on the primary,archive_mode must be set to
on
oralways
. To perform archiving on a standby, set this parameter toalways
.Set thearchive_command parameter, as follows:
archive_command = '"
install_dir
/pg_probackup" archive-push -B "backup_dir
" --instance=instance_name
--wal-file-name=%f [remote_options
]'
whereinstall_dir
is the installation directory of thepg_probackup version you are going to use,backup_dir
andinstance_name
refer to the already initialized backup catalog instance for this database cluster, andremote_options only need to be specified to archive WAL on a remote host. For details about all possiblearchive-push
parameters, see the sectionarchive-push.
Once these steps are complete, you can start making backups in theARCHIVE WAL mode, backups in the PAGE backup mode, as well as performPITR.
You can view the current state of the WAL archive using theshow command. For details, seethe section called “Viewing WAL Archive Information”.
If you are planning to make PAGE backups and/or backups withARCHIVE WAL mode from a standby server that generates a small amount of WAL traffic, without long waiting for WAL segment to fill up, consider setting thearchive_timeoutPostgres Pro parameteron the primary. The value of this parameter should be slightly lower than the--archive-timeout
setting (5 minutes by default), so that there is enough time for the rotated segment to be streamed to a standby and sent to WAL archive before the backup is aborted because of--archive-timeout
.
Note
Instead of using thearchive-push command provided bypg_probackup, you can use any other tool to set up continuous archiving as long as it delivers WAL segments into
directory. If compression is used, it should bebackup_dir
/wal/instance_name
gzip
, and.gz
suffix in filename is mandatory.
Note
Instead of configuring continuous archiving by setting thearchive_mode
andarchive_command
parameters, you can opt for using thepg_receivewal utility. In this case,pg_receivewal-D
option should point todirectory
directory.pg_probackup supports WAL compression that can be done bypg_receivewal.“Zero Data Loss” archive strategy can be achieved only by usingpg_receivewal.backup_dir
/wal/instance_name
Setting up Backups from a Standby#
pg_probackup can take backups from a standby server. This requires the following additional setup:
On the standby server, set thehot_standby parameter to
on
.On the primary server, set thefull_page_writes parameter to
on
.To perform standalone backups on a standby, complete all the steps in sectionSetting up STREAM Backups.
To perform archive backups on a standby, complete all steps in sectionSetting up continuous WAL archiving.
Once these steps are complete, you can start taking FULL, PAGE, DELTA, or PTRACK backups with appropriate WAL delivery mode: ARCHIVE or STREAM, from the standby server.
Backups from a standby server have the following limitations:
If a standby is promoted to a primary during the backup process, the backup fails.
All WAL records required for the backup must contain sufficient full-page writes. This requires you to enable
full_page_writes
on the primary, and not to use tools likepg_compresslog asarchive_command to remove full-page writes from WAL files.
Setting up Cluster Verification#
Logical verification of a database cluster requires the following additional setup. Rolebackup
is used as an example:
Install theamcheck oramcheck_next extensionin every database of the cluster:
CREATE EXTENSION amcheck;
Grant the following permissions to the
backup
rolein every database of the cluster:
GRANT SELECT ON TABLE pg_catalog.pg_am TO backup;GRANT SELECT ON TABLE pg_catalog.pg_class TO backup;GRANT SELECT ON TABLE pg_catalog.pg_database TO backup;GRANT SELECT ON TABLE pg_catalog.pg_namespace TO backup;GRANT SELECT ON TABLE pg_catalog.pg_extension TO backup;GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO backup;GRANT EXECUTE ON FUNCTION bt_index_check(regclass, bool) TO backup;GRANT EXECUTE ON FUNCTION bt_index_check(regclass, bool, bool) TO backup;
Setting up Partial Restore#
If you are planning to use partial restore, complete the following additional step:
Grant the read-only access to
pg_catalog.pg_database
to thebackup
role only in the databaseused for connection toPostgres Pro server:GRANT SELECT ON TABLE pg_catalog.pg_database TO backup;
Configuring the Remote Mode#
pg_probackup supports the remote mode that allows you to perform backup, restore and WAL archiving operations remotely. In this mode, the backup catalog is stored on a local system, whilePostgres Pro instance to backup and/or to restore is located on a remote system. Currently the only supported remote protocol is SSH.
Set up SSH#
If you are going to usepg_probackup in remote mode via SSH, complete the following steps:
Installpg_probackup on both systems:
backup_host
andpostgres_host
.For communication between the hosts set up a passwordless SSH connection between the
backup_user
user onbackup_host
and thepostgres
user onpostgres_host
:backup_user@backup_host:~$ ssh-copy-id postgres@postgres_host
Where:
backup_host
is the system withbackup catalog.postgres_host
is the system with thePostgres Pro cluster.backup_user
is the OS user onbackup_host
used to runpg_probackup.postgres
is the user onpostgres_host
under whichPostgres Pro cluster processes are running. ForPostgres Pro 11 or higher a more secure approach can be used thanks togroup access feature.
If you are going to rely oncontinuous WAL archiving, set up a passwordless SSH connection between the
postgres
user onpostgres_host
and thebackup
user onbackup_host
:postgres@postgres_host:~$ ssh-copy-id backup_user@backup_host
Make surepg_probackup on
postgres_host
can be located when a connection via SSH is made. For example, forBash, you can modifyPATH
in~/.bashrc
of thepostgres
user (above the line inbashrc
that exits the script for non-interactive shells). Alternatively, forpg_probackup commands, specify the path to the directory containing thepg_probackup binary onpostgres_host
via the--remote-path option.
pg_probackup in the remote mode via SSH works as follows:
Only the following commands can be launched in the remote mode:add-instance,backup,restore,delete,catchup,archive-push, andarchive-get.
Operating in remote mode requirespg_probackup binary to be installed on both local and remote systems. The versions of local and remote binary must be the same.
When started in the remote mode, the mainpg_probackup process on the local system connects to the remote system via SSH and launches one or more agent processes on the remote system, which are calledremote agents. The number of remote agents is equal to the
-j
/--threads
setting.The mainpg_probackup process uses remote agents to access remote files and transfer data between local and remote systems.
Remote agents try to minimize the network traffic and the number of round-trips between hosts.
The main process is usually started on
backup_host
and connects topostgres_host
, but in case ofarchive-push
andarchive-get
commands the main process is started onpostgres_host
and connects tobackup_host
.Once data transfer is complete, remote agents are terminated and SSH connections are closed.
If an error condition is encountered by a remote agent, then all agents are terminated and error details are reported by the mainpg_probackup process, which exits with an error.
Compression is always done on
postgres_host
, while decompression is always done onbackup_host
.
Note
You can imposeadditional restrictions on SSH settings to protect the system in the event of account compromise.
Note
Setting the number of threads (-j
/--threads
option) to a value greater than 10 forpg_probackup working in the remote mode via SSH may result in the actual number of SSH connections exceeding the maximum allowed number of simultaneous SSH connections on the remote server and consequently lead to an“ERROR: Agent error: kex_exchange_identification: Connection closed by remote host” error. To correct the error, either reduce the number ofpg_probackup threads or adjust the value ofMaxStartups
configuration parameter of the remote SSH server. If SSH is set up as axinetd service on the remote server, adjust the value of thexinetdper_source
configuration parameter rather thanMaxStartups
.
Setting up PTRACK Backups#
Note
PTRACK versions lower than 2.0 are deprecated and not supported. Postgres Pro Standard and Postgres Pro Enterprise versions starting with 11.9.1 contain PTRACK 2.0. Upgrade your server to avoid issues in backups that you will take in future and be sure to take fresh backups of your clusters with the upgraded PTRACK since the backups taken with PTRACK 1.x might be corrupt.
If you are going to use PTRACK backups, complete the following additional steps.
Note
The permissions required for the role that will perform PTRACK backups (thebackup
role in the examples below) are listed inthe section called “Configuring the Database Cluster”. The role must have permissions only in the database used for connection to thePostgres Pro server.
ForPostgres Pro 11 or higher:
Create PTRACK extension:
CREATE EXTENSION ptrack;
To enable tracking page updates, set
ptrack.map_size
parameter to a positive integer and restart the server.For optimal performance, it is recommended to set
ptrack.map_size
to
, whereN
/ 1024N
is the size of thePostgres Pro cluster, in MB. If you set this parameter to a lower value, PTRACK is more likely to map several blocks together, which leads to false-positive results when tracking changed blocks and increases the incremental backup size as unchanged blocks can also be copied into the incremental backup. Settingptrack.map_size
to a higher value does not affect PTRACK operation, but it is not recommended to set this parameter to a value higher than 1024.
Note
If you change theptrack.map_size
parameter value, the previously created PTRACK map file is cleared, and tracking newly changed blocks starts from scratch. Thus, you have to retake a full backup before taking incremental PTRACK backups after changingptrack.map_size
.
Usage#
Creating a Backup#
To create a backup, run the following command:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-bbackup_mode
Wherebackup_mode
can take one of the following values:FULL
,DELTA
,PAGE
, andPTRACK
.
When restoring a cluster from an incremental backup,pg_probackup relies on the parent full backup and all the incremental backups between them, which is called“the backup chain”. Thus, to perform incremental backups, it is necessary to have the last parent full backup with the statusOK
orDONE
in the directory. If the parent full backup has theMERGING
orMERGED
status, an incremental backup cannot be performed.
For example, if merge has already been launched with a single full backup, an attempt to perform an incremental backup will end with the following messages:
WARNING: Valid full backup on current timeline 1 is not found, trying to look up on previous timelinesWARNING: Cannot find valid backup on previous timelinesERROR: Create new full backup before an incremental one
ARCHIVE Mode#
ARCHIVE is the default WAL delivery mode.
For example, to make a FULL backup in ARCHIVE mode, run:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL
ARCHIVE backups rely oncontinuous archiving to get WAL segments required to restore the cluster to a consistent state at the time the backup was taken.
When a backup is taken,pg_probackup ensures that WAL files containing WAL records betweenStart LSN
andStop LSN
actually exist in
directory.pg_probackup also ensures that WAL records betweenbackup_dir
/wal/instance_name
Start LSN
andStop LSN
can be parsed. This precaution eliminates the risk of silent WAL corruption.
STREAM Mode#
STREAM is the optional WAL delivery mode.
For example, to make a FULL backup in the STREAM mode, add the--stream
flag to the command from the previous example:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --stream --temp-slot
The optional--temp-slot
flag ensures that the required segments remain available if the WAL is rotated before the backup is complete.
Unlike backups in ARCHIVE mode, STREAM backups include all the WAL segments required to restore the cluster to a consistent state at the time the backup was taken.
Duringbackuppg_probackup streams WAL files containing WAL records betweenStart LSN
andStop LSN
to
directory. To eliminate the risk of silent WAL corruption,pg_probackup also checks that WAL records betweenbackup_dir
/backups/instance_name
/backup_id
/database/pg_walStart LSN
andStop LSN
can be parsed.
Even if you are usingcontinuous archiving, STREAM backups can still be useful in the following cases:
STREAM backups can be restored on the server that has no file access to WAL archive.
STREAM backups enable you to restore the cluster state at the point in time for which WAL files in archive are no longer available.
Backup in STREAM mode can be taken from a standby of a server that generates small amount of WAL traffic, without long waiting for WAL segment to fill up.
Page Validation#
Ifdata_checksums are enabled in the database cluster,pg_probackup uses this information to check correctness of data files during backup. While reading each page,pg_probackup checks whether the calculated checksum coincides with the checksum stored in the page header. This guarantees that thePostgres Pro instance and the backup itself have no corrupt pages. Note thatpg_probackup reads database files directly from the filesystem, so under heavy write load during backup it can show false-positive checksum mismatches because of partial writes. If a page checksum mismatch occurs, the page is re-read and checksum comparison is repeated.
A page is considered corrupt if checksum comparison has failed more than 300 times. In this case, the backup is aborted.
Even if data checksums are not enabled,pg_probackup always performs sanity checks for page headers.
External Directories#
To back up a directory located outside of the data directory, use the optional--external-dirs
parameter that specifies the path to this directory. If you would like to add more than one external directory, you can provide several paths separated by colons on Linux systems or semicolons on Windows systems.
For example, to include/etc/dir1
and/etc/dir2
directories into the full backup of yourinstance_name
instance that will be stored under thebackup_dir
directory on Linux, run:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --external-dirs=/etc/dir1:/etc/dir2
Similarly, to includeC:\dir1
andC:\dir2
directories into the full backup on Windows, run:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --external-dirs=C:\dir1;C:\dir2
pg_probackup recursively copies the contents of each external directory into a separate subdirectory in the backup catalog. Since external directories included into different backups do not have to be the same, when you are restoring the cluster from an incremental backup, only those directories that belong to this particular backup will be restored. Any external directories stored in the previous backups will be ignored.
To include the same directories into each backup of your instance, you can specify them in thepg_probackup.conf
configuration file using theset-config command with the--external-dirs
option.
Performing Cluster Verification#
To verify thatPostgres Pro database cluster is not corrupt, run the following command:
pg_probackup checkdb [-Bbackup_dir
[--instance=instance_name
]] [-Ddata_dir
] [connection_options
]
This command performs physical verification of all data files located in the specified data directory by running page header sanity checks, as well as block-level checksum verification if checksums are enabled. If a corrupt page is detected,checkdb
continues cluster verification until all pages in the cluster are validated.
By default, similarpage validation is performed automatically while a backup is taken bypg_probackup. Thecheckdb
command enables you to perform such page validation on demand, without taking any backup copies, even if the cluster is not backed up usingpg_probackup at all.
To perform cluster verification,pg_probackup needs to connect to the cluster to be verified. In general, it is enough to specify the backup instance of this cluster forpg_probackup to determine the required connection options. However, if-B
and--instance
options are omitted, you have to provideconnection options anddata_dir
via environment variables or command-line options.
Physical verification cannot detect logical inconsistencies, missing or nullified blocks and entire files, or similar anomalies. Extensionsamcheck andamcheck_next provide a partial solution to these problems.
If you would like, in addition to physical verification, to verify all indexes in all databases using these extensions, you can specify the--amcheck
flag when running thecheckdb command:
pg_probackup checkdb -Ddata_dir
--amcheck [connection_options
]
You can skip physical verification by specifying the--skip-block-validation
flag. In this case, you can omitbackup_dir anddata_dir options, onlyconnection options are mandatory:
pg_probackup checkdb --amcheck --skip-block-validation [connection_options
]
Logical verification can be done more thoroughly with the--heapallindexed
flag by checking that all heap tuples that should be indexed are actually indexed, but at the higher cost of CPU, memory, and I/O consumption.
Validating a Backup#
pg_probackup calculates checksums for each file in a backup during the backup process. The process of checking checksums of backup data files is calledthe backup validation. By default, validation is run immediately after the backup is taken and right before the restore, to detect possible backup corruption.
If you would like to skip backup validation, you can specify the--no-validate
flag when runningbackup andrestore commands.
To ensure that all the required backup files are present and can be used to restore the database cluster, you can run thevalidate command with the exactrecovery target options you are going to use for recovery.
For example, to check that you can restore the database cluster from a backup copy up to transaction ID 4242, run this command:
pg_probackup validate -Bbackup_dir
--instance=instance_name
--recovery-target-xid=4242
If validation completes successfully,pg_probackup displays the corresponding message. If validation fails, you will receive an error message with the exact time, transaction ID, and LSN up to which the recovery is possible.
If you specifybackup_id via-i/--backup-id
option, then only the backup copy with specified backup ID will be validated. Ifbackup_id is specified withrecovery target options, thevalidate
command will check whether it is possible to restore the specified backup to the specified recovery target.
For example, to check that you can restore the database cluster from a backup copy with theSBOL6P
backup ID up to the specified timestamp, run this command:
pg_probackup validate -Bbackup_dir
--instance=instance_name
-i SBOL6P --recovery-target-time="2024-04-10 18:18:26+03"
If you specify thebackup_id
of an incremental backup, all its parents starting from FULL backup will be validated.
If you omit all the parameters, all backups are validated.
Restoring a Cluster#
To restore the database cluster from a backup, run therestore command with at least the following options:
pg_probackup restore -Bbackup_dir
--instance=instance_name
-ibackup_id
Where:
backup_dir
is the backup catalog that stores all backup files and meta information.instance_name
is the backup instance for the cluster to be restored.backup_id
specifies the backup to restore the cluster from. If you omit this option,pg_probackup uses the latest valid backup available for the specified instance. If you specify an incremental backup to restore,pg_probackup automatically restores the underlying full backup and then sequentially applies all the necessary increments.
Once therestore
command is complete, start the database service.
If you restoreARCHIVE backups, performPITR, or specify the--restore-as-replica
flag with therestore
command to set up a standby server,pg_probackup creates a recovery configuration file once all data files are copied into the target directory. This file includes the minimal settings required for recovery, except for the password in theprimary_conninfo parameter; you have to add the password manually or use the--primary-conninfo
option, if required. ForPostgres Pro 11, recovery settings are written into therecovery.conf
file. Starting fromPostgres Pro 12,pg_probackup writes these settings into theprobackup_recovery.conf
file and then includes it intopostgresql.auto.conf
.
If you are restoring a STREAM backup, the restore is complete at once, with the cluster returned to a self-consistent state at the point when the backup was taken. For ARCHIVE backups,Postgres Pro replays all available archived WAL segments, so the cluster is restored to the latest state possible within the current timeline. You can change this behavior by using therecovery target options with therestore
command, as explained inthe section called “Performing Point-in-Time (PITR) Recovery”.
If the cluster to restore contains tablespaces,pg_probackup restores them to their original location by default. To restore tablespaces to a different location, use the--tablespace-mapping
/-T
option. Otherwise, restoring the cluster on the same host will fail if tablespaces are in use, because the backup would have to be written to the same directories.
When using the--tablespace-mapping
/-T
option, you must provide absolute paths to the old and new tablespace directories. If a path happens to contain an equals sign (=
), escape it with a backslash. This option can be specified multiple times for multiple tablespaces. For example:
pg_probackup restore -Bbackup_dir
--instance=instance_name
-Ddata_dir
-j 4 -ibackup_id
-T tablespace1_dir=tablespace1_newdir
-T tablespace2_dir=tablespace2_newdir
To restore the cluster on a remote host, follow the instructions inthe section called “Usingpg_probackup in the Remote Mode”.
Note
By default, therestore command validates the specified backup before restoring the cluster. If you run regular backup validations and would like to save time when restoring the cluster, you can specify the--no-validate
flag to skip validation and speed up the recovery.
Incremental Restore#
The speed of restore from backup can be significantly improved by replacing only invalid and changed pages in already existingPostgres Pro data directory usingincremental restore options with therestore command.
To restore the database cluster from a backup in incremental mode, run therestore command with the following options:
pg_probackup restore -Bbackup_dir
--instance=instance_name
-Ddata_dir
-Iincremental_mode
Whereincremental_mode
can take one of the following values:
CHECKSUM — read all data files in the data directory, validate header and checksum in every page and replace only invalid pages and those with checksum and LSN not matching with corresponding page in backup. This is the simplest, the most fool-proof incremental mode. Recommended to use by default.
LSN — read the
pg_control
in the data directory to obtain redo LSN and redo TLI, which allows you to determine a point in history(shiftpoint), where data directory state shifted from target backup chain history. If shiftpoint is not within reach of backup chain history, then restore is aborted. If shiftpoint is within reach of backup chain history, then read all data files in the data directory, validate header and checksum in every page and replace only invalid pages and those with LSN greater than shiftpoint. This mode offers a greater speed up compared to CHECKSUM, but rely on two conditions to be met. First,data_checksums parameter must be enabled in data directory (to avoid corruption due to hint bits). This condition will be checked at the start of incremental restore and the operation will be aborted if checksums are disabled. Second, thepg_control
file must be synched with state of data directory. This condition cannot checked at the start of restore, so it is a user responsibility to ensure thatpg_control
contain valid information. Therefore it is not recommended to use LSN mode in any situation, where pg_control cannot be trusted or has been tampered with: afterpg_resetxlog
execution, after restore from backup without recovery been run, etc.NONE — regular restore without any incremental optimizations.
Regardless of chosen incremental mode, pg_probackup will check, that postmaster in given destination directory is not running andsystem-identifier
is the same as in the backup.
Suppose you want to return an old primary as a replica after switchover using incremental restore in LSN mode:
================================================================================================================================================== Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status ================================================================================================================================================== node 17 SBOL8S 2024-04-09 18:19:43.707720+03 DELTA STREAM 16/15 3s 114MB 64MB lz4 1.42 0/3C003020 0/3E8D4930 OK node 17 SBOL8G 2024-04-09 18:19:32.594670+03 PTRACK STREAM 15/15 4s 30MB 16MB zlib 2.23 0/31000028 0/310029E0 OK node 17 SBOL83 2024-04-09 18:19:22.269595+03 PAGE STREAM 15/15 7s 46MB 32MB pglz 1.44 0/29000028 0/2A0000F8 OK node 17 SBOL7P 2024-04-09 18:19:06.557301+03 FULL STREAM 15/0 6s 144MB 16MB zstd 2.47 0/22000028 0/220001C8 OK backup_user@backup_host:~$ pg_probackup restore -B /mnt/backups --instance=node -R -I lsnINFO: Destination directory and tablespace directories are empty, disable incremental restoreINFO: Validating parents for backup SBOL8SINFO: Validating backup SBOL7PINFO: Backup SBOL7P data files are validINFO: Validating backup SBOL83INFO: Backup SBOL83 data files are validINFO: Validating backup SBOL8GINFO: Backup SBOL8G data files are validINFO: Validating backup SBOL8SINFO: Backup SBOL8S data files are validINFO: Backup SBOL8S WAL segments are validINFO: Backup SBOL8S is valid.INFO: Restoring the database from the backup starting at 2024-04-09 18:19:40+03INFO: Start restoring backup files. PGDATA size: 616MBINFO: Backup files are restored. Transferred bytes: 616MB, time elapsed: 2sINFO: Restore incremental ratio (less is better): 100% (616MB/616MB)INFO: Syncing restored files to diskINFO: Restored backup files are synced, time elapsed: 2sINFO: Restore of backup SBOL8S completed.
Note
Incremental restore is possible only for backups withprogram_version
equal or greater than 2.4.0.
Partial Restore#
If you have enabledpartial restore before taking backups, you can restore only some of the databases usingpartial restore options with therestore commands.
To restore the specified databases only, run therestore command with the following options:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--db-include=database_name
The--db-include
option can be specified multiple times. For example, to restore only databasesdb1
anddb2
, run the following command:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--db-include=db1 --db-include=db2
To exclude one or more databases from restore, use the--db-exclude
option:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--db-exclude=database_name
The--db-exclude
option can be specified multiple times. For example, to exclude the databasesdb1
anddb2
from restore, run the following command:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--db-exclude=db1 --db-exclude=db2
Partial restore relies on lax behavior ofPostgres Pro recovery process toward truncated files. For recovery to work properly, files of excluded databases are restored as files of zero size. After thePostgres Pro cluster is successfully started, you must drop the excluded databases usingDROP DATABASE
command.
To decouple a single cluster containing multiple databases into separate clusters with minimal downtime, you can do partial restore of the cluster as a standby using the--restore-as-replica
option for specific databases.
Note
Thetemplate0
andtemplate1
databases are always restored.
Note
Due to recovery specifics ofPostgres Pro versions earlier than 12, it is advisable that you set thehot_standby parameter tooff
when running partial restore of aPostgres Pro cluster of version earlier than 12. Otherwise the recovery may fail.
Performing Point-in-Time (PITR) Recovery#
If you have enabledcontinuous WAL archiving before taking backups, you can restore the cluster to its state at an arbitrary point in time (recovery target) usingrecovery target options with therestore command.
You can use both STREAM and ARCHIVE backups for point in time recovery as long as the WAL archive is available at least starting from the time the backup was taken. If-i
/--backup-id
option is omitted,pg_probackup automatically chooses the backup that is the closest to the specified recovery target and starts the restore process, otherwisepg_probackup will try to restore the specified backup to the specified recovery target.
To restore the cluster state at the exact time, specify the
--recovery-target-time
option, in the timestamp format. For example:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target-time="2024-04-10 18:18:26+03"To restore the cluster state up to a specific transaction ID, use the
--recovery-target-xid
option:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target-xid=687To restore the cluster state up to the specific LSN, use
--recovery-target-lsn
option:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target-lsn=16/B374D848To restore the cluster state up to the specific named restore point, use
--recovery-target-name
option:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target-name="before_app_upgrade"To restore the backup to the latest state available in the WAL archive, use
--recovery-target
option withlatest
value:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target="latest"To restore the cluster to the earliest point of consistency, use
--recovery-target
option with theimmediate
value:pg_probackup restore -B
backup_dir
--instance=instance_name
--recovery-target='immediate'
Usingpg_probackup in the Remote Mode#
pg_probackup supports the remote mode that allows you to performbackup
andrestore
operations remotely via SSH. In this mode, the backup catalog is stored on a local system, whilePostgres Pro instance to be backed up is located on a remote system. You must havepg_probackup installed on both systems.
Note
pg_probackup relies on passwordless SSH connection for communication between the hosts.
Note
In addition to SSH connection,pg_probackup uses a regular connection to the database to manage the remote operation. See the sectionConfiguring the Database Cluster for details of how to set up a database connection.
The typical workflow is as follows:
On your backup host, configurepg_probackup as explained in the sectionInstallation and Setup. For theadd-instance andset-config commands, make sure to specifyremote options that point to the database host with thePostgres Pro instance.
If you would like to take remote backups inPAGE mode, or rely onARCHIVE WAL delivery mode, or usePITR, configure continuous WAL archiving from the database host to the backup host as explained in the sectionSetting up continuous WAL archiving. For thearchive-push andarchive-get commands, you must specify theremote options that point to the backup host with the backup catalog.
Runbackup orrestore commands withremote optionson the backup host.pg_probackup connects to the remote system via SSH and creates a backup locally or restores the previously taken backup on the remote system, respectively.
For example, to create an archive full backup of aPostgres Pro cluster located on a remote system with host address192.168.0.2
on behalf of thepostgres
user via SSH connection through port2302
, run:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302
To restore the latest available backup on a remote system with host address192.168.0.2
on behalf of thepostgres
user via SSH connection through port2302
, run:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302
Restoring an ARCHIVE backup or performing PITR in the remote mode require additional information: destination address, port and username for establishing an SSH connectionfrom the host with databaseto the host with the backup catalog. This information will be used by therestore_command
to copy WAL segments from the archive to thePostgres Propg_wal
directory.
To solve this problem, you can useRemote WAL Archive Options.
For example, to restore latest backup on remote system using remote mode through SSH connection to userpostgres
on host with address192.168.0.2
via port2302
and userbackup
on backup catalog host with address192.168.0.3
via port2303
, run:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302 --archive-host=192.168.0.3 --archive-port=2303 --archive-user=backup
Provided arguments will be used to construct therestore_command
:
restore_command = '"install_dir
/pg_probackup" archive-get -B "backup_dir
" --instance=instance_name
--wal-file-path=%p --wal-file-name=%f --remote-host=192.168.0.3 --remote-port=2303 --remote-user=backup'
Alternatively, you can use the--restore-command
option to provide the entirerestore_command
:
pg_probackup restore -Bbackup_dir
--instance=instance_name
--remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302 --restore-command='"install_dir
/pg_probackup" archive-get -B "backup_dir
" --instance=instance_name
--wal-file-path=%p --wal-file-name=%f --remote-host=192.168.0.3 --remote-port=2303 --remote-user=backup'
Note
The remote mode is currently unavailable for Windows systems.
Runningpg_probackup on Parallel Threads#
backup,restore,merge,delete,catchup,checkdb, andvalidate processes can be executed on several parallel threads. This can significantly speed uppg_probackup operation given enough resources (CPU cores, disk, and network bandwidth).
Parallel execution is controlled by the-j/--threads
command-line option. For example, to create a backup using four parallel threads, run:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL -j 4
Note
Parallel restore applies only to copying data from the backup catalog to the data directory of the cluster. WhenPostgres Pro server is started, WAL records need to be replayed, and this cannot be done in parallel.
Important
A technique is implemented that prevents repeatable copying of one file whenpg_probackup runs on multiple threads. With this technique, however, when disks are slow or the system is overloaded, parallel copying might fail. To handle this situation, resolve issues with your system resources.
Configuringpg_probackup#
Once the backup catalog is initialized and a new backup instance is added, you can use thepg_probackup.conf
configuration file located in the
directory to fine-tunepg_probackup configuration.backup_dir
/backups/instance_name
For example,backup andcheckdb commands use a regularPostgres Pro connection. To avoid specifyingconnection options each time on the command line, you can set them in thepg_probackup.conf
configuration file using theset-config command.
Note
It isnot recommended to editpg_probackup.conf
manually.
Initially,pg_probackup.conf
contains the following settings:
PGDATA
— the path to the data directory of the cluster to back up.system-identifier
— the unique identifier of thePostgres Pro instance.
Additionally, you can defineremote,retention,logging, andcompression settings using theset-config
command:
pg_probackup set-config -Bbackup_dir
--instance=instance_name
[--external-dirs=external_directory_path
] [remote_options
] [connection_options
] [retention_options
] [logging_options
]
To view the current settings, run the following command:
pg_probackup show-config -Bbackup_dir
--instance=instance_name
You can override the settings defined inpg_probackup.conf
when runningpg_probackupcommands via the corresponding environment variables and/or command line options.
Specifying Connection Settings#
If you define connection settings in thepg_probackup.conf
configuration file, you can omit connection options in all the subsequentpg_probackup commands. However, if the corresponding environment variables are set, they get higher priority. The options provided on the command line overwrite both environment variables and configuration file settings.
If nothing is given, the default values are taken. By defaultpg_probackup tries to use local connection via Unix domain socket (localhost
on Windows) and tries to get the database name and the user name from thePGUSER
environment variable or the current OS user name.
Managing the Backup Catalog#
Withpg_probackup, you can manage backups from the command line:
Viewing Backup Information#
To view the list of existing backups for every instance, run the command:
pg_probackup show -Bbackup_dir
pg_probackup displays the list of all the available backups. For example:
BACKUP INSTANCE 'node'================================================================================================================================================== Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status================================================================================================================================================== node 17 SBOL94 2024-04-09 18:19:56.603355+03 FULL ARCHIVE 1/0 6s 377MB 16MB lz4 1.46 0/41000028 0/420000C0 OK node 17 SBOL8S 2024-04-09 18:19:43.707720+03 DELTA STREAM 1/1 3s 114MB 64MB lz4 1.42 0/3C003020 0/3E8D4930 OK node 17 SBOL8G 2024-04-09 18:19:32.594670+03 PTRACK STREAM 1/1 4s 30MB 16MB zlib 2.23 0/31000028 0/310029E0 OK node 17 SBOL83 2024-04-09 18:19:22.269595+03 PAGE STREAM 1/1 7s 46MB 32MB pglz 1.44 0/29000028 0/2A0000F8 OK node 17 SBOL7P 2024-04-09 18:19:06.557301+03 FULL STREAM 1/0 6s 144MB 16MB zstd 2.47 0/22000028 0/220001C8 OK
For each backup, the following information is provided:
Instance
— the instance name.Version
—Postgres Pro major version.ID
— the backup identifier.Recovery time
— the earliest moment for which you can restore the state of the database cluster.Mode
— the method used to take this backup. Possible values:FULL
,PAGE
,DELTA
,PTRACK
.WAL Mode
— WAL delivery mode. Possible values:STREAM
andARCHIVE
.TLI
— timeline identifiers of the current backup and its parent.Time
— the time it took to perform the backup.Data
— the size of the data files in this backup. This value does not include the size of WAL files. For STREAM backups, the total size of the backup can be calculated asData
+WAL
.WAL
— the uncompressed size of WAL files that need to be applied during recovery for the backup to reach a consistent state.compress-alg
— compression algorithm used during backup. Possible values:zlib
,pglz
,lz4
,zstd
,none
.Zratio
— compression ratio calculated as“uncompressed-bytes” /“data-bytes”.Start LSN
— WAL log sequence number corresponding to the start of the backup process. REDO point forPostgres Pro recovery process to start from.Stop LSN
— WAL log sequence number corresponding to the end of the backup process. Consistency point forPostgres Pro recovery process.Status
— backup status. Possible values:OK
— the backup is complete and valid.DONE
— the backup is complete, but was not validated.RUNNING
— the backup is in progress.MERGING
— the backup is being merged.MERGED
— the backup data files were successfully merged, but its metadata is in the process of being updated. Only full backups can have this status.DELETING
— the backup files are being deleted.CORRUPT
— some of the backup files are corrupt.ERROR
— the backup was aborted because of an unexpected error.ORPHAN
— the backup is invalid because one of its parent backups is corrupt or missing.HIDDEN_FOR_TEST
— a test script marked the backup as nonexistent. (pg_probackup never sets this status by itself.)
You can restore the cluster from the backup only if the backup status isOK
orDONE
.
To get more detailed information about the backup, run theshow
command with the backup ID:
pg_probackup show -Bbackup_dir
--instance=instance_name
-ibackup_id
The sample output is as follows:
#Configurationbackup-mode = FULLstream = falsecompress-alg = lz4compress-level = 1from-replica = false#Compatibilityblock-size = 8192xlog-block-size = 8192checksum-version = 1program-version = 2.7.3server-version = 17#Result backup infotimelineid = 1start-lsn = 0/41000028stop-lsn = 0/420000C0start-time = '2024-04-09 18:19:52+03'end-time = '2024-04-09 18:19:58+03'end-validation-time = '2024-04-09 18:19:59+03'recovery-xid = 757recovery-time = '2024-04-09 18:19:56.603355+03'data-bytes = 395651278wal-bytes = 16777216uncompressed-bytes = 578552566pgdata-bytes = 578552248status = OKprimary_conninfo = 'user=backup channel_binding=prefer host=localhost port=5432 sslmode=prefer sslcompression=0 sslcertmode=allow sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres gssdelegation=0 target_session_attrs=any load_balance_hosts=disable'content-crc = 3862224379
Detailed output has additional attributes:
compress-alg
— compression algorithm used during backup. Possible values:zlib
,pglz
,lz4
,zstd
,none
.compress-level
— compression level used during backup.from-replica
— was this backup taken on a standby? Possible values:1
,0
.block-size
— theblock_size setting ofPostgres Pro cluster at the backup start.checksum-version
— aredata_checksums enabled in the backed upPostgres Pro cluster? Possible values:1
,0
.program-version
— full version ofpg_probackup binary used to create the backup.start-time
— the backup start time.end-time
— the backup end time.end-validation-time
— the backup validation end time.expire-time
— the point in time when a pinned backup can be removed in accordance with retention policy. This attribute is only available for pinned backups.uncompressed-bytes
— the size of data files before adding page headers and applying compression. You can evaluate the effectiveness of compression by comparinguncompressed-bytes
todata-bytes
if compression if used.pgdata-bytes
— the size ofPostgres Pro cluster data files at the time of backup. You can evaluate the effectiveness of an incremental backup by comparingpgdata-bytes
touncompressed-bytes
.recovery-xid
— transaction ID at the backup end time.parent-backup-id
— ID of the parent backup. Available only for incremental backups.primary_conninfo
—libpq connection parameters used to connect to thePostgres Pro cluster to take this backup. The password is not included.note
— text note attached to backup.content-crc
— CRC32 checksum ofbackup_content.control
file. It is used to detect corruption of backup metainformation.
Viewing WAL Archive Information#
To view the information about WAL archive for every instance, run the command:
pg_probackup show -Bbackup_dir
[--instance=instance_name
] --archive
pg_probackup displays the list of all the available WAL files grouped by timelines. For example:
INFO: checking WAL file name "00000001000000000000001B"INFO: checking WAL file name "00000001000000000000001C"INFO: checking WAL file name "00000001000000000000001D"INFO: checking WAL file name "00000001000000000000001E"INFO: checking WAL file name "00000001000000000000001F"INFO: checking WAL file name "000000010000000000000020"INFO: checking WAL file name "000000010000000000000021"INFO: checking WAL file name "000000010000000000000022"INFO: checking WAL file name "000000010000000000000022.00000028.backup"INFO: checking WAL file name "000000010000000000000023"INFO: checking WAL file name "000000010000000000000024"INFO: checking WAL file name "000000010000000000000025"INFO: checking WAL file name "000000010000000000000026"INFO: checking WAL file name "000000010000000000000027"INFO: checking WAL file name "000000010000000000000028"INFO: checking WAL file name "000000010000000000000029"INFO: checking WAL file name "000000010000000000000029.00000028.backup"INFO: checking WAL file name "00000001000000000000002A"INFO: checking WAL file name "00000001000000000000002B"INFO: checking WAL file name "00000001000000000000002C"INFO: checking WAL file name "00000001000000000000002D"INFO: checking WAL file name "00000001000000000000002E"INFO: checking WAL file name "00000001000000000000002F"INFO: checking WAL file name "000000010000000000000030"INFO: checking WAL file name "000000010000000000000031"INFO: checking WAL file name "000000010000000000000031.00000028.backup"INFO: checking WAL file name "000000010000000000000032"INFO: checking WAL file name "000000010000000000000033"INFO: checking WAL file name "000000010000000000000034"INFO: checking WAL file name "000000010000000000000035"INFO: checking WAL file name "000000010000000000000036"INFO: checking WAL file name "000000010000000000000037"INFO: checking WAL file name "000000010000000000000038"INFO: checking WAL file name "000000010000000000000039"INFO: checking WAL file name "00000001000000000000003A"INFO: checking WAL file name "00000001000000000000003B"INFO: checking WAL file name "00000001000000000000003C"INFO: checking WAL file name "00000001000000000000003C.00003020.backup"INFO: checking WAL file name "00000001000000000000003D"INFO: checking WAL file name "00000001000000000000003E"INFO: checking WAL file name "00000001000000000000003F"INFO: checking WAL file name "000000010000000000000040"INFO: checking WAL file name "000000010000000000000041"INFO: checking WAL file name "000000010000000000000041.00000028.backup"INFO: checking WAL file name "000000010000000000000042"ARCHIVE INSTANCE 'node'================================================================================================================================ TLI Parent TLI Switchpoint Min Segno Max Segno N segments Size Zratio N backups Status ================================================================================================================================ 1 0 0/0 00000001000000000000001B 000000010000000000000042 40 640MB 1.00 5 OK
For each timeline, the following information is provided:
TLI
— timeline identifier.Parent TLI
— identifier of the timeline from which this timeline branched off.Switchpoint
— LSN of the moment when the timeline branched off from its parent timeline.Min Segno
— the first WAL segment belonging to the timeline.Max Segno
— the last WAL segment belonging to the timeline.N segments
— number of WAL segments belonging to the timeline.Size
— the size that files take on disk.Zalg
— compression algorithm used during backup. Possible values:zlib
,pglz
,lz4
,zstd
,none
.Zratio
— compression ratio calculated asN segments
*wal_segment_size
*wal_block_size
/Size
.N backups
— number of backups belonging to the timeline. To get the details about backups, use theJSON format.Status
— status of the WAL archive for this timeline. Possible values:OK
— all WAL segments betweenMin Segno
andMax Segno
are present.DEGRADED
— some WAL segments betweenMin Segno
andMax Segno
are missing. To find out which files are lost, view this report in theJSON format. This status may appear if several WAL files (in the middle of the sequence) were deleted by thedelete command with the--delete-wal
option according to the retention policy. This status does not affect the restore correctness, but it can be impossible to perform PITR of the cluster to some recovery targets.
Configuring Retention Policy#
Withpg_probackup, you can configure retention policy to remove redundant backups, clean up unneeded WAL files, as well as pin specific backups to ensure they are kept for the specified time, as explained in the sections below. All these actions can be combined together in any way.
Removing Redundant Backups#
By default, all backup copies created withpg_probackup are stored in the specified backup catalog. To save disk space, you can configure retention policy to remove redundant backup copies.
To configure retention policy, set one or more of the following variables in thepg_probackup.conf
file viaset-config:
--retention-redundancy=redundancy
Specifiesthe number of full backup copies to keep in the backup catalog.
--retention-window=window
Defines the earliest point in time for whichpg_probackup can complete the recovery. This option is set inthe number of days from the current moment. For example, ifretention-window=7
,pg_probackup must keep at least one backup copy that is older than seven days, with all the corresponding WAL files, and all the backups that follow.
If both--retention-redundancy
and--retention-window
options are set, both these conditions have to be taken into account when purging the backup catalog. For example, if you set--retention-redundancy=2
and--retention-window=7
,pg_probackup has to keep two full backup copies, as well as all the backups required to ensure recoverability for the last seven days:
pg_probackup set-config -Bbackup_dir
--instance=instance_name
--retention-redundancy=2 --retention-window=7
It is recommended to always keep at least two last parent full backups to avoid errors when creating incremental backups.
To clean up the backup catalog in accordance with retention policy, you have to run thedelete command withretention flags, as shown below, or use thebackup command with these flags to process the outdated backup copies right when the new backup is created.
For example, to remove all backup copies that no longer satisfy the defined retention policy, run the following command with the--delete-expired
flag:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-expired
If you would like to also remove the WAL files that are no longer required for any of the backups, you should also specify the--delete-wal
flag:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-expired --delete-wal
You can also set or override the current retention policy by specifying--retention-redundancy
and--retention-window
options directly when runningdelete
orbackup
commands:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-expired --retention-window=7 --retention-redundancy=2
Since incremental backups require that their parent full backup and all the preceding incremental backups are available, if any of such backups expire, they still cannot be removed while at least one incremental backup in this chain satisfies the retention policy. To avoid keeping expired backups that are still required to restore an active incremental one, you can merge them with this backup using the--merge-expired
flag when runningbackup ordelete commands.
Suppose you have backed up thenode
instance in thebackup_dir
directory, with the--retention-window
option set to6
and--retention-redundancy
option set to2
, and you have the following backups available on August 01, 2024:
BACKUP INSTANCE 'node'=========================================================================================================================================== Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status =========================================================================================================================================== node 17 SHJ1N9 2024-08-01 09:50:00+03 FULL ARCHIVE 1/0 5s 13MB 16MB zstd 2,81 0/1D000028 0/1E0000C0 OK node 17 SHJ1N8 2024-08-01 09:49:59+03 DELTA ARCHIVE 1/1 5s 6432kB 16MB zstd 1,06 0/1A000028 0/1B0000C0 OK node 17 SHH6Z8 2024-07-31 09:49:59+03 PAGE ARCHIVE 1/1 5s 6431kB 16MB zstd 1,06 0/17000028 0/180000C0 OK node 17 SHFCB6 2024-07-30 09:49:57+03 FULL ARCHIVE 1/0 5s 12MB 16MB zstd 2,83 0/14000028 0/150000C0 OK node 17 SH9SB5 2024-07-27 09:49:56+03 PAGE ARCHIVE 1/1 5s 6432kB 16MB zstd 1,06 0/11000028 0/120000C0 OK ----------------------------------------------------------retention window----------------------------------------------------------- node 17 SH62Z5 2024-07-25 09:49:56+03 DELTA ARCHIVE 1/1 5s 6431kB 16MB zstd 1,06 0/E000028 0/F0000C0 OK node 17 SH48B3 2024-07-24 09:49:54+03 FULL ARCHIVE 1/0 5s 12MB 16MB zstd 2,86 0/B000028 0/C0000C0 OK node 17 SGWTN3 2024-07-20 09:49:54+03 PAGE ARCHIVE 1/1 5s 6432kB 16MB zstd 1,06 0/8000028 0/90000C0 OK node 17 SGUYZ2 2024-07-19 09:49:53+03 DELTA ARCHIVE 1/1 5s 6442kB 16MB zstd 1,07 0/5000028 0/60000C0 OK node 17 SGT4B1 2024-07-18 09:49:52+03 FULL ARCHIVE 1/0 5s 11MB 16MB zstd 2,89 0/2000028 0/3003A28 OK
If you run thedelete command with the--delete-expired
flag, the backups with IDsSGT4B1
,SGUYZ2
, andSGWTN3
will be removed as they are expired both according to the retention window and due to redundancy (the required set of full backups has already been retained).SGUYZ2
andSGWTN3
will also be removed since the base full backup is expired.
Running thedelete command with the--merge-expired
flag will merge backupsSH48B3
andSH62Z5
withSH9SB5
. The merge will occur withSH9SB5
as it is the first non-expired delta backup, which can be merged with expired delta backupsSH62Z5
and expired full backupSH48B3
.
pg_probackup delete -Bbackup_dir
--instance=node
--delete-expired --merge-expiredpg_probackup show -Bbackup_dir
BACKUP INSTANCE 'node'=========================================================================================================================================== Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status=========================================================================================================================================== node 17 SHJ1N9 2024-08-01 09:50:00+03 FULL ARCHIVE 1/0 5s 13MB 16MB zstd 2,81 0/1D000028 0/1E0000C0 OK node 17 SHJ1N8 2024-08-01 09:49:59+03 DELTA ARCHIVE 1/1 5s 6432kB 16MB zstd 1,06 0/1A000028 0/1B0000C0 OK node 17 SHH6Z8 2024-07-31 09:49:59+03 PAGE ARCHIVE 1/1 5s 6431kB 16MB zstd 1,06 0/17000028 0/180000C0 OK node 17 SHFCB6 2024-07-30 09:49:57+03 FULL ARCHIVE 1/0 5s 12MB 16MB zstd 2,83 0/14000028 0/150000C0 OK node 17 SH9SB5 2024-07-27 09:49:56+03 FULL ARCHIVE 1/0 1s 12MB 16MB zstd 2,84 0/11000028 0/120000C0 OK
TheTime
field for the merged backup displays the time required for the merge.
Pinning Backups#
If you need to keep certain backups longer than the established retention policy allows, you can pin them for arbitrary time. For example:
pg_probackup set-backup -Bbackup_dir
--instance=instance_name
-ibackup_id
--ttl=30d
This command sets the expiration time of the specified backup to 30 days starting from the time indicated in itsrecovery-time
attribute.
You can also explicitly set the expiration time for a backup using the--expire-time
option. For example:
pg_probackup set-backup -Bbackup_dir
--instance=instance_name
-ibackup_id
--expire-time="2027-04-09 18:21:32+00"
Alternatively, you can use the--ttl
and--expire-time
options with thebackup command to pin the newly created backup:
pg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --ttl=30dpg_probackup backup -Bbackup_dir
--instance=instance_name
-b FULL --expire-time="2027-04-09 18:21:32+00"
To check if the backup is pinned, run theshow command:
pg_probackup show -Bbackup_dir
--instance=instance_name
-ibackup_id
If the backup is pinned, it has theexpire-time
attribute that displays its expiration time:
...recovery-time = '2024-04-09 18:21:32+00'expire-time = '2027-04-09 18:21:32+00'data-bytes = 22288792...
You can unpin the backup by setting the--ttl
option to zero:
pg_probackup set-backup -Bbackup_dir
--instance=instance_name
-ibackup_id
--ttl=0
Note
A pinned incremental backup implicitly pins all its parent backups. If you unpin such a backup later, its implicitly pinned parents will also be automatically unpinned.
Configuring WAL Archive Retention Policy#
Whencontinuous WAL archiving is enabled, archived WAL segments can take a lot of disk space. Even if you delete old backup copies from time to time, the--delete-wal
flag can purge only those WAL segments that do not apply to any of the remaining backups in the backup catalog. However, if point-in-time recovery is critical only for the most recent backups, you can configure WAL archive retention policy to keep WAL archive of limited depth and win back some more disk space.
To configure WAL archive retention policy, you have to run theset-config command with the--wal-depth
option that specifies the number of backups that can be used for PITR. This setting applies to all the timelines, so you should be able to perform PITR for the same number of backups on each timeline, if available.Pinned backups are not included into this count: if one of the latest backups is pinned,pg_probackup ensures that PITR is possible for one extra backup.
To remove WAL segments that do not satisfy the defined WAL archive retention policy, you simply have to run thedelete orbackup command with the--delete-wal
flag. For archive backups, WAL segments betweenStart LSN
andStop LSN
are always kept intact, so such backups remain valid regardless of the--wal-depth
setting and can still be restored, if required.
You can also use the--wal-depth
option with thedelete andbackup commands to override the previously defined WAL archive retention policy and purge old WAL segments on the fly.
Suppose you have backed up thenode
instance in thebackup_dir
directory and configuredcontinuous WAL archiving:
pg_probackup show -Bbackup_dir
--instance=node
================================================================================================================================================== Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zalg Zratio Start LSN Stop LSN Status ================================================================================================================================================== node 17 SBOLDA 2024-04-09 18:22:23.147138+03 DELTA STREAM 1/1 1s 1165kB 16MB zstd 1.09 0/6F000028 0/6F000190 OK node 17 SBOLCY 2024-04-09 18:22:16.079841+03 FULL STREAM 1/0 10s 278MB 16MB zstd 2.46 0/6D000028 0/6D000190 OK node 17 SBOLCW 2024-04-09 18:22:10.154022+03 DELTA STREAM 1/1 2s 1364kB 16MB zstd 1.01 0/6B000028 0/6B000190 OK node 17 SBOLCS 2024-04-09 18:22:07.521646+03 DELTA STREAM 1/1 4s 78MB 16MB zstd 2.41 0/69000028 0/69000190 OK node 17 SBOLCC 2024-04-09 18:21:55.830115+03 FULL STREAM 1/0 15s 278MB 96MB zstd 2.46 0/600060C8 0/64FE6640 OK node 17 SBOLBW 2024-04-09 18:21:38.399702+03 FULL STREAM 1/0 12s 278MB 96MB zstd 2.46 0/54001830 0/589E5908 OK
You can check the state of the WAL archive by running theshow command with the--archive
flag:
pg_probackup show -Bbackup_dir
--instance=node --archive
INFO: checking WAL file name "000000010000000000000052"INFO: checking WAL file name "000000010000000000000053"INFO: checking WAL file name "000000010000000000000054"INFO: checking WAL file name "000000010000000000000054.00001830.backup"INFO: checking WAL file name "000000010000000000000055"INFO: checking WAL file name "000000010000000000000056"INFO: checking WAL file name "000000010000000000000057"INFO: checking WAL file name "000000010000000000000058"INFO: checking WAL file name "000000010000000000000059"INFO: checking WAL file name "00000001000000000000005A"INFO: checking WAL file name "00000001000000000000005B"INFO: checking WAL file name "00000001000000000000005C"INFO: checking WAL file name "00000001000000000000005D"INFO: checking WAL file name "00000001000000000000005E"INFO: checking WAL file name "00000001000000000000005F"INFO: checking WAL file name "000000010000000000000060"INFO: checking WAL file name "000000010000000000000060.000060C8.backup"INFO: checking WAL file name "000000010000000000000061"INFO: checking WAL file name "000000010000000000000062"INFO: checking WAL file name "000000010000000000000063"INFO: checking WAL file name "000000010000000000000064"INFO: checking WAL file name "000000010000000000000065"INFO: checking WAL file name "000000010000000000000066"INFO: checking WAL file name "000000010000000000000067"INFO: checking WAL file name "000000010000000000000068"INFO: checking WAL file name "000000010000000000000069"INFO: checking WAL file name "000000010000000000000069.00000028.backup"INFO: checking WAL file name "00000001000000000000006A"INFO: checking WAL file name "00000001000000000000006B"INFO: checking WAL file name "00000001000000000000006B.00000028.backup"INFO: checking WAL file name "00000001000000000000006C"INFO: checking WAL file name "00000001000000000000006D"INFO: checking WAL file name "00000001000000000000006D.00000028.backup"INFO: checking WAL file name "00000001000000000000006E"INFO: checking WAL file name "00000001000000000000006F"INFO: checking WAL file name "00000001000000000000006F.00000028.backup"ARCHIVE INSTANCE 'node'================================================================================================================================ TLI Parent TLI Switchpoint Min Segno Max Segno N segments Size Zratio N backups Status ================================================================================================================================ 1 0 0/0 000000010000000000000052 00000001000000000000006F 30 480MB 1.00 6 OK
WAL purge without--wal-depth
cannot achieve much, only one segment is removed:
pg_probackup delete -Bbackup_dir
--instance=node --delete-wal
INFO: checking WAL file name "000000010000000000000054"INFO: checking WAL file name "000000010000000000000054.00001830.backup"INFO: checking WAL file name "000000010000000000000055"INFO: checking WAL file name "000000010000000000000056"INFO: checking WAL file name "000000010000000000000057"INFO: checking WAL file name "000000010000000000000058"INFO: checking WAL file name "000000010000000000000059"INFO: checking WAL file name "00000001000000000000005A"INFO: checking WAL file name "00000001000000000000005B"INFO: checking WAL file name "00000001000000000000005C"INFO: checking WAL file name "00000001000000000000005D"INFO: checking WAL file name "00000001000000000000005E"INFO: checking WAL file name "00000001000000000000005F"INFO: checking WAL file name "000000010000000000000060"INFO: checking WAL file name "000000010000000000000060.000060C8.backup"INFO: checking WAL file name "000000010000000000000061"INFO: checking WAL file name "000000010000000000000062"INFO: checking WAL file name "000000010000000000000063"INFO: checking WAL file name "000000010000000000000064"INFO: checking WAL file name "000000010000000000000065"INFO: checking WAL file name "000000010000000000000066"INFO: checking WAL file name "000000010000000000000067"INFO: checking WAL file name "000000010000000000000068"INFO: checking WAL file name "000000010000000000000069"INFO: checking WAL file name "000000010000000000000069.00000028.backup"INFO: checking WAL file name "00000001000000000000006A"INFO: checking WAL file name "00000001000000000000006B"INFO: checking WAL file name "00000001000000000000006B.00000028.backup"INFO: checking WAL file name "00000001000000000000006C"INFO: checking WAL file name "00000001000000000000006D"INFO: checking WAL file name "00000001000000000000006D.00000028.backup"INFO: checking WAL file name "00000001000000000000006E"INFO: checking WAL file name "00000001000000000000006F"INFO: checking WAL file name "00000001000000000000006F.00000028.backup"ARCHIVE INSTANCE 'node'================================================================================================================================ TLI Parent TLI Switchpoint Min Segno Max Segno N segments Size Zratio N backups Status ================================================================================================================================ 1 0 0/0 000000010000000000000054 00000001000000000000006F 28 448MB 1.00 6 OK
If you would like, for example, to keep only those WAL segments that can be applied to the latest valid backup, set the--wal-depth
option to 1:
pg_probackup delete -Bbackup_dir
--instance=node --delete-wal --wal-depth=1
INFO: checking WAL file name "00000001000000000000006F"INFO: checking WAL file name "00000001000000000000006F.00000028.backup"ARCHIVE INSTANCE 'node'=============================================================================================================================== TLI Parent TLI Switchpoint Min Segno Max Segno N segments Size Zratio N backups Status =============================================================================================================================== 1 0 0/0 00000001000000000000006F 00000001000000000000006F 1 16MB 1.00 6 OK
Alternatively, you can use the--wal-depth
option with thebackup command:
pg_probackup backup -Bbackup_dir
--instance=node -b DELTA --wal-depth=1 --delete-wal
INFO: checking WAL file name "000000010000000000000071"INFO: checking WAL file name "000000010000000000000071.00000028.backup"ARCHIVE INSTANCE 'node'=============================================================================================================================== TLI Parent TLI Switchpoint Min Segno Max Segno N segments Size Zratio N backups Status =============================================================================================================================== 1 0 0/0 000000010000000000000071 000000010000000000000071 1 16MB 1.00 7 OK
Merging Backups#
As you take more and more incremental backups, the total size of the backup catalog can substantially grow. To save disk space, you can merge incremental backups to their parent full backup by running themerge
command, specifying the backup ID of the most recent incremental backup you would like to merge:
pg_probackup merge -Bbackup_dir
--instance=instance_name
-ibackup_id
This command merges backups that belong to a common incremental backup chain. If you specify a full backup, it will be merged with its first incremental backup. If you specify an incremental backup, it will be merged to its parent full backup, together with all incremental backups between them. Once the merge is complete, the full backup takes in all the merged data, and the incremental backups are removed as redundant. Thus, the merge operation is virtually equivalent to retaking a full backup and removing all the outdated backups, but it allows you to save much time, especially for large data volumes, as well as I/O and network traffic if you are usingpg_probackup in theremote mode.
Before the merge,pg_probackup validates all the affected backups to ensure that they are valid. You can check the current backup status by running theshow command with the backup ID:
pg_probackup show -Bbackup_dir
--instance=instance_name
-ibackup_id
If the merge is still in progress, the backup status is displayed asMERGING
. For full backups, it can also be shown asMERGED
while the metadata is being updated at the final stage of the merge. The merge is idempotent, so you can restart the merge if it was interrupted.
Deleting Backups#
To delete a backup that is no longer required, run the following command:
pg_probackup delete -Bbackup_dir
--instance=instance_name
-ibackup_id
This command will delete the backup with the specifiedbackup_id
, together with all the incremental backups that descend frombackup_id
, if any. This way you can delete some recent incremental backups, retaining the underlying full backup and some of the incremental backups that follow it.
To delete obsolete WAL files that are not necessary to restore any of the remaining backups, use the--delete-wal
flag:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-wal
To delete backups that are expired according to the current retention policy, use the--delete-expired
flag:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-expired
Expired backups cannot be removed while at least one incremental backup that satisfies the retention policy is based on them. If you would like to minimize the number of backups still required to keep incremental backups valid, specify the--merge-expired
flag when running this command:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--delete-expired --merge-expired
In this case,pg_probackup searches for the oldest incremental backup that satisfies the retention policy and merges this backup with the underlying full and incremental backups that have already expired, thus making it a full backup. Once the merge is complete, the remaining expired backups are deleted.
Before merging or deleting backups, you can run thedelete
command with the--dry-run
flag, which displays the status of all the available backups according to the current retention policy, without performing any irreversible actions.
To delete all backups with specific status, use the--status
:
pg_probackup delete -Bbackup_dir
--instance=instance_name
--status=ERROR
Deleting backups by status ignores established retention policies.
Cloning and SynchronizingPostgres Pro Instance#
pg_probackup can create a copy of aPostgres Pro instance directly, without using the backup catalog. To do this, you can run thecatchup command. It can be useful in the following cases:
To add a new standby server.
Usually,pg_basebackup is used to create a copy of aPostgres Pro instance. If the data directory of the destination instance is empty, the
catchup
command works similarly, but it can be faster if run in parallel mode.To have a fallen-behind standby server“catch up” with the primary.
Under write-intensive load, replicas may fail to replay WAL fast enough to keep up with the primary and hence may lag behind. A usual solution to create a new replica and switch to it requires a lot of extra space and data transfer. The
catchup
command allows you to update an existing replica much faster by bringing differences from the primary.
catchup
is different from otherpg_probackup operations:
The backup catalog is not required.
STREAM WAL delivery mode is only supported.
Copying external directories is not supported.
DDL commandsCREATE TABLESPACE/DROP TABLESPACE cannot be run simultaneously with
catchup
.catchup
takes configuration files, such aspostgresql.conf
,postgresql.auto.conf
, orpg_hba.conf
, from the source server and overwrites them on the target server. The--exclude-path
option allows you to keep the configuration files intact.
To prepare for cloning/synchronizing aPostgres Pro instance, set up the source server as follows:
Configure the database cluster for the instance to copy.
To copy from a remote server,configure the remote mode.
To use the PTRACK catchup mode,set up PTRACK backups.
Before cloning/synchronizing aPostgres Pro instance, ensure that the source server is running and accepting connections. To clone/sync aPostgres Pro instance, on the server with the destination instance, you can run thecatchup command as follows:
pg_probackup catchup -bcatchup_mode
--source-pgdata=path_to_pgdata_on_remote_server
--destination-pgdata=path_to_local_dir
--stream [connection_options
] [remote_options
]
Wherecatchup_mode
can take one of the following values:
FULL
— creates a full copy of thePostgres Pro instance. The data directory of the destination instance must be empty for this mode.DELTA
— reads all data files in the data directory and creates an incremental copy for pages that have changed since the destination instance was shut down.PTRACK
— tracking page changes on the fly, only reads and copies pages that have changed since the point of divergence of the source and destination instances.Warning
PTRACK catchup mode requiresPTRACK not earlier than 2.0 and hence,Postgres Pro not earlier than 11.
By specifying the--stream
option, you can setSTREAM WAL delivery mode of copying, which will include all the necessary WAL files by streaming them from the server via replication protocol.
You can useconnection_options to specify the connection to the source database cluster. If it is located on a different server, also specifyremote_options.
If the source database cluster contains tablespaces that must be located in a different directory, additionally specify the--tablespace-mapping
option:
pg_probackup catchup -bcatchup_mode
--source-pgdata=path_to_pgdata_on_remote_server
--destination-pgdata=path_to_local_dir
--stream --tablespace-mapping=OLDDIR
=NEWDIR
To run thecatchup
command on parallel threads, specify the number of threads with the--threads
option:
pg_probackup catchup -bcatchup_mode
--source-pgdata=path_to_pgdata_on_remote_server
--destination-pgdata=path_to_local_dir
--stream --threads=num_threads
Before cloning/synchronising aPostgres Pro instance, you can run thecatchup
command with the--dry-run
flag to estimate the size of data files to be transferred, but make no changes on disk:
pg_probackup catchup -bcatchup_mode
--source-pgdata=path_to_pgdata_on_remote_server
--destination-pgdata=path_to_local_dir
--stream --dry-run
For example, assume that a remote standby server with thePostgres Pro instance having/replica-pgdata
data directory has fallen behind. To sync this instance with the one in/master-pgdata
data directory, you can run thecatchup
command in thePTRACK
mode on four parallel threads as follows:
pg_probackup catchup --source-pgdata=/master-pgdata --destination-pgdata=/replica-pgdata -p 5432 -d postgres -U remote-postgres-user --stream --backup-mode=PTRACK --remote-host=remote-hostname --remote-user=remote-unix-username -j 4 --exclude-path=postgresql.conf --exclude-path=postgresql.auto.conf --exclude-path=pg_hba.conf --exclude-path=pg_ident.conf
Note that in this example, the configuration files will not be overwritten during synchronization.
Another example shows how you can add a new remote standby server with thePostgres Pro data directory/replica-pgdata
by running thecatchup
command in theFULL
mode on four parallel threads:
pg_probackup catchup --source-pgdata=/master-pgdata --destination-pgdata=/replica-pgdata -p 5432 -d postgres -U remote-postgres-user --stream --backup-mode=FULL --remote-host=remote-hostname --remote-user=remote-unix-username -j 4
Command-Line Reference#
Commands#
This section describespg_probackup commands. Optional parameters are enclosed in square brackets. For detailed parameter descriptions, see the sectionOptions.
version#
pg_probackup version [--format=json
]
Printspg_probackup version and edition, as well asPostgres Pro version and edition.
If--format=
is specified, the output is printed in the JSON format. This may be needed for native integration with JSON-based applications, such as PPEM. Example of a JSON output:json
pg_probackup version --format=json{ "pg_probackup": { "version": "2.8.2", "edition": "community" }, "database": { "type": "Postgres Pro Standard", "version": "16.3.1" }, "compressions": [zlib, pglz, lz4, zstd]}
help#
pg_probackup help [command
]
Displays the synopsis ofpg_probackup commands. If one of thepg_probackup commands is specified, shows detailed information about the options that can be used with this command.
init#
pg_probackup init -Bbackup_dir
[--skip-if-exists] [--help][logging_options
]
Initializes the backup catalog inbackup_dir
that will store backup copies, WAL archive, and meta information for the backed up database clusters. If the specifiedbackup_dir
already exists, it must be empty. Otherwise,pg_probackup displays a corresponding error message. You can ignore this error by specifying the--skip-if-exists
option. Although the backup will not be initialized, the application will return 0 code.
For details, see the sectionInitializing the Backup Catalog.
add-instance#
pg_probackup add-instance -Bbackup_dir
-Ddata_dir
--instance=instance_name
[--skip-if-exists] [--help] [logging_options
]
Initializes a new backup instance inside the backup catalogbackup_dir
and generates thepg_probackup.conf
configuration file that controlspg_probackup settings for the cluster with the specifieddata_dir
data directory. If the catalog was already initialized, you can ignore the error by specifying--skip-if-exists
.
For details, see the sectionAdding a New Backup Instance.
del-instance#
pg_probackup del-instance -Bbackup_dir
--instance=instance_name
[--help][logging_options
]
Deletes all backups and WAL files associated with the specified instance.
set-config#
pg_probackup set-config -Bbackup_dir
--instance=instance_name
[--help] [--pgdata=pgdata-path
][--retention-redundancy=redundancy
][--retention-window=window
][--wal-depth=wal_depth
][--compress-algorithm=compression_algorithm
] [--compress-level=compression_level
][-ddbname
] [-hhost
] [-pport
] [-Uusername
][--archive-timeout=timeout
] [--external-dirs=external_directory_path
][--restore-command=cmdline
][remote_options
] [remote_wal_archive_options
] [logging_options
]
Adds the specified connection, compression, retention, logging, and external directory settings into thepg_probackup.conf
configuration file, or modifies the previously defined values.
For all available settings, see theOptions section.
It isnot recommended to editpg_probackup.conf
manually.
set-backup#
pg_probackup set-backup -Bbackup_dir
--instance=instance_name
-ibackup_id
{--ttl=ttl
| --expire-time=time
}[--note=backup_note
] [--help] [logging_options
]
Sets the provided backup-specific settings into thebackup.control
configuration file, or modifies the previously defined values.
--note=
backup_note
Sets the text note for backup copy. If
backup_note
contains newline characters, then only the substring before the first newline character will be saved. The maximum size of a text note is 1 KB. The'none'
value removes the current note.
For all available pinning settings, see the sectionPinning Options.
show-config#
pg_probackup show-config -Bbackup_dir
--instanceinstance_name
[--format=plain|json][--no-scale-units] [logging_options
]
Displays all the currentpg_probackup configuration settings, including those that are specified in the You can also specify the To editpg_probackup.conf
configuration file located in the
directory and those that were provided on a command line. You can specify thebackup_dir
/backups/instance_name
--format=json
option to get the result in theJSON format. By default, configuration settings are shown as plain text.--no-scale-units
option to display time and memory configuration settings in their base (unscaled) units. Otherwise, the values are scaled to larger units for optimal display. For example, ifarchive-timeout
is 300, then5min
is displayed, but ifarchive-timeout
is 301, then301s
is displayed. Also, if the--no-scale-units
option is specified, configuration settings are displayed without units and for the JSON format, numeric and boolean values are not enclosed in quotes. This facilitates parsing the output.pg_probackup.conf
, use theset-config command.
show#
pg_probackup show -Bbackup_dir
[--help] [--instance=instance_name
[-ibackup_id
| --archive]] [--format=plain|json] [--no-color] [--show-symlinks][logging_options
]
Shows the contents of the backup catalog. Ifinstance_name
andbackup_id
are specified, shows detailed information about this backup. If the--archive
option is specified, shows the contents of WAL archive of the backup catalog.
By default, the contents of the backup catalog is shown as plain text. You can specify the If the For details on usage, see the sectionsManaging the Backup Catalog andViewing WAL Archive Information.--format=json
option to get the result in theJSON format. If--no-color
flag is used, then the output is not colored.--show-symlinks
option is specified, the command also shows the links betweenmerged backups and the original full backups that incremental backups were merged to.
backup#
pg_probackup backup -Bbackup_dir
-bbackup_mode
--instance=instance_name
[--help] [-jnum_threads
] [--progress][--backup-threadsnum_threads
] [--validate-threadsnum_threads
][-C] [--stream [-S slot_name] [--temp-slot[=true|false|on|off]]] [--backup-pg-log][--no-validate] [--skip-block-validation][-w --no-password] [-W --password][--write-rate-limit=bitrate
][--archive-timeout=timeout
] [--external-dirs=external_directory_path
][--no-sync] [--note=backup_note
][connection_options
] [compression_options
] [remote_options
][retention_options
] [pinning_options
] [logging_options
]
Creates a backup copy of thePostgres Pro instance.
-b
mode
--backup-mode=
mode
Specifies the backup mode to use. Possible values are:
FULL
,DELTA
,PAGE
, andPTRACK
.--backup-threads
num_threads
Specifies the number of threads for copying files. Overrides the
j
/--threads
option for file copying.--validate-threads
num_threads
Specifies the number of threads for the backup validation. Overrides the
j
/--threads
option for the backup validation.-C
--smooth-checkpoint
Spreads out the checkpoint over a period of time. By default,pg_probackup tries to complete the checkpoint as soon as possible.
--stream
Makes aSTREAM backup, which includes all the necessary WAL files by streaming them from the database server via replication protocol.
--temp-slot[=
true
|false
|on
|off
]Creates atemporary physical replication slot for streaming WAL from the backed upPostgres Pro instance.
--temp-slot
is enabled by default. It ensures that all the required WAL segments remain available if WAL is rotated while the backup is in progress. This flag can only be used together with the--stream
flag. The default slot name ispg_probackup_slot
. To change it, use the--slot
/-S
option and explicitly specify--temp-slot
or--temp-slot=
.true
|on
-S
slot_name
--slot=
slot_name
Specifies the replication slot to connect to for WAL streaming. This option can only be used together with the
--stream
flag.--backup-pg-log
Includes the log directory into the backup. This directory usually contains log messages. By default, log directory is excluded.
-E
external_directory_path
--external-dirs=
external_directory_path
Includes the specified directory into the backup by recursively copying its contents into a separate subdirectory in the backup catalog. This option is useful to back up scripts, SQL dump files, and configuration files located outside of the data directory. If you would like to back up several external directories, separate their paths by a colon on Unix and a semicolon on Windows.
--write-rate-limit=
bitrate
Sets the rate of writing data to disk, in MBps or GBps. The default unit is MBps. For example:
--write-rate-limit=1GBps
or--write-rate-limit=100
(MBps). The default value is 0 — no limitation.If this option is specified, the following information is displayed at the end of the backup:
written
— the amount of data written, in MB.total time
— the time that elapsed between the first and last writes, in seconds. Note that this is not the total backup time.sleep time
— the amount of forced delay time, in seconds.average rate
— the actual average write rate, in MBps.
For example:
INFO: Rate limit: written 14975.445 MB, total time 17.163 s, sleep time 2.370 s, average rate 872.560715 MBps
--archive-timeout=
wait_time
Sets the timeout for WAL segment archiving and streaming, in seconds. By default,pg_probackup waits 300 seconds.
--skip-block-validation
Disables block-level checksum verification to speed up the backup process.
--no-validate
Skips automatic validation after the backup is taken. You can use this flag if you validate backups regularly and would like to save time when running backup operations.
--no-sync
Do not sync backed up files to disk. You can use this flag to speed up the backup process. Using this flag can result in data corruption in case of operating system or hardware crash. If you use this option, it is recommended to run thevalidate command once the backup is complete to detect possible issues.
--note=
backup_note
Sets the text note for backup copy. If
backup_note
contain newline characters, then only substring before first newline character will be saved. Max size of text note is 1 KB. The'none'
value removes current note.
For more details of the command settings, see sectionsCommon Options,Connection Options,Retention Options,Pinning Options,Remote Mode Options,Compression Options, andLogging Options.
For details on usage, see the sectionCreating a Backup.
restore#
pg_probackup restore -Bbackup_dir
--instance=instance_name
[--help] [--dry-run] [-Ddata_dir
] [-ibackup_id
][-jnum_threads
] [--progress][-TOLDDIR
=NEWDIR
] [--external-mapping=OLDDIR
=NEWDIR
] [--skip-external-dirs][-R | --restore-as-replica] [--no-validate] [--skip-block-validation][--force] [--no-sync][--restore-command=cmdline
][--primary-conninfo=primary_conninfo
][-S | --primary-slot-name=slot_name
][-Xwal_dir
| --waldir=wal_dir
][recovery_target_options
] [logging_options
] [remote_options
][partial_restore_options
] [remote_wal_archive_options
]
Restores thePostgres Pro instance from a backup copy located in thebackup_dir
backup catalog. If you specify arecovery target option,pg_probackup finds the closest backup and restores it to the specified recovery target. If neither the backup ID nor recovery target options are provided,pg_probackup uses the most recent backup to perform the recovery.
-R
--restore-as-replica
Creates a minimal recovery configuration file to facilitate setting up a standby server. If the replication connection requires a password, you must specify the password manually in theprimary_conninfo parameter as it is not included. ForPostgres Pro 11 or lower, recovery settings are written into the
recovery.conf
file. Starting fromPostgres Pro 12,pg_probackup writes these settings into theprobackup_recovery.conf
file in the data directory, and then includes them into thepostgresql.auto.conf
when the cluster is is started.--primary-conninfo=
primary_conninfo
Sets theprimary_conninfo parameter to the specified value. This option will be ignored unless the
-R
flag is specified.Example:
--primary-conninfo="host=192.168.1.50 port=5432 user=foo password=foopass"
-S
--primary-slot-name=
slot_name
Sets theprimary_slot_name parameter to the specified value. This option will be ignored unless the
-R
flag is specified.-T
OLDDIR
=NEWDIR
--tablespace-mapping=
OLDDIR
=NEWDIR
Relocates the tablespace from the
OLDDIR
to theNEWDIR
directory at the time of recovery. BothOLDDIR
andNEWDIR
must be absolute paths. If the path contains the equals sign (=
), escape it with a backslash. This option can be specified multiple times for multiple tablespaces.--external-mapping=
OLDDIR
=NEWDIR
Relocates an external directory included into the backup from the
OLDDIR
to theNEWDIR
directory at the time of recovery. BothOLDDIR
andNEWDIR
must be absolute paths. If the path contains the equals sign (=
), escape it with a backslash. This option can be specified multiple times for multiple directories.--skip-external-dirs
Skip external directories included into the backup with the
--external-dirs
option. The contents of these directories will not be restored.--skip-block-validation
Disables block-level checksum verification to speed up validation. During automatic validation before the restore only file-level checksums will be verified.
--no-validate
Skips backup validation. You can use this flag if you validate backups regularly and would like to save time when running restore operations.
--restore-command=
cmdline
Sets therestore_command parameter to the specified command. For example:
--restore-command='cp /mnt/server/archivedir/%f "%p"'
--force
Allows to ignore an invalid status of the backup. You can use this flag if you need to restore thePostgres Pro cluster from a corrupt or an invalid backup. Use with caution. If
PGDATA
contains a non-empty directory with system ID different from that of the backup being restored,incremental restore with this flag overwrites the directory contents (while an error occurs without the flag). If tablespaces are remapped through the--tablespace-mapping
option into non-empty directories, the contents of such directories will be deleted.--no-sync
Do not sync restored files to disk. You can use this flag to speed up restore process. Using this flag can result in data corruption in case of operating system or hardware crash. If it happens, you have to run therestore command again.
-X
wal_dir
--waldir=
wal_dir
Sets the directory to write WAL files to. By default WAL files will be placed in the
pg_wal
subdirectory of the target directory, but this option can be used to place them elsewhere.wal_dir
must be an absolute path, which must not already exist, but if it does, it must be empty.
For more details of the command settings, see sectionsCommon Options,Recovery Target Options,Remote Mode Options,Remote WAL Archive Options,Logging Options, andPartial Restore Options.
For details on usage, see the sectionRestoring a Cluster.
checkdb#
pg_probackup checkdb[-Bbackup_dir
] [--instance=instance_name
] [-Ddata_dir
][--help] [-jnum_threads
] [--progress][--amcheck [--skip-block-validation] [--checkunique] [--heapallindexed]][connection_options
] [logging_options
]
Verifies thePostgres Pro database cluster correctness by detecting physical and logical corruption.
--amcheck
Performs logical verification of indexes for the specifiedPostgres Pro instance if no corruption was found while checking data files. You must have theamcheck extension or theamcheck_next extension installed in the database to check its indexes. For databases withoutamcheck, index verification will be skipped. Additional options
--checkunique
and--heapallindexed
are effective depending on the version ofamcheck installed.--checkunique
Verifies unique constraints during logical verification of indexes. You can use this flag only together with the
--amcheck
flag when theamcheck extension is installed in the database.The verification of unique constraints is only possible if in the version of theamcheck extension you are using, the
bt_index_check
function takes thecheckunique
parameter.--heapallindexed
Checks that all heap tuples that should be indexed are actually indexed. You can use this flag only together with the
--amcheck
flag.This check is only possible if in the version of theamcheck/amcheck_next extension you are using, the
bt_index_check
function takes theheapallindexed
parameter.--skip-block-validation
Skip validation of data files. You can use this flag only together with the
--amcheck
flag, so that only logical verification of indexes is performed.
For more details of the command settings, see sectionsCommon Options,Connection Options, andLogging Options.
For details on usage, see the sectionVerifying a Cluster.
validate#
pg_probackup validate -Bbackup_dir
[--help] [--instance=instance_name
] [-ibackup_id
][-jnum_threads
] [--progress] [--wal][--skip-block-validation][recovery_target_options
] [logging_options
]
Verifies that all the files required to restore the cluster are present and are not corrupt. Ifinstance_name
is not specified,pg_probackup validates all backups available in the backup catalog. If you specify theinstance_name
without any additional options,pg_probackup validates all the backups available for this backup instance. If you specify theinstance_name
with arecovery target option and/or abackup_id
,pg_probackup checks whether it is possible to restore the cluster using these options. If the--wal
option is specified, full check of the WAL archive will be performed instead of only checking WAL segments needed to restore the cluster.
For details, see the sectionValidating a Backup.
merge#
pg_probackup merge -Bbackup_dir
--instance=instance_name
-ibackup_id
[--dry-run] [--help] [-jnum_threads
] [--progress] [--no-validate] [--no-sync][logging_options
]
Merges backups that belong to a common incremental backup chain. If you specify a full backup, it will be merged with its first incremental backup. If you specify an incremental backup, it will be merged to its parent full backup, together with all incremental backups between them. Once the merge is complete, the full backup takes in all the merged data, and the incremental backups are removed as redundant.
--no-validate
Skips automatic validation before and after merge.
--no-sync
Do not sync merged files to disk. You can use this flag to speed up the merge process. Using this flag can result in data corruption in case of operating system or hardware crash.
For more details of the command settings, see sectionsCommon Options andMerging Backups.
delete#
pg_probackup delete -Bbackup_dir
--instance=instance_name
[--help] [-jnum_threads
] [--progress][--retention-redundancy=redundancy
][--retention-window=window
][--wal-depth=wal_depth
] [--delete-wal]{-ibackup_id
| --delete-expired [--merge-expired] | --merge-expired | --status=backup_status}[--dry-run] [--no-validate] [--no-sync] [logging_options
]
Deletes backup with specifiedbackup_id
or launches the retention purge of backups and archived WAL that do not satisfy the current retention policies.
--no-validate
Skips automatic validation before and after retention merge.
--no-sync
Do not sync merged files to disk. You can use this flag to speed up the retention merge process. Using this flag can result in data corruption in case of operating system or hardware crash.
For details, see the sectionsDeleting Backups,Retention Options, andConfiguring Retention Policy.
archive-push#
pg_probackup archive-push -Bbackup_dir
--instance=instance_name
--wal-file-name=wal_file_name
[--wal-file-path=wal_file_path
][--help] [--dry-run] [--no-sync] [--compress] [--no-ready-rename] [--overwrite][-jnum_threads
] [--batch-size=batch_size
][--archive-timeout=timeout
][--compress-algorithm=compression_algorithm
][--compress-level=compression_level
][remote_options
] [logging_options
]
Copies WAL files into the corresponding subdirectory of the backup catalog and validates the backup instance byinstance_name
andsystem-identifier
. If parameters of the backup instance and the cluster do not match, this command fails with the following error message:Refuse to push WAL segment segment_name into archive. Instance parameters mismatch.
If the files to be copied already exists in the backup catalog,pg_probackup computes and compares their checksums. If the checksums match,archive-push
skips the corresponding file and returns a successful execution code. Otherwise,archive-push
fails with an error. If you would like to replace WAL files in the case of checksum mismatch, run thearchive-push
command with the--overwrite
flag.
Each file is copied to a temporary file with the.part
suffix. If the temporary file already exists,pg_probackup will waitarchive_timeout
seconds before discarding it. After the copy is done, atomic rename is performed. This algorithm ensures that a failedarchive-push
will not stall continuous archiving and that concurrent archiving from multiple sources into a single WAL archive has no risk of archive corruption.
ThePostgres Pro server requests WAL segments one at a time. To speed up archiving, you can specify the--batch-size
option to copy WAL segments in batches of the specified size. If--batch-size
option is used, then you can also specify the-j
option to copy the batch of WAL segments on multiple threads.
WAL segments copied to the archive are synced to disk unless the--no-sync
flag is used.
You can usearchive-push
in thearchive_commandPostgres Pro parameter to set upcontinuous WAL archiving.
For more details of the command settings, see sectionsCommon Options,Archiving Options, andCompression Options.
archive-get#
pg_probackup archive-get -Bbackup_dir
--instance=instance_name
--wal-file-path=wal_file_path
--wal-file-name=wal_file_name
[-jnum_threads
] [--batch-size=batch_size
][--prefetch-dir=prefetch_dir_path
] [--no-validate-wal][--dry-run] [--help] [remote_options
] [logging_options
]
Copies WAL files from the corresponding subdirectory of the backup catalog to the cluster's write-ahead log location. This command is automatically set bypg_probackup as part of therestore_command
when restoring backups using a WAL archive. You do not need to set it manually.
ThePostgres Pro server requests WAL segments one at a time. To speed up recovery, you can specify the--batch-size
option to copy WAL segments in batches of the specified size. If--batch-size
option is used, then you can also specify the-j
option to copy the batch of WAL segments on multiple threads.
For more details of the command settings, see sectionsCommon Options,Archiving Options, andCompression Options.
catchup#
pg_probackup catchup -bcatchup_mode
--source-pgdata=path_to_pgdata_on_remote_server
--destination-pgdata=path_to_local_dir
[--help] [-j | --threads=num_threads
] [--dry-run][--write-rate-limit=bitrate
][--stream [--temp-slot[=true|false|on|off]] [-P | --perm-slot] [-S | --slot=slot_name
]][--exclude-path=PATHNAME
][-TOLDDIR
=NEWDIR
][-X | --waldir=wal_dir
][connection_options
] [remote_options
][logging_options
]
Creates a copy of aPostgres Pro instance without using the backup catalog.
-b
catchup_mode
--backup-mode=
catchup_mode
Specifies the catchup mode to use. Possible values are:
FULL
,DELTA
, andPTRACK
.--source-pgdata=
path_to_pgdata_on_remote_server
Specifies the path to the data directory of the instance to be copied. The path can be local or remote.
--destination-pgdata=
path_to_local_dir
Specifies the path to the local data directory to copy to.
-j
num_threads
--threads=
num_threads
Sets the number of parallel threads for
catchup
process.--stream
Copies the instance inSTREAM WAL delivery mode, including all the necessary WAL files by streaming them from the server via replication protocol. For
catchup
, it is enabled by default.--write-rate-limit=
bitrate
Sets the rate of writing data to disk, in MBps or GBps. The default unit is MBps. For example:
--write-rate-limit=1GBps
or--write-rate-limit=100
(MBps). The default value is 0 — no limitation.If this option is specified, the following information is displayed at the end of the
catchup
operation:written
— the amount of data written, in MB.total time
— the time that elapsed between the first and last writes, in seconds. Note that this is not the total duration of thecatchup
operation.sleep time
— the amount of forced delay time, in seconds.average rate
— the actual average write rate, in MBps.
For example:
INFO: Rate limit: written 14975.445 MB, total time 17.163 s, sleep time 2.370 s, average rate 872.560715 MBps
-x
=path_prefix
--exclude-path
=path_prefix
Specifies a prefix for files to exclude from the synchronization ofPostgres Pro instances during copying. The prefix must contain a path relative to the data directory of an instance. If the prefix specifies a directory, all files in this directory will not be synchronized.
Warning
This option is dangerous since excluding files from synchronization can result in incomplete synchronization; use with care.
--temp-slot[=
true
|false
|on
|off
]Creates atemporary physical replication slot for streaming WAL from thePostgres Pro instance being copied.
--temp-slot
is enabled by default. It ensures that all the required WAL segments remain available if WAL is rotated while the backup is in progress. This flag can only be used together with the--stream
flag and cannot be used together with the--perm-slot
flag. The default slot name ispg_probackup_slot
. To change it, use the--slot
/-S
option and explicitly specify--temp-slot
or--temp-slot=
.true
|on
-P
--perm-slot
Creates apermanent physical replication slot for streaming WAL from thePostgres Pro instance being copied. This flag can only be used together with the
--stream
flag and cannot be used together with the--temp-slot
flag. The default slot name ispg_probackup_perm_slot
, which can be changed using the--slot
/-S
option.-S
slot_name
--slot=
slot_name
Specifies the replication slot to connect to for WAL streaming. This option can only be used together with the
--stream
flag.-T
OLDDIR
=NEWDIR
--tablespace-mapping=
OLDDIR
=NEWDIR
Relocates the tablespace from the
OLDDIR
to theNEWDIR
directory at the time of recovery. BothOLDDIR
andNEWDIR
must be absolute paths. If the path contains the equals sign (=
), escape it with a backslash. This option can be specified multiple times for multiple tablespaces.-X
wal_dir
--waldir=
wal_dir
Sets the directory to write WAL files to. By default WAL files will be placed in the
pg_wal
subdirectory of the target directory, but this option can be used to place them elsewhere.wal_dir
must be an absolute path, which must not already exist, but if it does, it must be empty to performcatchup
with--catchup-mode
=FULL
.
For more details of the command settings, see sectionsCommon Options,Connection Options, andRemote Mode Options.
For details on usage, see the sectionCloning and SynchronizingPostgres Pro Instance.
Options#
This section describes command-line options forpg_probackup commands. If the option value can be derived from an environment variable, this variable is specified below the command-line option, in the uppercase. Some values can be taken from thepg_probackup.conf
configuration file located in the backup catalog.
For details, seethe section called “Configuringpg_probackup”.
If an option is specified using more than one method, command-line input has the highest priority, while thepg_probackup.conf
settings have the lowest priority.
Common Options#
The list of general options.
--dry-run
Initiates a trial run of the appropriate command, which does not actually do any changes, that is, it does not create, delete or move files on disk. This flag allows you to check that all the command options are correct and the command is ready to run. WAL streaming is skipped with
--dry-run
.-B
directory
--backup-path=
directory
BACKUP_PATH
Specifies the absolute path to the backup catalog. Backup catalog is a directory where all backup files and meta information are stored. Since this option is required for most of thepg_probackup commands, you are recommended to specify it once in the
BACKUP_PATH
environment variable. In this case, you do not need to use this option each time on the command line.-D
directory
--pgdata=
directory
PGDATA
Specifies the absolute path to the data directory of the database cluster. This option is mandatory only for theadd-instance command. Other commands can take its value from the
PGDATA
environment variable, or from thepg_probackup.conf
configuration file.-i
backup_id
--backup-id=
backup_id
Specifies the unique identifier of the backup.
-j
num_threads
--threads=
num_threads
Sets the number of parallel threads for
backup
,restore
,merge
,validate
,checkdb
, andarchive-push
processes.--progress
Shows the progress of operations.
--help
Shows detailed information about the options that can be used with this command.
Recovery Target Options#
Ifcontinuous WAL archiving is configured, you can use one of these options together withrestore orvalidate commands to specify the moment up to which the database cluster must be restored or validated.
--recovery-target=immediate|latest
Defines when to stop the recovery:
The
immediate
value stops the recovery after reaching the consistent state of the specified backup, or the latest available backup if the-i
/--backup-id
option is omitted. This is the default behavior for STREAM backups.The
latest
value continues the recovery until all WAL segments available in the archive are applied. Setting this value of--recovery-target
also sets--recovery-target-timeline
tolatest
.
--recovery-target-timeline=
timeline
Specifies a particular timeline to be used for recovery:
current
— the timeline of the specified backup, default.
latest
— the timeline of the latest available backup.A numeric value.
--recovery-target-lsn=
lsn
Specifies the LSN of the write-ahead log location up to which recovery will proceed.
--recovery-target-name=
recovery_target_name
Specifies a named savepoint up to which to restore the cluster.
--recovery-target-time=
time
Specifies the timestamp up to which recovery will proceed. If the time zone offset is not specified, the local time zone is used.
Example:
--recovery-target-time="2027-04-09 18:21:32+00"
--recovery-target-xid=
xid
Specifies the transaction ID up to which recovery will proceed.
--recovery-target-inclusive=
boolean
Specifies whether to stop just after the specified recovery target (
true
), or just before the recovery target (false
). This option can only be used together with--recovery-target-time
,--recovery-target-lsn
or--recovery-target-xid
options. The default depends on therecovery_target_inclusive parameter.--recovery-target-action=pause|promote|shutdown
Specifiesrecovery_target_action the server should take when the recovery target is reached.
Default:
pause
Retention Options#
You can use these options together withbackup anddelete commands.
For details on configuring retention policy, see the sectionConfiguring Retention Policy.
--retention-redundancy=
redundancy
Specifies the number of full backup copies to keep in the data directory. Must be a non-negative integer. The zero value disables this setting.
Default:
0
--retention-window=
window
Number of days of recoverability. Must be a non-negative integer. The zero value disables this setting.
Default:
0
--wal-depth=
wal_depth
Number of latest valid backups on every timeline that must retain the ability to perform PITR. Must be a non-negative integer. The zero value disables this setting.
Default:
0
--delete-wal
Deletes WAL files that are no longer required to restore the cluster from any of the existing backups.
--delete-expired
Deletes backups that do not conform to the retention policy defined in the
pg_probackup.conf
configuration file.--merge-expired
Merges the oldest incremental backup that satisfies the requirements of retention policy with its parent backups that have already expired.
--dry-run
Displays the current status of all the available backups, without deleting or merging expired backups, if any.
Pinning Options#
You can use these options together withbackup andset-backup commands.
For details on backup pinning, see the sectionBackup Pinning.
--ttl=
ttl
Specifies the amount of time the backup should be pinned. Must be a non-negative integer. The zero value unpins the already pinned backup. Supported units: ms, s, min, h, d (s by default).
Example:
--ttl=30d
--expire-time=
time
Specifies the timestamp up to which the backup will stay pinned. Must be an ISO-8601 complaint timestamp. If the time zone offset is not specified, the local time zone is used.
Example:
--expire-time="2027-04-09 18:21:32+00"
Logging Options#
You can use these options with any command.
--no-color
Disable coloring for console log messages of
warning
anderror
levels.--log-level-console=
log_level
Controls which message levels are sent to the console log. Valid values are
verbose
,log
,info
,warning
,error
andoff
. Each level includes all the levels that follow it. The later the level, the fewer messages are sent. Theoff
level disables console logging.Default:
info
Note
All console log messages are going tostderr, so the output ofshow andshow-config commands does not mingle with log messages.
--log-level-file=
log_level
Controls which message levels are sent to a log file. Valid values are
verbose
,log
,info
,warning
,error
, andoff
. Each level includes all the levels that follow it. The later the level, the fewer messages are sent. Theoff
level disables file logging.Default:
off
--log-filename=
log_filename
Defines the filenames of the created log files. The filenames are treated as a
strftime
pattern, so you can use %-escapes to specify time-varying filenames.Default:
pg_probackup.log
For example, if you specify the
pg_probackup-%u.log
pattern,pg_probackup generates a separate log file for each day of the week, with%u
replaced by the corresponding decimal number:pg_probackup-1.log
for Monday,pg_probackup-2.log
for Tuesday, and so on.This option takes effect if file logging is enabled by the
--log-level-file
option.--error-log-filename=
error_log_filename
Defines the filenames of log files for error messages only. The filenames are treated as a
strftime
pattern, so you can use %-escapes to specify time-varying filenames.Default: none
For example, if you specify the
error-pg_probackup-%u.log
pattern,pg_probackup generates a separate log file for each day of the week, with%u
replaced by the corresponding decimal number:error-pg_probackup-1.log
for Monday,error-pg_probackup-2.log
for Tuesday, and so on.This option is useful for troubleshooting and monitoring.
--log-directory=
log_directory
Defines the directory in which log files will be created. You must specify the absolute path. This directory is created lazily, when the first log message is written.
Default:
$BACKUP_PATH/log/
--log-format-console=
log_format
Defines the format of the console log. Only set from the command line. Note that you cannot specify this option in the
pg_probackup.conf
configuration file through theset-config command and that thebackup command also treats this option specified in the configuration file as an error. Possible values are:plain
— sets the plain-text format of the console log.json
— sets theJSON format of the console log.
Default:
plain
--log-format-file=
log_format
Defines the format of log files used. Possible values are:
plain
— sets the plain-text format of log files.json
— sets theJSON format of log files.
Default:
plain
--log-rotation-size=
log_rotation_size
Maximum size of an individual log file. If this value is reached, the log file is rotated once apg_probackup command is launched, except
help
andversion
commands. The zero value disables size-based rotation. Supported units: kB, MB, GB, TB (kB by default).Default:
0
--log-rotation-age=
log_rotation_age
Maximum lifetime of an individual log file. If this value is reached, the log file is rotated once apg_probackup command is launched, except
help
andversion
commands. The time of the last log file creation is stored in$BACKUP_PATH/log/log_rotation
. The zero value disables time-based rotation. Supported units: ms, s, min, h, d (min by default).Default:
0
Connection Options#
You can use these options together withbackup,catchup, andcheckdb commands.
Alllibpq environment variables are supported.
-d
dbname
--pgdatabase=
dbname
PGDATABASE
Specifies the name of the database to connect to. The connection is used only for managing backup process, so you can connect to any existing database. If this option is not provided on the command line,
PGDATABASE
environment variable, or thepg_probackup.conf
configuration file,pg_probackup tries to take this value from thePGUSER
environment variable, or from the current user name ifPGUSER
variable is not set.-h
host
--pghost=
host
PGHOST
Specifies the host name of the system on which the server is running. If the value begins with a slash, it is used as a directory for the Unix domain socket.
Default:
localhost
-p
port
--pgport=
port
PGPORT
Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.
Default:
5432
-U
username
--pguser=
username
PGUSER
User name to connect as.
-w
--no-password
Disables a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpass file or
PGPASSWORD
environment variable, the connection attempt will fail. This flag can be useful in batch jobs and scripts where no user is present to enter a password.-W
--password
Forces a password prompt. (Deprecated)
Compression Options#
You can use these options together withbackup andarchive-push commands.
--compress-algorithm=
compression_algorithm
Defines the algorithm to use for compressing data files. Possible values are
zlib
,lz4
,zstd
,pglz
, andnone
. If set to any value, butnone
, this option enables compression that uses the corresponding algorithm. Both data files and WAL files are compressed. By default, compression is disabled. For thearchive-push command, thepglz
compression algorithm is not supported.Note
pg_probackup supports compression algorithms included in thePostgres Pro version. In particular:
lz4 is supported forPostgres Pro 14 and higher.
zstd is supported forPostgres Pro 15 and higher.
Default:
none
--compress-level=
compression_level
Defines the compression level. This option can be used together with the
--compress-algorithm
option. Possible values depend on the compression algorithm specified:0 — 9 for
zlib
1 for
pglz
0 — 12 for
lz4
0 — 22 for
zstd
The value of 0 sets the default compression level for the specified algorithm:
6 for
zlib
1 for
pglz
9 for
lz4
3 for
zstd
Note
The pure lz4 algorithmn has only one compression level — 1. So, if the specified compression algorithm is
lz4
and--compress-level
is greater than 1, the lz4hc algorithm is actually used, which is much slower although does better compression.Default:
1
--compress
Specifies the default compression algorithm and
--compress-level=1
. The default algorithm is selected among those supported byPostgres Pro according to the priorities:zstd
(highest) ->lz4
->zlib
->pglz
. The--compress
option overrides the--compression-algorithm
and--compress-level
settings and cannot be specified together with them.
Archiving Options#
These options can be used with thearchive-push command in thearchive_command setting and thearchive-get command in therestore_command setting.
Additionally,remote mode options andlogging options can be used.
--wal-file-path=
wal_file_path
Provides the path to the WAL file in
archive_command
andrestore_command
. Use the%p
variable as the value for this option or explicitly specify the path to a file outside of the data directory. If you skip this option, the path specified inpg_probackup.conf
will be used.--wal-file-name=
wal_file_name
Provides the name of the WAL file in
archive_command
andrestore_command
. Use the%f
variable as the value for this option for correct processing. If the value of--wal-file-path
is a path outside of the data directory, explicitly specify the filename.--overwrite
Overwrites archived WAL file. Use this flag together with thearchive-push command if the specified subdirectory of the backup catalog already contains this WAL file and it needs to be replaced with its newer copy. Otherwise,
archive-push
reports that a WAL segment already exists, and aborts the operation. If the file to replace has not changed,archive-push
skips this file regardless of the--overwrite
flag.--batch-size=
batch_size
Used to speed up archiving in case of
archive-push
or to speed up recovery in case ofarchive-get
. Sets the maximum number of WAL files that can be copied into the archive by a singlearchive-push
process, or from the archive by a singlearchive-get
process.--archive-timeout=
wait_time
Sets the timeout for considering existing
.part
files to be stale. By default,pg_probackup waits 300 seconds. This option can be used only witharchive-push command.--no-ready-rename
Do not rename status files in the
archive_status
directory. This option should be used only ifarchive_command
contains multiple commands. This option can be used only witharchive-push command.--no-sync
Do not sync copied WAL files to disk. You can use this flag to speed up archiving process. Using this flag can result in WAL archive corruption in case of operating system or hardware crash. This option can be used only witharchive-push command.
--prefetch-dir=
path
Directory used to store prefetched WAL segments if
--batch-size
option is used. Directory must be located on the same filesystem and on the same mountpoint thePGDATA/pg_wal
is located. By default files are stored inPGDATA/pg_wal/pbk_prefetch
directory. This option can be used only witharchive-get command.--no-validate-wal
Do not validate prefetched WAL file before using it. Use this option if you want to increase the speed of recovery. This option can be used only witharchive-get command.
Remote Mode Options#
This section describes the options related to runningpg_probackup operations remotely via SSH. These options can be used withadd-instance,set-config,backup,catchup,restore,archive-push, andarchive-get commands.
For details on configuring and using the remote mode, seethe section called “Configuring the Remote Mode” andthe section called “Usingpg_probackup in the Remote Mode”.
--remote-proto=
proto
Specifies the protocol to use for remote operations. Currently only the SSH protocol is supported. Possible values are:
ssh
enables the remote mode via SSH. This is the default value.none
explicitly disables the remote mode.
You can omit this option if the
--remote-host
option is specified.--remote-host=
destination
Specifies the remote host IP address or hostname to connect to.
--remote-port=
port
Specifies the remote host port to connect to.
Default:
22
--remote-user=
username
Specifies remote host user for SSH connection. If you omit this option, the current user initiating the SSH connection is used.
--remote-path=
path
Specifiespg_probackup installation directory on the remote system.
--ssh-options=
ssh_options
Provides a string of SSH command-line options. For example, the following options can be used to set
keep-alive
for SSH connections opened bypg_probackup:--ssh-options="-o ServerAliveCountMax=5 -o ServerAliveInterval=60"
. For the full list of possible options, seessh_config manual page.
Remote WAL Archive Options#
This section describes the options used to provide the arguments forremote mode options inarchive-get used in therestore_command command when restoring ARCHIVE backups or performing PITR.
--archive-host=
destination
Provides the argument for the
--remote-host
option in thearchive-get
command.--archive-port=
port
Provides the argument for the
--remote-port
option in thearchive-get
command.Default:
22
--archive-user=
username
Provides the argument for the
--remote-user
option in thearchive-get
command. If you omit this option, the user that has started thePostgres Pro cluster is used.Default:Postgres Pro user
Incremental Restore Options#
This section describes the options for incremental cluster restore. These options can be used with therestore command.
-I
incremental_mode
--incremental-mode=
incremental_mode
Specifies the incremental mode to be used. Possible values are:
CHECKSUM
— replace only pages with mismatched checksum and LSN.LSN
— replace only pages with LSN greater than point of divergence.NONE
— regular restore.
Partial Restore Options#
This section describes the options for partial cluster restore. These options can be used with therestore command.
--db-exclude=
dbname
Specifies the name of the database to exclude from restore. All other databases in the cluster will be restored as usual, including
template0
andtemplate1
. This option can be specified multiple times for multiple databases.--db-include=
dbname
Specifies the name of the database to restore from a backup. All other databases in the cluster will not be restored, with the exception of
template0
andtemplate1
. This option can be specified multiple times for multiple databases.
Testing and Debugging Options#
This section describes options useful only in a test or development environment.
PGPROBACKUP_TESTS_SKIP_HIDDEN
Instructspg_probackup to ignore backups marked as hidden. Note thatpg_probackup can never mark a backup as hidden. It can only be done by directly editing the
backup.control
file. This option can only be set with environment variables.--destroy-all-other-dbs
By default,pg_probackup exits with an error if an attempt is made to perform a partial incremental restore since this destroys databases not included in the restore set. This flag allows you to suppress the error and proceed with the partial incremental restore (e.g., to keep a development database snapshot up-to-date with a production one). This option can be used with therestore command.
Important
Never use this flag in a production cluster.
PGPROBACKUP_TESTS_SKIP_EMPTY_COMMIT
Instructspg_probackup to skip empty commits after pg_backup_stop.