1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-28 09:33:54 +02:00
pg_probackup/Documentation.md

1223 lines
77 KiB
Markdown
Raw Normal View History

2019-06-13 16:32:43 +02:00
# pg_probackup
2019-06-13 16:57:39 +02:00
2019-06-13 16:49:02 +02:00
**pg_probackup** is a utility to manage backup and recovery of PostgreSQL database clusters. It is designed to perform periodic backups of the PostgreSQL instance that enable you to restore the server in case of a failure. pg_probackup supports PostgreSQL 9.5 or higher.
2019-06-13 16:57:39 +02:00
Current version - 2.1.3
2019-06-23 04:05:01 +02:00
1. [Synopsis](#synopsis)
2. [Overview](#overview)
2019-06-23 11:32:49 +02:00
* [Limitations](#limitations)
2019-06-23 04:05:01 +02:00
3. [Installation and Setup](#installation-and-setup)
2019-06-23 11:32:49 +02:00
* [Initializing the Backup Catalog](#initializing-the-backup-catalog)
* [Adding a New Backup Instance](#adding-a-new-backup-instance)
* [Configuring the Database Cluster](#configuring-the-database-cluster)
* [Setting up STREAM Backups](#setting-up-stream-backups)
* [Setting up Continuous WAL Archiving](#setting-up-continuous-wal-archiving)
* [Setting up Backup from Standby](#backup-from-standby)
* [Setting up Cluster Verification](#setting-up-cluster-verification)
2019-06-23 11:32:49 +02:00
* [Setting up PTRACK Backups](#setting-up-ptrack-backups)
2019-06-23 04:05:01 +02:00
4. [Command-Line Reference](#command-line-reference)
2019-06-23 11:32:49 +02:00
* [Commands](#commands)
* [version](#version)
* [help](#help)
2019-06-23 19:34:45 +02:00
* [init](#init)
2019-06-23 11:32:49 +02:00
* [add-instance](#add-instance)
* [del-instance](#del-instance)
* [set-config](#set-config)
* [show-config](#show-config)
* [show](#show)
* [backup](#backup)
* [restore](#restore)
* [checkdb](#checkdb)
2019-06-23 11:32:49 +02:00
* [validate](#validate)
* [merge](#merge)
* [delete](#delete)
* [archive-push](#archive-push)
* [archive-get](#archive-get)
* [Options](#options)
* [Common Options](#common-options)
* [Backup Options](#backup-options)
* [Restore Options](#restore-options)
* [Checkdb Options](#checkdb-options)
* [Recovery Target Options](#recovery-target-options)
* [Retention Options](#retention-options)
* [Logging Options](#logging-options)
* [Connection Options](#connection-options)
2019-06-23 19:34:45 +02:00
* [Compression Options](#compression-options)
2019-06-23 11:32:49 +02:00
* [Archiving Options](#archiving-options)
* [Remote Mode Options](#remote-mode-options)
* [Replica Options](#replica-options)
2019-06-23 04:05:01 +02:00
5. [Usage](#usage)
2019-06-23 11:32:49 +02:00
* [Creating a Backup](#creating-a-backup)
2019-06-23 22:05:08 +02:00
* [Verifying a Cluster](#verifying-a-cluster)
2019-06-23 19:34:45 +02:00
* [Validating a Backup](#validating-a-backup)
2019-06-23 11:32:49 +02:00
* [Restoring a Cluster](#restoring-a-cluster)
2019-06-23 19:34:45 +02:00
* [Performing Point-in-Time (PITR) Recovery](#performing-point-in-time-pitr-recovery)
2019-06-23 11:32:49 +02:00
* [Using pg_probackup in the Remote Mode](#using-pg_probackup-in-the-remote-mode)
* [Running pg_probackup on Parallel Threads](#running-pg_probackup-on-parallel-threads)
* [Configuring pg_probackup](#configuring-pg_probackup)
* [Managing the Backup Catalog](#managing-the-backup-Catalog)
* [Configuring Backup Retention Policy](#configuring-backup-retention-policy)
* [Merging Backups](#merging-backups)
* [Deleting Backups](#deleting-backups)
2019-06-23 04:05:01 +02:00
6. [Authors](#authors)
7. [Credits](#credits)
2019-06-13 16:32:43 +02:00
### Synopsis
2019-06-23 04:05:01 +02:00
`pg_probackup version`
`pg_probackup help [command]`
2019-06-20 19:49:42 +02:00
`pg_probackup init -B backup_dir`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup add-instance -B backup_dir -D data_dir --instance instance_name`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup del-instance -B backup_dir --instance instance_name`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup set-config -B backup_dir --instance instance_name [option...]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup show-config -B backup_dir --instance instance_name [--format=format]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup show -B backup_dir [option...]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup backup -B backup_dir --instance instance_name -b backup_mode [option...]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup restore -B backup_dir --instance instance_name [option...]`
2019-06-13 16:34:15 +02:00
2019-06-24 00:41:05 +02:00
`pg_probackup checkdb -B backup_dir --instance instance_name [-D data_dir] [option...]`
2019-06-20 19:49:42 +02:00
`pg_probackup validate -B backup_dir [option...]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup merge -B backup_dir --instance instance_name -i backup_id [option...]`
2019-06-13 16:34:15 +02:00
2019-06-23 04:05:01 +02:00
`pg_probackup delete -B backup_dir --instance instance_name { -i backup_id | --delete-wal | --delete-expired | --merge-expired }`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup archive-push -B backup_dir --instance instance_name --wal-file-path %p --wal-file-name %f [option...]`
2019-06-13 16:34:15 +02:00
2019-06-20 19:49:42 +02:00
`pg_probackup archive-get -B backup_dir --instance instance_name --wal-file-path %p --wal-file-name %f`
2019-06-13 16:34:15 +02:00
2019-06-13 16:32:43 +02:00
### 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:
2019-06-24 00:41:05 +02:00
- Incremental backup: page-level incremental backup allows you save to disk space, speed up backup and restore. With three different incremental modes you can plan the backup strategy in accordance with your data flow
2019-06-20 19:49:42 +02:00
- Validation: Automatic data consistency checks and on-demand backup validation without actual data recovery
2019-06-23 04:05:01 +02:00
- Verification: On-demand verification of PostgreSQL instance via dedicated command `checkdb`
- Retention: Managing backups in accordance with retention policies - Time and/or Redundancy based, with two retention methods: `delete expired` and `merge expired`
2019-06-24 00:41:05 +02:00
- Parallelization: Running backup, restore, merge, delete, verificaton and validation processes on multiple parallel threads
2019-06-20 19:49:42 +02:00
- Compression: Storing backup data in a compressed state to save disk space
2019-06-23 04:05:01 +02:00
- Deduplication: Saving disk space by not copying the not changed non-data files ('_vm', '_fsm', etc)
2019-06-20 19:49:42 +02:00
- Remote operations: Backup PostgreSQL instance located on remote machine or restore backup on it
- Backup from replica: Avoid extra load on the master server by taking backups from a standby
2019-06-23 04:05:01 +02:00
- External directories: Add to backup content of directories located outside of the PostgreSQL data directory (PGDATA), such as scripts, configs, logs and pg_dump files
2019-06-24 00:41:05 +02:00
- Backup Catalog: get list of backups and corresponding meta information in `plain` or `json` formats
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
To manage backup data, pg_probackup creates a `backup 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.
2019-06-13 16:32:43 +02:00
Using pg_probackup, you can take full or incremental backups:
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
- FULL backups contain all the data files required to restore the database cluster.
2019-06-24 00:41:05 +02:00
- Incremental backups only store the data that has changed since the previous backup. It allows to decrease the backup size and speed up backup and restore operations. pg_probackup supports the following modes of incremental backups:
2019-06-20 19:49:42 +02:00
- DELTA backup. In this mode, pg_probackup reads all data files in the data directory and copies only those pages that has changed since the previous backup. Note that this mode can impose read-only I/O pressure equal to a full backup.
2019-06-23 04:05:01 +02:00
- 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 in the section [Setting up continuous WAL archiving](#setting-up-continuous-wal-archiving) to make PAGE backups.
2019-06-13 16:49:02 +02:00
- PTRACK backup. In this mode, PostgreSQL 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 for this relation. As one page requires just one bit in the PTRACK fork, such bitmaps are quite small. Tracking implies some minor overhead on the database server operation, but speeds up incremental backups significantly.
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
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, DELTA, etc), all backups taken with pg_probackup must use one of the following `WAL delivery methods`:
2019-06-20 19:49:42 +02:00
2019-06-24 23:43:48 +02:00
- ARCHIVE. Such backups rely on [continuous archiving](#setting-up-continuous-wal-archiving) to ensure consistent recovery. This is the default WAL delivery method.
2019-06-23 04:05:01 +02:00
- STREAM. Such backups include all the files required to restore the cluster to a consistent state at the time the backup was taken. Regardless of [continuous archiving](#setting-up-continuous-wal-archiving) been set up or not, the WAL segments required for consistent recovery are streamed (hence STREAM) via replication protocol during backup and included into the backup files.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Limitations
2019-06-13 16:32:43 +02:00
pg_probackup currently has the following limitations:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- Creating backups from a remote server is currently not supported on Windows systems.
2019-06-23 12:11:10 +02:00
- The PostgreSQL server from which the backup was taken and the restored server must be compatible by the [block_size](https://www.postgresql.org/docs/current/runtime-config-preset.html#GUC-BLOCK-SIZE) and [wal_block_size](https://www.postgresql.org/docs/current/runtime-config-preset.html#GUC-WAL-BLOCK-SIZE) parameters and have the same major release number.
2019-06-13 16:32:43 +02:00
### Installation and Setup
2019-06-13 16:49:02 +02:00
Once you have pg_probackup installed, complete the following setup:
2019-06-13 16:32:43 +02:00
- Initialize the backup catalog.
- Add a new backup instance to the backup catalog.
- Configure the database cluster to enable pg_probackup backups.
2019-06-23 04:05:01 +02:00
#### Initializing the Backup Catalog
2019-06-13 16:32:43 +02:00
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:
2019-06-20 19:49:42 +02:00
pg_probackup init -B backup_dir
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Where *backup_dir* is the path to backup catalog. If the *backup_dir* already exists, it must be empty. Otherwise, pg_probackup returns an error.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup creates the backup_dir backup catalog, with the following subdirectories:
2019-06-24 23:43:48 +02:00
- wal/ — directory for WAL files.
- backups/ — directory for backup files.
2019-06-13 16:32:43 +02:00
Once the backup catalog is initialized, you can add a new backup instance.
2019-06-23 04:05:01 +02:00
#### Adding a New Backup Instance
2019-06-13 16:32:43 +02:00
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:
2019-06-23 15:46:30 +02:00
pg_probackup add-instance -B backup_dir -D data_dir --instance instance_name [remote_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Where:
- *data_dir* is the data directory of the cluster you are going to back up. To set up and use pg_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.
- The optional parameters [remote_options](#remote-mode-options) should be used if *data_dir* is located on remote machine.
2019-06-13 16:32:43 +02:00
2019-06-24 23:52:03 +02:00
pg_probackup creates the *instance_name* subdirectories under the 'backups/' and 'wal/' directories of the backup catalog. The 'backups/*instance_name*' directory contains the 'pg_probackup.conf' configuration file that controls backup and restore settings for this backup instance. If you run this command with the [remote_options](#remote-mode-options), used parameters will be added to 'pg_probackup.conf'.
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
For details on how to fine-tune pg_probackup configuration, see the section [Configuring pg_probackup](#configuring-pg_probackup).
The user launching pg_probackup must have full access to *backup_dir* directory and at least read-only access to *data_dir* directory. If you specify the path to the backup catalog in the `BACKUP_PATH` environment variable, you can omit the corresponding option when running pg_probackup commands.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Configuring the Database Cluster
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Although pg_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, the *backup* role is used as an example.
2019-06-13 16:32:43 +02:00
To enable backups, the following rights are required:
```CREATE ROLE backup WITH LOGIN;
GRANT USAGE ON SCHEMA pg_catalog TO backup;
GRANT EXECUTE ON FUNCTION current_setting(text) TO backup;
GRANT EXECUTE ON FUNCTION pg_is_in_recovery() TO backup;
GRANT EXECUTE ON FUNCTION pg_start_backup(text, boolean, boolean) TO backup;
GRANT EXECUTE ON FUNCTION pg_stop_backup() TO backup;
GRANT EXECUTE ON FUNCTION pg_stop_backup(boolean, boolean) TO backup;
GRANT EXECUTE ON FUNCTION pg_create_restore_point(text) TO backup;
GRANT EXECUTE ON FUNCTION pg_switch_wal() TO backup;
GRANT EXECUTE ON FUNCTION txid_current() TO backup;
GRANT EXECUTE ON FUNCTION txid_current_snapshot() TO backup;
GRANT EXECUTE ON FUNCTION txid_snapshot_xmax(txid_snapshot) TO backup;
```
Since pg_probackup needs to read cluster files directly, pg_probackup must be started on behalf of an 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 are plan to take STREAM and/or ARCHIVE backups, PostgreSQL cluster configuration will differ, as specified in the sections below. To back up the database cluster from a standby server or create PTRACK backups, additional setup is required. For details, see the sections [Setting up STREAM Backups](#setting-up-stream-backups), [Setting up continuous WAL archiving](#setting-up-continuous-wal-archiving), [Setting up PTRACK Backups](#setting-up-ptrack-backups) and [Setting up Backup from Standby](#backup-from-standby).
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Setting up STREAM Backups
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
To set up the cluster for STREAM backups, complete the following steps:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- Grant the REPLICATION privilege to the backup role:
2019-06-13 16:49:02 +02:00
ALTER ROLE backup WITH REPLICATION;
2019-06-20 19:49:42 +02:00
2019-06-24 23:43:48 +02:00
- In the [pg_hba.conf](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) file, allow replication on behalf of the *backup* role.
- Make sure the parameter [max_wal_senders](https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-MAX-WAL-SENDERS) is set high enough to leave at least one session available for the backup process.
- Set the parameter [wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-WAL-LEVEL) to be higher than `minimal`.
2019-06-13 16:32:43 +02:00
If you are planning to take PAGE backups in STREAM mode, you still have to configure WAL archiving as explained in the section [Setting up continuous WAL archiving](#setting-up-continuous-wal-archiving).
2019-06-23 04:05:01 +02:00
Once these steps are complete, you can start taking FULL, PAGE, DELTA and PTRACK backups in STREAM mode.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Setting up continuous WAL archiving
2019-06-23 12:11:10 +02:00
ARCHIVE backups require [continious WAL archiving](https://www.postgresql.org/docs/current/continuous-archiving.html) to be enabled. To set up continious archiving in the cluster, complete the following steps:
2019-06-24 23:43:48 +02:00
- Make sure the [wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-WAL-LEVEL) parameter is higher than `minimal`.
2019-06-24 00:41:05 +02:00
- If you are configuring backups on master, [archive_mode](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-MODE) must be set to `on`. To perform archiving on standby, set this parameter to `always`.
- Set the [archive_command](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-COMMAND) parameter, as follows:
2019-06-23 22:09:09 +02:00
2019-06-24 00:41:05 +02:00
archive_command = 'pg_probackup archive-push -B backup_dir --instance instance_name --wal-file-path %p --wal-file-name %f [remote_options]'
2019-06-24 23:43:48 +02:00
Where *backup_dir* and *instance_name* refer to the already initialized backup catalog instance for this database cluster and optional parameters [remote_options](#remote-mode-options) should be used to archive WAL to the remote machine.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Once these steps are complete, you can start taking FULL, PAGE, DELTA and PTRACK backups in ARCHIVE mode.
2019-06-13 16:32:43 +02:00
2019-06-24 23:52:03 +02:00
>NOTE: Instead of `archive_mode`+`archive_command` method you may opt to use the utility [pg_receivewal](https://www.postgresql.org/docs/current/app-pgreceivewal.html). In this case pg_receivewal `-D directory` option should point to '*backup_dir*/wal/*instance_name*' directory. WAL compression that could be done by pg_receivewal is supported by pg_probackup. `Zero data loss` archive strategy can be achieved only by using pg_receivewal.
2019-06-20 19:49:42 +02:00
2019-06-23 04:05:01 +02:00
#### Backup from Standby
2019-06-13 16:32:43 +02:00
2019-06-13 16:49:02 +02:00
For PostgreSQL 9.6 or higher, pg_probackup can take backups from a standby server. This requires the following additional setup:
2019-06-13 16:32:43 +02:00
2019-06-23 15:46:30 +02:00
- On the standby server, set the parameter [hot_standby](https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-HOT-STANDBY) to `on`.
- On the master server, set the parameter [full_page_writes](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-FULL-PAGE-WRITES) to `on`.
2019-06-20 19:49:42 +02:00
- To perform STREAM backup on standby, complete all steps in section [Setting up STREAM Backups](#setting-up-stream-backups)
2019-06-23 04:05:01 +02:00
- To perform ARCHIVE backup on standby, complete all steps in section [Setting up continuous WAL archiving](#setting-up-continuous-wal-archiving)
2019-06-13 16:32:43 +02:00
2019-06-23 15:46:30 +02:00
Once these steps are complete, you can start taking FULL, PAGE, DELTA or PTRACK backups of appropriate WAL delivery method: ARCHIVE or STREAM, from the standby server.
2019-06-13 16:32:43 +02:00
Backup from the standby server has the following limitations:
2019-06-24 23:43:48 +02:00
2019-06-20 19:49:42 +02:00
- If the standby is promoted to the master during backup, the backup fails.
2019-06-24 23:43:48 +02:00
- All WAL records required for the backup must contain sufficient full-page writes. This requires you to enable `full_page_writes` on the master, and not to use a tools like pg_compresslog as [archive_command](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-COMMAND) to remove full-page writes from WAL files.
2019-06-13 16:32:43 +02:00
#### Setting up Cluster Verification
2019-06-24 23:43:48 +02:00
Logical verification of database cluster requires the following additional setup. Role *backup* is used as an example:
- Install extension `amcheck` or `amcheck_next` in every database of the cluster:
CREATE EXTENSION amcheck;
- To perform logical verification the following rights are requiared:
2019-06-24 23:43:48 +02:00
```
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(oid) TO backup;
GRANT EXECUTE ON FUNCTION bt_index_check(oid, bool) TO backup;
```
2019-06-23 04:05:01 +02:00
#### Setting up PTRACK Backups
2019-06-13 16:32:43 +02:00
If you are going to use PTRACK backups, complete the following additional steps:
2019-06-24 23:43:48 +02:00
2019-06-20 19:49:42 +02:00
- Set the parameter `ptrack_enable` to `on`.
2019-06-24 23:43:48 +02:00
- Grant the rights to execute ptrack functions to the *backup* role:
2019-06-13 16:49:02 +02:00
GRANT EXECUTE ON FUNCTION pg_ptrack_clear() TO backup;
GRANT EXECUTE ON FUNCTION pg_ptrack_get_and_clear(oid, oid) TO backup;
2019-06-24 23:43:48 +02:00
- The *backup* role must have access to all the databases of the cluster.
2019-06-13 16:32:43 +02:00
### Command-Line Reference
2019-06-23 04:05:01 +02:00
#### Commands
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
This section describes pg_probackup commands. Some commands require mandatory parameters and can take additional options. Optional parameters encased in square brackets. For detailed descriptions of options, see the section [Options](#options).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### version
2019-06-23 04:05:01 +02:00
pg_probackup version
Prints pg_probackup version.
2019-06-23 11:32:49 +02:00
##### help
2019-06-23 04:05:01 +02:00
pg_probackup help [command]
Displays the synopsis of pg_probackup commands. If one of the pg_probackup commands is specified, shows detailed information about the options that can be used with this command.
2019-06-23 11:32:49 +02:00
##### init
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup init -B backup_dir [--help]
2019-06-23 04:05:01 +02:00
2019-06-24 23:43:48 +02:00
Initializes the backup catalog in *backup_dir* that will store backup copies, WAL archive and meta information for the backed up database clusters. If the specified *backup_dir* already exists, it must be empty. Otherwise, pg_probackup displays a corresponding error message.
For details, see the secion [Initializing the Backup Catalog](#initializing-the-backup-catalog).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### add-instance
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup add-instance -B backup_dir -D data_dir --instance instance_name
[--help] [--external-dirs=external_directory_path]
2019-06-23 04:05:01 +02:00
2019-06-24 23:43:48 +02:00
Initializes a new backup instance inside the backup catalog backup_dir and generates the pg_probackup.conf configuration file that controls backup and restore settings for the cluster with the specified data_dir data directory.
For details, see the section [Adding a New Backup Instance](#adding-a-new-backup-instance).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### del-instance
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup del-instance -B backup_dir --instance instance_name
[--help]
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
Deletes all backups and WAL files associated with the specified instance.
2019-06-23 04:05:01 +02:00
2019-06-23 11:32:49 +02:00
##### set-config
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup set-config -B backup_dir --instance instance_name
[--help] [--pgdata=pgdata-path]
2019-06-13 16:32:43 +02:00
[--retention-redundancy=redundancy][--retention-window=window]
[--compress-algorithm=compression_algorithm] [--compress-level=compression_level]
[-d dbname] [-h host] [-p port] [-U username]
[--archive-timeout=timeout] [--external-dirs=external_directory_path]
2019-06-24 00:41:05 +02:00
[remote_options] [logging_options]
2019-06-23 04:05:01 +02:00
2019-06-23 11:32:49 +02:00
Adds the specified connection, compression, retention, logging and external directory settings into the pg_probackup.conf configuration file, or modifies the previously defined values.
2019-06-24 23:43:48 +02:00
2019-06-23 19:34:45 +02:00
It is **not recommended** to edit pg_probackup.conf manually.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### show-config
2019-06-13 16:49:02 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup show-config -B backup_dir --instance instance_name [--format=plain|json]
2019-06-23 04:05:01 +02:00
2019-06-24 23:52:03 +02:00
Displays the contents of the pg_probackup.conf configuration file located in the '*backup_dir*/backups/*instance_name*' directory. You can specify the `--format=json` option to return the result in the JSON format. By default, configuration settings are shown as plain text.
2019-06-24 23:43:48 +02:00
2019-06-23 19:34:45 +02:00
To edit pg_probackup.conf, use the [set-config](#set-config) command.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### show
2019-06-23 04:05:01 +02:00
pg_probackup show -B backup_dir
[--help] [--instance instance_name [-i backup_id]] [--format=plain|json]
2019-06-24 23:43:48 +02:00
Shows the contents of the backup catalog. If *instance_name* and *backup_id* are specified, shows detailed information about this backup. You can specify the `--format=json` option to return the result in the JSON format.
By default, the contents of the backup catalog is shown as plain text.
2019-06-23 04:05:01 +02:00
2019-06-23 11:32:49 +02:00
##### backup
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup backup -B backup_dir -b backup_mode --instance instance_name
[--help] [-j num_threads] [--progress]
[-C] [--stream [-S slot_name] [--temp-slot]] [--backup-pg-log]
[--no-validate] [--skip-block-validation]
2019-06-13 16:32:43 +02:00
[-w --no-password] [-W --password]
2019-06-20 19:49:42 +02:00
[--archive-timeout=timeout] [--external-dirs=external_directory_path]
2019-06-24 00:41:05 +02:00
[connection_options] [compression_options] [remote_options]
[retention_options] [logging_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Creates a backup copy of the PostgreSQL instance. The *backup_mode* option specifies the backup mode to use.
2019-06-23 19:34:45 +02:00
For details, see the sections [Backup Options](#backup-options) and [Creating a Backup](#creating-a-backup).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### restore
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup restore -B backup_dir --instance instance_name
[--help] [-D data_dir] [-i backup_id]
2019-06-13 16:32:43 +02:00
[-j num_threads] [--progress]
2019-06-20 19:49:42 +02:00
[-T OLDDIR=NEWDIR] [--external-mapping=OLDDIR=NEWDIR] [--skip-external-dirs]
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation]
2019-06-24 00:41:05 +02:00
[recovery_options] [logging_options] [remote_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Restores the PostgreSQL instance from a backup copy located in the *backup_dir* backup catalog. If you specify a recovery target option, pg_probackup will find the closest backup and restores it to the specified recovery target. Otherwise, the most recent backup is used.
2019-06-23 22:39:47 +02:00
For details, see the sections [Restore Options](#restore-options), [Recovery Target Options](#recovery-target-options) and [Restoring a Cluster](#restoring-a-cluster).
2019-06-13 16:32:43 +02:00
##### checkdb
pg_probackup checkdb
[-B backup_dir] [--instance instance_name] [-D data_dir]
[--help] [-j num_threads] [--progress]
[--skip-block-validation] [--amcheck] [--heapallindexed]
2019-06-24 00:41:05 +02:00
[connection_options] [logging_options]
Verifyes the PostgreSQL database cluster correctness by detecting physical and logical corruption.
For details, see the sections [Checkdb Options](#checkdb-options) and [Verifying a Cluster](#verifying-a-cluster).
2019-06-23 11:32:49 +02:00
##### validate
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup validate -B backup_dir
[--help] [--instance instance_name] [-i backup_id]
2019-06-13 16:32:43 +02:00
[-j num_threads] [--progress]
2019-06-20 19:49:42 +02:00
[--skip-block-validation]
2019-06-24 00:41:05 +02:00
[recovery_options] [logging_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Verifies that all the files required to restore the cluster are present and not corrupted. If *instance_name* is not specified, pg_probackup validates all backups available in the backup catalog. If you specify the *instance_name* without any additional options, pg_probackup validates all the backups available for this backup instance. If you specify the *instance_name* with a [recovery target option](#recovery-target-options) and/or a *backup_id*, pg_probackup checks whether it is possible to restore the cluster using these options.
2019-06-23 19:34:45 +02:00
For details, see the section [Validating a Backup](#validating-a-backup).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### merge
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
pg_probackup merge -B backup_dir --instance instance_name -i backup_id
[--help] [-j num_threads][--progress]
[logging_options]
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Merges the specified incremental backup to its parent full backup, together with all incremental backups between them, if any. As a result, the full backup takes in all the merged data, and the incremental backups are removed as redundant.
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
For details, see the section [Merging Backups](#merging-backups).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### delete
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name
[--help] [-j num_threads] [--progress]
[--delete-wal] {-i backup_id | --delete-expired [--merge-expired] | --merge-expired}
[--dry-run]
2019-06-23 04:05:01 +02:00
[logging_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Deletes backup with specified *backip_id* or launches the retention purge of backups and archived WAL that do not satisfy the current retention policies.
2019-06-23 04:05:01 +02:00
For details, see the sections [Deleting Backups](#deleting-backups), [Retention Options](#retention-otions) and [Configuring Backup Retention Policy](#configuring-backup-retention-policy).
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### archive-push
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup archive-push -B backup_dir --instance instance_name
--wal-file-path %p --wal-file-name %f
[--help] [--compress] [--compress-algorithm=compression_algorithm]
[--compress-level=compression_level] [--overwrite]
2019-06-24 00:41:05 +02:00
[remote_options] [logging_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Copies WAL files into the corresponding subdirectory of the backup catalog and validates the backup instance by *instance_name* and *system-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.” For each WAL file moved to the backup catalog, you will see the following message in PostgreSQL logfile: “pg_probackup archive-push completed successfully”.
If the files to be copied already exist in the backup catalog, pg_probackup computes and compares their checksums. If the checksums match, archive-push skips the corresponding file and returns 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 the archive-push command with the `--overwrite` option.
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
Copying is done to temporary file with `.partial` suffix or, if [compression](#compression-options) is used, with `.gz.partial` suffix. After copy is done, atomic rename is performed. This algorihtm ensures that failed archive-push will not stall continuous archiving and that concurrent archiving from multiple sources into single WAL archive has no risk of archive corruption.
Copied to archive WAL segments are synced to disk.
2019-06-13 16:32:43 +02:00
2019-06-23 22:39:47 +02:00
You can use `archive-push` in [archive_command](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-COMMAND) PostgreSQL parameter to set up [continous WAl archiving](#setting-up-continuous-wal-archiving).
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
For details, see section [Archiving Options](#archiving-options)
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### archive-get
2019-06-13 16:32:43 +02:00
2019-06-24 00:41:05 +02:00
pg_probackup archive-get -B backup_dir --instance instance_name --wal-file-path %p --wal-file-name %f
[--help] [remote_options] [logging_options]
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Copies WAL files from the corresponding subdirectory of the backup catalog to the cluster's write-ahead log location. This command is automatically set by pg_probackup as part of the `restore_command` in 'recovery.conf' when restoring backups using a WAL archive. You do not need to set it manually.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Options
2019-06-13 16:32:43 +02:00
2019-06-23 19:34:45 +02:00
This section describes all command-line options for pg_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 the pg_probackup.conf configuration file located in the backup catalog.
For details, see the section [Configuring pg_probackup](#configuring-pg_probackup).
2019-06-13 16:32:43 +02:00
If an option is specified using more than one method, command-line input has the highest priority, while the pg_probackup.conf settings have the lowest priority.
2019-06-23 11:32:49 +02:00
##### Common Options
2019-06-20 19:49:42 +02:00
The list of general options.
2019-06-23 04:05:01 +02:00
2019-06-13 16:32:43 +02:00
-B directory
--backup-path=directory
BACKUP_PATH
2019-06-24 23:43:48 +02:00
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 the pg_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.
2019-06-13 16:32:43 +02:00
-D directory
--pgdata=directory
PGDATA
2019-06-23 19:34:45 +02:00
Specifies the absolute path to the data directory of the database cluster. This option is mandatory only for the [add-instance](#add-instance) command. Other commands can take its value from the PGDATA environment variable, or from the pg_probackup.conf configuration file.
2019-06-13 16:32:43 +02:00
-i backup_id
-backup-id=backup_id
2019-06-20 19:49:42 +02:00
Specifies the unique identifier of the backup.
2019-06-13 16:32:43 +02:00
-j num_threads
--threads=num_threads
2019-06-23 04:05:01 +02:00
Sets the number of parallel threads for backup, restore, merge, validation and verification processes.
2019-06-13 16:32:43 +02:00
--progress
2019-06-20 19:49:42 +02:00
Shows the progress of operations.
--help
Shows detailed information about the options that can be used with this command.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Backup Options
2019-06-13 16:32:43 +02:00
2019-06-23 19:34:45 +02:00
The following options can be used together with the [backup](#backup) command. Additionally [Connection Options](#connection-options), [Retention Options](#retention-options), [Remote Mode Options](#remote-mode-options), [Compression Options](#compression-options), [Logging Options](#logging-options) and [Common Options](#common-options) can be used.
2019-06-13 16:32:43 +02:00
-b mode
--backup-mode=mode
Specifies the backup mode to use. Possible values are:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- FULL — creates a full backup that contains all the data files of the cluster to be restored.
- DELTA — reads all data files in the data directory and creates an incremental backup for pages that have changed since the previous backup.
- PAGE — creates an incremental PAGE backup based on the WAL files that have changed since the previous full or incremental backup was taken.
- PTRACK — creates an incremental PTRACK backup tracking page changes on the fly.
2019-06-23 19:34:45 +02:00
For details, see the section [Creating a Backup](#creating-a-backup).
2019-06-13 16:32:43 +02:00
-C
--smooth-checkpoint
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
2019-06-23 04:05:01 +02:00
Makes an STREAM backup that includes all the necessary WAL files by streaming them from the database server via replication protocol.
2019-06-13 16:32:43 +02:00
-S slot_name
--slot=slot_name
2019-06-23 19:34:45 +02:00
Specifies the replication slot for WAL streaming. This option can only be used together with the `--stream` option.
2019-06-13 16:32:43 +02:00
--temp-slot
Creates a temporary physical replication slot for streaming WAL from the backed up PostgreSQL instance. It ensures that all the required WAL segments remain available if WAL is rotated while the backup is in progress. This option can only be used together with the `--stream` option. Default slot name is `pg_probackup_slot`, which can be changed via option `-S / --slot`.
2019-06-13 16:32:43 +02:00
--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
2019-06-23 19:34:45 +02:00
Includes the specified directory into the backup. This option is useful to back up scripts, sql dumps 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.
2019-06-13 16:32:43 +02:00
--archive-timeout=wait_time
2019-06-20 19:49:42 +02:00
Sets in seconds the timeout for WAL segment archiving and streaming. By default pg_probackup waits 300 seconds.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
--skip-block-validation
Disables block-level checksum verification to speed up backup.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
--no-validate
Skips automatic validation after successfull backup. You can use this option if you validate backups regularly and would like to save time when running backup operations.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Restore Options
2019-06-23 22:39:47 +02:00
2019-06-23 19:34:45 +02:00
The following options can be used together with the [restore](#restore) command. Additionally [Recovery Target Options](#recovery-target-options), [Remote Mode Options](#remote-mode-options), [Logging Options](#logging-options) and [Common Options](#common-options) can be used.
2019-06-13 16:32:43 +02:00
-R | --restore-as-replica
Writes a minimal recovery.conf in the output directory to facilitate setting up a standby server. The password is not included. If the replication connection requires a password, you must specify the password manually.
-T OLDDIR=NEWDIR
--tablespace-mapping=OLDDIR=NEWDIR
Relocates the tablespace from the OLDDIR to the NEWDIR directory at the time of recovery. Both OLDDIR and NEWDIR 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 the NEWDIR directory at the time of recovery. Both OLDDIR and NEWDIR 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
2019-06-23 22:39:47 +02:00
Skip external directories included into the backup with the `--external-dirs` option. The contents of these directories will not be restored.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
--skip-block-validation
Disables block-level checksum verification to speed up validation. During automatic validation before restore only file-level checksums will be verified.
2019-06-13 16:32:43 +02:00
--no-validate
2019-06-20 19:49:42 +02:00
Skips backup validation. You can use this option if you validate backups regularly and would like to save time when running restore operations.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
###### Checkdb Options
2019-06-23 23:15:12 +02:00
The following options can be used together with the [checkdb](#checkdb) command. For details on verifying PostgreSQL database cluster, see section [Verifying a Cluster](#verifying-a-cluster).
2019-06-20 19:49:42 +02:00
--amcheck
Performs logical verification of indexes for the specified PostgreSQL instance if no corruption was found while checking data files. You must have the `amcheck` extention or the `amcheck_next` extension installed in the database to check its indexes. For databases without amcheck, index verification will be skipped.
--skip-block-validation
Skip validation of data files. Can be used only with `--amcheck` option, so only logical verification of indexes is performed.
2019-06-20 19:49:42 +02:00
--heapallindexed
Checks that all heap tuples that should be indexed are actually indexed. You can use this option only together with the `--amcheck` option. Can be used only with `amcheck` extension of version 2.0 and `amcheck_next` extension of any version.
2019-06-20 19:49:42 +02:00
2019-06-23 11:32:49 +02:00
##### Recovery Target Options
2019-06-23 22:39:47 +02:00
2019-06-24 00:41:05 +02:00
If [continuous WAL archiving](#setting-up-continuous-wal-archiving) is configured, you can use one of these options together with [restore](#restore) or [validate](#validate) commands to specify the moment up to which the database cluster must be restored or validated.
2019-06-13 16:32:43 +02:00
--recovery-target=immediate|latest
Defines when to stop the recovery:
2019-06-24 23:43:48 +02:00
2019-06-23 23:15:12 +02:00
- `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.
- `latest` value continues the recovery until all WAL segments available in the archive are applied.
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
Default value of `--recovery-target` depends on WAL delivery method of restored backup, `immediate` for STREAM backup and `latest` for ARCHIVE.
2019-06-23 23:16:03 +02:00
2019-06-20 19:49:42 +02:00
--recovery-target-timeline=timeline
Specifies a particular timeline to which recovery will proceed. By default, the timeline of the specified backup is used.
2019-06-13 16:32:43 +02:00
--recovery-target-lsn=lsn
2019-06-20 19:49:42 +02:00
Specifies the LSN of the write-ahead log location up to which recovery will proceed. Can be used only when restoring database cluster of major version 10 or higher.
2019-06-13 16:32:43 +02:00
--recovery-target-name=recovery_target_name
Specifies a named savepoint up to which to restore the cluster data.
--recovery-target-time=time
Specifies the timestamp up to which recovery will proceed.
--recovery-target-xid=xid
2019-06-20 19:49:42 +02:00
Specifies the transaction ID up to which recovery will proceed.
2019-06-13 16:32:43 +02:00
--recovery-target-inclusive=boolean
2019-06-23 22:39:47 +02:00
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-name`, `--recovery-target-time`, `--recovery-target-lsn` or `--recovery-target-xid` options. The default value is taken from the [recovery_target_inclusive](https://www.postgresql.org/docs/current/recovery-target-settings.html#RECOVERY-TARGET-INCLUSIVE) parameter.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
--recovery-target-action=pause|promote|shutdown
Default: pause
Specifies [the action](https://www.postgresql.org/docs/current/recovery-target-settings.html#RECOVERY-TARGET-ACTION) the server should take when the recovery target is reached.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Retention Options
You can use these options together with [backup](#backup) and [delete](#delete) commands. For details on configuring retention policy, see the section [Configuring Backup Retention Policy](#configuring-backup-retention-policy).
2019-06-13 16:32:43 +02:00
--retention-redundancy=redundancy
Default: 0
Specifies the number of full backup copies to keep in the data directory. Must be a positive integer. The zero value disables this setting.
--retention-window=window
Default: 0
2019-06-20 19:49:42 +02:00
Number of days of recoverability. Must be a positive integer. The zero value disables this setting.
--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.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Logging Options
2019-06-20 19:49:42 +02:00
You can use these options with any command.
2019-06-13 16:32:43 +02:00
--log-level-console=log_level
Default: info
Controls which message levels are sent to the console log. Valid values are `verbose`, `log`, `info`, `warning`, `error` and `off`. Each level includes all the levels that follow it. The later the level, the fewer messages are sent. The `off` level disables console logging.
>NOTE: all console log messages are going to stderr, so output from [show](#show) and [show-config](#show-config) commands do not mingle with log messages.
2019-06-13 16:32:43 +02:00
--log-level-file=log_level
Default: off
Controls which message levels are sent to a log file. Valid values are `verbose`, `log`, `info`, `warning`, `error` and `off`. Each level includes all the levels that follow it. The later the level, the fewer messages are sent. The `off` level disables file logging.
2019-06-13 16:32:43 +02:00
--log-filename=log_filename
Default: pg_probackup.log
2019-06-24 23:43:48 +02:00
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, as explained in *log_filename*.
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.
2019-06-23 23:03:24 +02:00
This option takes effect if file logging is enabled by the `log-level-file` option.
2019-06-13 16:32:43 +02:00
--error-log-filename=error_log_filename
2019-06-23 23:03:24 +02:00
Default: none
2019-06-24 23:43:48 +02:00
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, as explained in *error_log_filename*.
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.
2019-06-13 16:32:43 +02:00
--log-directory=log_directory
2019-06-20 19:49:42 +02:00
Default: $BACKUP_PATH/log/
2019-06-13 16:32:43 +02:00
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.
--log-rotation-size=log_rotation_size
Default: 0
Maximum size of an individual log file. If this value is reached, the log file is rotated once a pg_probackup command is launched, except help and version commands. The zero value disables size-based rotation. Supported units: kB, MB, GB, TB (kB by default).
--log-rotation-age=log_rotation_age
2019-06-23 23:03:24 +02:00
Default: 0
2019-06-13 16:32:43 +02:00
Maximum lifetime of an individual log file. If this value is reached, the log file is rotated once a pg_probackup command is launched, except help and version 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).
2019-06-23 11:32:49 +02:00
##### Connection Options
You can use these options together with [backup](#backup) and [checkdb](#checkdb) commands.
2019-06-13 16:32:43 +02:00
-d dbname
--dbname=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 the pg_probackup.conf configuration file, pg_probackup tries to take this value from the PGUSER environment variable, or from the current user name if PGUSER variable is not set.
-h host
--host=host
PGHOST
Default: local socket
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.
-p port
--port=port
PGPORT
Default: 5432
Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.
-U username
--username=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, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.
-W
--password
Forces a password prompt.
2019-06-23 11:32:49 +02:00
##### Compression Options
You can use these options together with [backup](#backup) and [archive-push](#archive-push) commands.
2019-06-13 16:32:43 +02:00
--compress-algorithm=compression_algorithm
2019-06-20 19:49:42 +02:00
Default: none
Defines the algorithm to use for compressing data files. Possible values are zlib, pglz, and none. If set to zlib or pglz, this option enables compression. By default, compression is disabled.
For the `archive-push` command, the pglz compression algorithm is not supported.
2019-06-13 16:32:43 +02:00
--compress-level=compression_level
2019-06-20 19:49:42 +02:00
Default: 1
Defines compression level (0 through 9, 0 being no compression and 9 being best compression). This option can be used together with --compress-algorithm option.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
--compress
Alias for `--compress-algorithm=zlib` and `--compress-level=1`.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Archiving Options
2019-06-23 23:03:24 +02:00
These options can be used with [archive-push](#archive-push) and [archive-get](#archive-get) commands.
2019-06-13 16:32:43 +02:00
--wal-file-path=wal_file_path %p
2019-06-23 22:05:08 +02:00
Provides the path to the WAL file in `archive_command` and `restore_command` used by pg_probackup. The %p variable is required for correct processing.
2019-06-13 16:32:43 +02:00
--wal-file-name=wal_file_name %f
2019-06-23 22:05:08 +02:00
Provides the name of the WAL file in `archive_command` and `restore_command` used by pg_probackup. The %f variable is required for correct processing.
2019-06-13 16:32:43 +02:00
--overwrite
2019-06-23 22:05:08 +02:00
Overwrites archived WAL file. Use this option together with the archive-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` option.
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
##### Remote Mode Options
This section describes the options related to running pg_probackup operations remotely via SSH. These options can be used with [add-instance](#add-instance), [set-config](#set-config), [backup](#backup), [restore](#restore), [archive-push](#archive-push) and [archive-get](#archive-get) commands. For details on configuring remote operation mode, see the section [Using pg_probackup in the Remote Mode](#using-pg_probackup-in-the-remote-mode).
2019-06-13 16:32:43 +02:00
--remote-proto
Specifies the protocol to use for remote operations. Currently only the SSH protocol is supported. Possible values are:
2019-06-24 23:43:48 +02:00
2019-06-23 23:03:24 +02:00
- `ssh` enables the remote backup mode via SSH. This is the Default value.
- `none` explicitly disables the remote mode.
2019-06-13 16:32:43 +02:00
2019-06-23 23:30:00 +02:00
You can omit this option if the `--remote-host` option is specified.
2019-06-13 16:32:43 +02:00
--remote-host
Specifies the remote host IP address or hostname to connect to.
--remote-port
Default: 22
Specifies the remote host port to connect to.
--remote-user
2019-06-20 19:49:42 +02:00
Default: current user
2019-06-13 16:32:43 +02:00
Specifies remote host user for SSH connection. If you omit this option, the current user initiating the SSH connection is used.
--remote-path
2019-06-20 19:49:42 +02:00
Specifies pg_probackup installation directory on the remote system.
2019-06-13 16:32:43 +02:00
--ssh-options
2019-06-20 19:49:42 +02:00
Specifies a string of SSH command-line options.
2019-06-23 11:32:49 +02:00
##### Replica Options
2019-06-20 19:49:42 +02:00
This section describes the options related to taking a backup from standby.
>NOTE: Starting from pg_probackup 2.0.24, backups can be taken from standby without connecting to the master server, so these options are no longer required. In lower versions, pg_probackup had to connect to the master to determine recovery time — the earliest moment for which you can restore a consistent state of the database cluster.
--master-db=dbname
Default: postgres, the default PostgreSQL database.
2019-06-23 19:34:45 +02:00
Deprecated. Specifies the name of the database on the master server to connect to. The connection is used only for managing the backup process, so you can connect to any existing database. Can be set in the pg_probackup.conf using the [set-config](#set-config) command.
2019-06-20 19:49:42 +02:00
--master-host=host
Deprecated. Specifies the host name of the system on which the master server is running.
--master-port=port
Default: 5432, the PostgreSQL default port.
Deprecated. Specifies the TCP port or the local Unix domain socket file extension on which the master server is listening for connections.
--master-user=username
Default: postgres, the PostgreSQL default user name.
Deprecated. User name to connect as.
--replica-timeout=timeout
Default: 300 sec
2019-06-23 19:34:45 +02:00
Deprecated. Wait time for WAL segment streaming via replication, in seconds. By default, pg_probackup waits 300 seconds. You can also define this parameter in the pg_probackup.conf configuration file using the [set-config](#set-config) command.
2019-06-13 16:32:43 +02:00
### Usage
- [Creating a Backup](#creating-a-backup)
- [Verifying a Cluster](#verifying-a-cluster)
2019-06-13 16:32:43 +02:00
- [Validating a Backup](#vaklidating-a-backup)
2019-06-23 04:05:01 +02:00
- [Restoring a Cluster](#restoring-a-cluster)
2019-06-23 19:34:45 +02:00
- [Performing Point-in-Time (PITR) Recovery](#performing-point-in-time-pitr-recovery)
2019-06-20 19:49:42 +02:00
- [Using pg_probackup in the Remote Mode](#using-pg_probackup-in-the-remote-mode)
2019-06-13 16:32:43 +02:00
- [Running pg_probackup on Parallel Threads](#running-pg_probackup-on-parallel-threads)
- [Configuring pg_probackup](#configuring-pg_probackup)
2019-06-23 19:34:45 +02:00
- [Managing the Backup Catalog](#managing-the-backup-catalog)
2019-06-20 19:49:42 +02:00
- [Configuring Backup Retention Policy](#configuring-backup-retention-policy)
- [Merging Backups](#merging-backups)
- [Deleting Backups](#deleting-backups)
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Creating a Backup
2019-06-23 22:09:09 +02:00
2019-06-13 16:32:43 +02:00
To create a backup, run the following command:
2019-06-23 15:46:30 +02:00
pg_probackup backup -B backup_dir --instance instance_name -b backup_mode
2019-06-23 04:05:01 +02:00
2019-06-24 23:43:48 +02:00
Where *backup_mode* can take one of the following values:
2019-06-13 16:32:43 +02:00
- FULL — creates a full backup that contains all the data files of the cluster to be restored.
- DELTA — reads all data files in the data directory and creates an incremental backup for pages that have changed since the previous backup.
- PAGE — creates an incremental PAGE backup based on the WAL files that have changed since the previous full or incremental backup was taken.
- PTRACK — creates an incremental PTRACK backup tracking page changes on the fly.
When restoring a cluster from an incremental backup, pg_probackup relies on the previous full backup to restore all the data files first. Thus, you must create at least one full backup before taking incremental ones.
##### Page validation
2019-06-23 12:11:10 +02:00
If [data checksums](https://www.postgresql.org/docs/current/runtime-config-preset.html#GUC-DATA-CHECKSUMS) are enabled in the database cluster, pg_probackup uses this information to check correctness of data files. While reading each page, pg_probackup checks whether the calculated checksum coincides with the checksum stored in the page header. This guarantees that the PostgreSQL instance and backup itself are free of corrupted pages.
2019-06-23 04:05:01 +02:00
Note that pg_probackup reads database files directly from filesystem, so under heavy write load during backup it can show false positive checksum failures because of partial writes. In case of page checksumm mismatch, page is readed again and checksumm comparison repeated.
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
Page is considered corrupted if checksumm comparison failed more than 100 times, is this case backup is aborted.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Redardless of data checksums been enabled or not, pg_probackup always check page header "sanity".
2019-06-23 22:09:09 +02:00
##### STREAM mode
2019-06-23 04:05:01 +02:00
To make a STREAM backup, add the `--stream` option to the above command. For example, to create a full STREAM backup, run:
2019-06-13 16:32:43 +02:00
2019-06-23 23:39:44 +02:00
pg_probackup backup -B backup_dir --instance instance_name -b FULL --stream --temp-slot
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
The optional `--temp-slot` parameter ensures that the required segments remain available if the WAL is rotated before the backup is complete.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
STREAM backups include all the WAL segments required to restore the cluster to a consistent state at the time the backup was taken. To restore a cluster from an incremental STREAM backup, pg_probackup still requires the full backup and all the incremental backups it depends on.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Even if you are using [continuous archiving](#setting-up-continuous-wal-archiving), STREAM backups can still be useful in the following cases:
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
1. STREAM backups can be restored on the server that has no file access to WAL archive.
2. STREAM backups enable you to restore the cluster state at the point in time for which WAL files are no longer available.
2019-06-23 12:11:10 +02:00
3. Creating backup from standby of a server that generates small amount of WAL traffic and using [archive_timeout](https://www.postgresql.org/docs/9.6/runtime-config-wal.html#GUC-ARCHIVE-TIMEOUT) is not an option.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
##### External directories
2019-06-24 23:43:48 +02:00
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, provide several paths separated by colons.
For example, to include '/etc/dir1/' and '/etc/dir2/' directories into the full backup of your *instance_name* instance that will be stored under the *backup_dir* directory, run:
2019-06-13 16:32:43 +02:00
pg_probackup backup -B backup_dir --instance instance_name -b FULL --external-dirs=/etc/dir1:/etc/dir2
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
pg_probackup creates a separate subdirectory in the backup directory for each external directory. 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 the pg_probackup.conf configuration file using the `set-config` command with the `--external-dirs` option.
2019-06-13 16:32:43 +02:00
#### Verifying a Cluster
2019-06-23 22:09:09 +02:00
To verify that PostgreSQL database cluster is free of corruption, run the following command:
2019-06-24 00:41:05 +02:00
pg_probackup checkdb [-B backup_dir [--instance instance_name]] [-D data_dir]
This physical verification works similar to [page validation](#page-validation) that is done during backup with several differences:
2019-06-24 23:43:48 +02:00
2019-06-23 22:05:08 +02:00
- `checkdb` is read-only
- if corrupted page is detected, `checkdb` is not aborted, but carry on, until all pages in the cluster are validated
2019-06-24 23:43:48 +02:00
- `checkdb` do not strictly require the backup catalog, so it can be used to verify database clusters that are **not** [added to the backup catalog](#adding-a-new-backup-instance).
2019-06-24 23:43:48 +02:00
If *backup_dir* and *instance_name* are omitted, then [connection options](#connection-options) and *data_dir* must be provided via environment variables or command-line options.
2019-06-24 00:41:05 +02:00
Physical verification cannot detect logical inconsistencies, missing and nullified blocks or entire files, repercussions from PostgreSQL bugs and other wicked anomalies.
Extensions [amcheck](https://www.postgresql.org/docs/current/amcheck.html) and [amcheck_next](https://github.com/petergeoghegan/amcheck) 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 `--amcheck` option when running [checkdb](#checkdb) command:
pg_probackup checkdb -D data_dir --amcheck
2019-06-24 23:43:48 +02:00
Physical verification can be skipped if `--skip-block-validation` option is used. For logical only verification *backup_dir* and *data_dir* are optional, only [connection options](#connection-options) are mandatory:
2019-06-24 00:41:05 +02:00
pg_probackup checkdb --amcheck --skip-block-validation [connection options]
Logical verification can be done more thoroughly with option `--heapallindexed` by checking that all heap tuples that should be indexed are actually indexed, but at the higher cost of CPU, memory and I/O comsumption.
2019-06-23 04:05:01 +02:00
#### Validating Backups
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
pg_probackup calculates checksums for each file in a backup during `backup` process. The process of checking checksumms of backup data files is called `backup validation`. By default validation is run immediately after backup is taken and right before restore, to detect possible backup corruptions.
If you would like to skip backup validation, you can specify the `--no-validate` option when running `backup` and `restore` commands.
2019-06-13 16:32:43 +02:00
To ensure that all the required backup files are present and can be used to restore the database cluster, you can run the [validate](#validate) command with the exact recovery target options you are going to use for recovery. If you omit all the parameters, all backups are validated.
2019-06-13 16:32:43 +02:00
For example, to check that you can restore the database cluster from a backup copy up to the specified xid transaction ID, run this command:
2019-06-20 19:49:42 +02:00
pg_probackup validate -B backup_dir --instance instance_name --recovery-target-xid=xid
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
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.
#### Restoring a Cluster
2019-06-13 16:32:43 +02:00
To restore the database cluster from a backup, run the restore command with at least the following options:
2019-06-20 19:49:42 +02:00
pg_probackup restore -B backup_dir --instance instance_name -i backup_id
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Where:
2019-06-24 23:43:48 +02:00
- *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.
2019-06-13 16:32:43 +02:00
2019-06-24 00:41:05 +02:00
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.
2019-06-13 16:32:43 +02:00
2019-06-24 00:41:05 +02:00
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:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup restore -B backup_dir --instance instance_name -D data_dir -j 4 -i backup_id -T tablespace1_dir=tablespace1_newdir -T tablespace2_dir=tablespace2_newdir
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Once the restore command is complete, start the database service. If you are restoring an 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, PostgreSQL replays all available archived WAL segments, so the cluster is restored to the latest state possible. You can change this behavior by using the [recovery target options](#recovery-target-options) with the `restore` command. Note that using the [recovery target options](#recovery-target-options) when restoring STREAM backup is possible if the WAL archive is available at least starting from the time the STREAM backup was taken.
2019-06-13 16:32:43 +02:00
2019-06-23 22:05:08 +02:00
>NOTE: By default, the [restore](#restore) 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` option to skip validation and speed up the recovery.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
#### Performing Point-in-Time (PITR) Recovery
2019-06-24 23:43:48 +02:00
If you have enabled [continuous WAL archiving](#setting-up-continuous-wal-archiving) before taking backups, you can restore the cluster to its state at an arbitrary point in time (recovery target) using [recovery target options](#recovery-target-options) with the [restore](#restore) and [validate](#validate) commands.
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, otherwise pg_probackup will try to restore *backup_id* to the specified recovery target.
2019-06-13 16:32:43 +02:00
- To restore the cluster state at the exact time, specify the recovery-target-time option, in the timestamp format. For example:
2019-06-23 04:05:01 +02:00
pg_probackup restore -B backup_dir --instance instance_name --recovery-target-time='2017-05-18 14:18:11+03'
2019-06-13 16:32:43 +02:00
- To restore the cluster state up to a specific transaction ID, use the recovery-target-xid option:
2019-06-20 19:49:42 +02:00
pg_probackup restore -B backup_dir --instance instance_name --recovery-target-xid=687
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
- To restore the cluster state up to a specific LSN, use recovery-target-lsn:
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
pg_probackup restore -B backup_dir --instance instance_name --recovery-target-lsn=16/B374D848
2019-06-13 16:32:43 +02:00
2019-06-24 00:41:05 +02:00
- To restore the cluster state up to a specific named restore point, use recovery-target-name:
pg_probackup restore -B backup_dir --instance instance_name --recovery-target-name='before_app_upgrade'
- To restore the cluster to the latest state available in archive, use recovery-target option:
pg_probackup restore -B backup_dir --instance instance_name --recovery-target='latest'
2019-06-20 19:49:42 +02:00
##### Using pg_probackup in the Remote Mode
2019-06-13 16:32:43 +02:00
2019-06-23 11:32:49 +02:00
pg_probackup supports the remote mode that allows to perform `backup` and `restore` operations remotely via SSH. In this mode, the backup catalog is stored on a local system, while PostgreSQL instance to be backed up is located on a remote system. You must have pg_probackup installed on both systems.
2019-06-13 16:32:43 +02:00
The typical workflow is as follows:
- On your local system, configure pg_probackup as explained in the section [Installation and Setup](#installation-and-setup). For the [add-instance](#add-instance) and [set-config](#set-config) commands, make sure to specify [remote options](#remote-mode-options) that point to the remote server with the PostgreSQL instance.
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
- If you would like to take ARCHIVE backups, configure continuous WAL archiving on the remote system as explained in the section [Setting up continuous WAL archiving](#setting-up-continuous-wal-archiving). For the [archive-push](#archive-push) and [archive-get](#archive-get) commands, you must specify the [remote options](#remote-mode-options) that point to host with backup catalog.
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
- Run [backup](#backup) or [restore](#restore) commands with remote options on system with backup catalog. 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.
2019-06-13 16:32:43 +02:00
>NOTE: The remote backup mode is currently unavailable for Windows systems.
##### Running pg_probackup on Parallel Threads
2019-06-23 23:39:44 +02:00
[Backup](#backup), [restore](#restore), [merge](#merge), [delete](#delete), [checkdb](#checkdb) and [validate](#validate) processes can be executed on several parallel threads. This can significantly speed up pg_probackup operation given enough resources (CPU cores, disk, and network throughput).
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Parallel execution is controlled by the `-j/--threads` command line option. For example, to create a backup using four parallel threads, run:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup backup -B backup_dir --instance instance_name -b FULL -j 4
2019-06-13 16:32:43 +02:00
2019-06-23 19:34:45 +02:00
>NOTE: Parallel restore applies only to copying data from the backup catalog to the data directory of the cluster. When PostgreSQL server is started, WAL records need to be replayed, and this cannot be done in parallel.
2019-06-13 16:32:43 +02:00
##### Configuring pg_probackup
2019-06-24 23:52:03 +02:00
Once the backup catalog is initialized and a new backup instance is added, you can use the pg_probackup.conf configuration file located in the '*backup_dir*/backups/*instance_name*' directory to fine-tune pg_probackup configuration.
2019-06-13 16:32:43 +02:00
2019-06-23 19:34:45 +02:00
For example, [backup](#backup) and [checkdb](#checkdb) commands uses a regular PostgreSQL connection. To avoid specifying these options each time on the command line, you can set them in the pg_probackup.conf configuration file using the [set-config](#set-config) command.
>NOTE: It is **not recommended** to edit pg_probackup.conf manually.
2019-06-20 19:49:42 +02:00
2019-06-13 16:32:43 +02:00
Initially, pg_probackup.conf contains the following settings:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- PGDATA — the path to the data directory of the cluster to back up.
2019-06-23 19:34:45 +02:00
- system-identifier — the unique identifier of the PostgreSQL instance.
2019-06-13 16:32:43 +02:00
Additionally, you can define [remote](#remote-mode-options), [retention](#retention-options), [logging](#logging-options) and [compression](#compression-options) settings using the `set-config` command:
2019-06-13 16:32:43 +02:00
2019-06-23 19:34:45 +02:00
pg_probackup set-config -B backup_dir --instance instance_name
[--external-dirs=external_directory_path] [remote_options] [connection_options] [retention_options] [logging_options]
2019-06-13 16:32:43 +02:00
To view the current settings, run the following command:
2019-06-20 19:49:42 +02:00
pg_probackup show-config -B backup_dir --instance instance_name
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
You can override the settings defined in pg_probackup.conf when running the backup command via corresponding environment variables and/or command line options.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
###### Specifying Connection Settings
2019-06-13 16:32:43 +02:00
2019-06-24 23:52:03 +02:00
If you define connection settings in the *pg_probackup.conf* configuration file, you can omit connection options in all the subsequent pg_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.
2019-06-13 16:32:43 +02:00
2019-06-23 23:03:24 +02:00
If nothing is given, the default values are taken. By default pg_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 the PGUSER environment variable or the current OS user name.
2019-06-13 16:32:43 +02:00
##### Managing the Backup Catalog
With pg_probackup, you can manage backups from the command line:
- View available backups
2019-06-23 11:32:49 +02:00
- Validate backups
2019-06-13 16:32:43 +02:00
- Merge backups
2019-06-23 11:32:49 +02:00
- Delete backups
2019-06-13 16:32:43 +02:00
- Viewing Backup Information
2019-06-20 19:49:42 +02:00
To view the list of existing backups for every instance, run the command:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup show -B backup_dir
2019-06-13 16:32:43 +02:00
pg_probackup displays the list of all the available backups. For example:
```
BACKUP INSTANCE 'node'
============================================================================================================================================
Instance Version ID Recovery time Mode WAL Current/Parent TLI Time Data Start LSN Stop LSN Status
============================================================================================================================================
node 10 P7XDQV 2018-04-29 05:32:59+03 DELTA STREAM 1 / 1 11s 19MB 0/15000060 0/15000198 OK
node 10 P7XDJA 2018-04-29 05:28:36+03 PTRACK STREAM 1 / 1 21s 32MB 0/13000028 0/13000198 OK
node 10 P7XDHU 2018-04-29 05:27:59+03 PAGE STREAM 1 / 1 31s 33MB 0/11000028 0/110001D0 OK
2019-06-13 16:32:43 +02:00
node 10 P7XDHB 2018-04-29 05:27:15+03 FULL STREAM 1 / 0 11s 39MB 0/F000028 0/F000198 OK
```
For each backup, the following information is provided:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- Instance — the instance name.
2019-06-20 19:49:42 +02:00
- Version — PostgreSQL major version.
2019-06-13 16:32:43 +02:00
- 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 — the way of WAL log handling. Possible values: STREAM for autonomous backups and ARCHIVE for archive backups.
2019-06-20 19:49:42 +02:00
- Current/Parent TLI — timeline identifiers of current backup and its parent.
2019-06-13 16:32:43 +02:00
- 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.
- Start LSN — WAL log sequence number corresponding to the start of the backup process.
- Stop LSN — WAL log sequence number corresponding to the end of the backup process.
- Status — backup status. Possible values:
2019-06-24 23:43:48 +02:00
2019-06-13 16:32:43 +02:00
- OK — the backup is complete and valid.
- RUNNING — the backup is in progress.
2019-06-20 19:49:42 +02:00
- DONE — the backup is complete, but was not validated.
2019-06-13 16:32:43 +02:00
- MERGING — the backup is being merged.
- DELETING — the backup files are being deleted.
2019-06-20 19:49:42 +02:00
- CORRUPT — some of the backup files are corrupted.
- 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.
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
You can restore the cluster from the backup only if the backup status is OK or DONE.
2019-06-13 16:32:43 +02:00
To get more detailed information about the backup, run the show with the backup ID:
2019-06-20 19:49:42 +02:00
pg_probackup show -B backup_dir --instance instance_name -i backup_id
2019-06-13 16:32:43 +02:00
The sample output is as follows:
2019-06-24 23:43:48 +02:00
2019-06-13 16:49:02 +02:00
```
#Configuration
2019-06-13 16:32:43 +02:00
backup-mode = FULL
stream = false
2019-06-20 19:49:42 +02:00
compress-alg = zlib
compress-level = 1
from-replica = false
2019-06-13 16:32:43 +02:00
#Compatibility
block-size = 8192
wal-block-size = 8192
2019-06-20 19:49:42 +02:00
checksum-version = 1
program-version = 2.1.3
server-version = 10
2019-06-13 16:32:43 +02:00
#Result backup info
timelineid = 1
start-lsn = 0/04000028
stop-lsn = 0/040000f8
start-time = '2017-05-16 12:57:29'
end-time = '2017-05-16 12:57:31'
recovery-xid = 597
recovery-time = '2017-05-16 12:57:31'
data-bytes = 22288792
2019-06-20 19:49:42 +02:00
wal-bytes = 16777216
2019-06-13 16:32:43 +02:00
status = OK
2019-06-20 19:49:42 +02:00
parent-backup-id = 'PT8XFX'
primary_conninfo = 'user=backup passfile=/var/lib/pgsql/.pgpass port=5432 sslmode=disable sslcompression=1 target_session_attrs=any'
```
To get more detailed information about the backup in json format, run the show with the backup ID:
pg_probackup show -B backup_dir --instance instance_name --format=json -i backup_id
The sample output is as follows:
2019-06-24 23:43:48 +02:00
2019-06-20 19:49:42 +02:00
```
[
{
"instance": "node",
"backups": [
{
"id": "PT91HZ",
"parent-backup-id": "PT8XFX",
"backup-mode": "DELTA",
"wal": "ARCHIVE",
"compress-alg": "zlib",
"compress-level": 1,
"from-replica": false,
"block-size": 8192,
"xlog-block-size": 8192,
"checksum-version": 1,
"program-version": "2.1.3",
"server-version": "10",
"current-tli": 16,
"parent-tli": 2,
"start-lsn": "0/8000028",
"stop-lsn": "0/8000160",
"start-time": "2019-06-17 18:25:11+03",
"end-time": "2019-06-17 18:25:16+03",
"recovery-xid": 0,
"recovery-time": "2019-06-17 18:25:15+03",
"data-bytes": 106733,
"wal-bytes": 16777216,
"primary_conninfo": "user=backup passfile=/var/lib/pgsql/.pgpass port=5432 sslmode=disable sslcompression=1 target_session_attrs=any",
"status": "OK"
}
]
}
]
2019-06-13 16:49:02 +02:00
```
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
##### Configuring Backup Retention Policy
By default, all backup copies created with pg_probackup are stored in the specified backup catalog. To save disk space, you can configure retention policy and periodically clean up redundant backup copies accordingly.
2019-06-24 23:52:03 +02:00
To configure retention policy, set one or more of the following variables in the pg_probackup.conf file via [set-config](#set-config):
2019-06-24 23:43:48 +02:00
2019-06-20 19:49:42 +02:00
- retention-redundancy — specifies the number of full backup copies to keep in the backup catalog.
- retention-window — defines the earliest point in time for which pg_probackup can complete the recovery. This option is set in the number of days from the current moment. For example, if retention-window=7, pg_probackup must keep at least one full backup copy that is older than seven days, with all the corresponding WAL files.
If both retention-redundancy and retention-window options are set, pg_probackup keeps backup copies that satisfy at least one condition. For example, if you set retention-redundancy=2 and retention-window=7, pg_probackup cleans up the backup directory to keep only two full backup copies and all backups that are newer than seven days.
To clean up the backup catalog in accordance with retention policy, run:
pg_probackup delete -B backup_dir --instance instance_name --delete-expired
pg_probackup deletes all backup copies that do not conform to the defined retention policy.
2019-06-24 23:43:48 +02:00
If you would like to also remove the WAL files that are no longer required for any of the backups, add the `--delete-wal` option:
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name --delete-expired --delete-wal
>NOTE: Alternatively, you can use the --delete-expired, --merge-expired and --delete-wal options together with the `backup` command to remove and merge the outdated backup copies once the new backup is created.
2019-06-24 23:43:48 +02:00
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` option when running [backup](#backup) or [delete](#delete) commands.
2019-06-20 19:49:42 +02:00
Suppose you have backed up the node instance in the node-backup directory, with the retention-window option is set to 7, and you have the following backups available on April 10, 2019:
```
BACKUP INSTANCE 'node'
===========================================================================================================================================
Instance Version ID Recovery time Mode WAL Current/Parent TLI Time Data Start LSN Stop LSN Status
===========================================================================================================================================
node 10 P7XDHR 2019-04-10 05:27:15+03 FULL STREAM 1 / 0 11s 200MB 0/18000059 0/18000197 OK
node 10 P7XDQV 2019-04-08 05:32:59+03 PAGE STREAM 1 / 0 11s 19MB 0/15000060 0/15000198 OK
node 10 P7XDJA 2019-04-03 05:28:36+03 DELTA STREAM 1 / 0 21s 32MB 0/13000028 0/13000198 OK
---------------------------------------retention window-------------------------------------------------------------
node 10 P7XDHU 2019-04-02 05:27:59+03 PAGE STREAM 1 / 0 31s 33MB 0/11000028 0/110001D0 OK
node 10 P7XDHB 2019-04-01 05:27:15+03 FULL STREAM 1 / 0 11s 200MB 0/F000028 0/F000198 OK
node 10 P7XDFT 2019-03-29 05:26:25+03 FULL STREAM 1 / 0 11s 200MB 0/D000028 0/D000198 OK
```
2019-06-23 04:05:01 +02:00
Even though P7XDHB and P7XDHU backups are outside the retention window, P7XDHB and P7XDHU cannot be removed as it invalidates the succeeding incremental backups P7XDJA and P7XDQV that are still required, so if you run the `delete` command with the `--delete-expired` option, only the P7XDFT full backup will be removed.
2019-06-24 23:43:48 +02:00
2019-06-23 04:05:01 +02:00
With the `--merge-expired` option, the P7XDJA backup is merged with the underlying P7XDHU and P7XDHB backups and becomes a full one, so there is no need to keep these expired backups anymore:
2019-06-20 19:49:42 +02:00
pg_probackup delete -B node-backup --instance node --delete-expired --merge-expired
pg_probackup show -B node-backup
```
BACKUP INSTANCE 'node'
============================================================================================================================================
Instance Version ID Recovery time Mode WAL Current/Parent TLI Time Data Start LSN Stop LSN Status
============================================================================================================================================
node 10 P7XDHR 2019-04-10 05:27:15+03 FULL STREAM 1 / 0 11s 200MB 0/18000059 0/18000197 OK
node 10 P7XDQV 2019-04-08 05:32:59+03 DELTA STREAM 1 / 0 11s 19MB 0/15000060 0/15000198 OK
node 10 P7XDJA 2019-04-04 05:28:36+03 FULL STREAM 1 / 0 5s 200MB 0/13000028 0/13000198 OK
```
>NOTE: The Time field for the merged backup displays the time required for the merge.
2019-06-20 19:49:42 +02:00
##### Merging Backups
2019-06-13 16:32:43 +02:00
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 the merge command, specifying the backup ID of the most recent incremental backup you would like to merge:
2019-06-20 19:49:42 +02:00
pg_probackup merge -B backup_dir --instance instance_name -i backup_id
2019-06-13 16:32:43 +02:00
This command merges the specified incremental backup to its parent full backup, together with all incremental backups between them. Once the merge is complete, 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 to save much time, especially for large data volumes.
2019-06-20 19:49:42 +02:00
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 the show command with the backup ID. If the merge is still in progress, the backup status is displayed as MERGING. The merge is idempotent, so you can restart the merge if it was interrupted.
##### Deleting Backups
2019-06-13 16:32:43 +02:00
To delete a backup that is no longer required, run the following command:
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name -i backup_id
2019-06-13 16:32:43 +02:00
2019-06-24 23:43:48 +02:00
This command will delete the backup with the specified *backup_id*, together with all the incremental backups that followed, 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.
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
To delete obsolete WAL files that are not necessary to restore any of the remaining backups, use the `--delete-wal` option:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name --delete-wal
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
To delete backups that are expired according to the current retention policy, use the `--delete-expired` option:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name --delete-expired
2019-06-13 16:32:43 +02:00
2019-06-23 04:05:01 +02:00
Note that 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` option when running this command:
2019-06-13 16:32:43 +02:00
2019-06-20 19:49:42 +02:00
pg_probackup delete -B backup_dir --instance instance_name --delete-expired --merge-expired
2019-06-13 16:32:43 +02:00
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.
2019-06-23 04:05:01 +02:00
Before merging or deleting backups, you can run the delete command with the `--dry-run` option, which displays the status of all the available backups according to the current retention policy, without performing any irreversible actions.
2019-06-13 16:32:43 +02:00
### Authors
2019-06-13 16:49:02 +02:00
PostgreSQLfessional, Moscow, Russia.
2019-06-23 04:05:01 +02:00
2019-06-13 16:32:43 +02:00
### Credits
2019-06-20 19:49:42 +02:00
pg_probackup utility is based on pg_arman, that was originally written by NTT and then developed and maintained by Michael Paquier.