5.1. Cloning a standby from Barman

5.1.1. Prerequisites for cloning from Barman
5.1.2. Using Barman as a WAL file source

repmgr standby clone can use 2ndQuadrant's Barman application to clone a standby (and also as a fallback source for WAL files).

Tip

Barman (aka PgBarman) should be considered as an integral part of any PostgreSQL replication cluster. For more details see: https://www.pgbarman.org/.

Barman support provides the following advantages:

Note

Currently repmgr's support for cloning from Barman is implemented by using rsync to clone from the Barman server.

It is therefore not able to make use of Barman's parallel restore facility, which is executed on the Barman server and clones to the target server.

Barman's parallel restore facility can be used by executing it manually on the Barman server and integrating the resulting cloned standby using repmgr standby clone --recovery-conf-only.

5.1.1. Prerequisites for cloning from Barman

In order to enable Barman support for repmgr standby clone, following prerequisites must be met:

  • the Barman catalogue must include at least one valid backup for this server;

  • the barman_host setting in repmgr.conf is set to the SSH hostname of the Barman server;

  • the barman_server setting in repmgr.conf is the same as the server configured in Barman.

For example, assuming Barman is located on the host "barmansrv" under the "barman" user account, repmgr.conf should contain the following entries:

    barman_host='barman@barmansrv'
    barman_server='pg'

Here pg corresponds to a section in Barman's configuration file for a specific server backup configuration, which would look something like:

[pg]
description = "Main cluster"
...
     

More details on Barman configuration can be found in the Barman documentation's configuration section.

Note

To use a non-default Barman configuration file on the Barman server, specify this in repmgr.conf with barman_config:

      barman_config='/path/to/barman.conf'

We also recommend configuring the restore_command setting in repmgr.conf to use the barman-wal-restore script (see section Using Barman as a WAL file source below).

Tip

If you have a non-default SSH configuration on the Barman server, e.g. using a port other than 22, then you can set those parameters in a dedicated Host section in ~/.ssh/config corresponding to the value of barman_host in repmgr.conf. See the Host section in man 5 ssh_config for more details.

It's now possible to clone a standby from Barman, e.g.:

    $ repmgr -f /etc/repmgr.conf -h node1 -U repmgr -d repmgr standby clone
    NOTICE: destination directory "/var/lib/postgresql/data" provided
    INFO: connecting to Barman server to verify backup for "test_cluster"
    INFO: checking and correcting permissions on existing directory "/var/lib/postgresql/data"
    INFO: creating directory "/var/lib/postgresql/data/repmgr"...
    INFO: connecting to Barman server to fetch server parameters
    INFO: connecting to source node
    DETAIL: current installation size is 30 MB
    NOTICE: retrieving backup from Barman...
    (...)
    NOTICE: standby clone (from Barman) complete
    NOTICE: you can now start your PostgreSQL server
    HINT: for example: pg_ctl -D /var/lib/postgresql/data start

Note

Barman support is automatically enabled if barman_server is set. Normally it is good practice to use Barman, for instance when fetching a base backup while cloning a standby; in any case, Barman mode can be disabled using the --without-barman command line option.

5.1.2. Using Barman as a WAL file source

As a fallback in case streaming replication is interrupted, PostgreSQL can optionally retrieve WAL files from an archive, such as that provided by Barman. This is done by setting restore_command in recovery.conf to a valid shell command which can retrieve a specified WAL file from the archive.

barman-wal-restore is a Python script provided as part of the barman-cli package (Barman 2.0 ~ 2.7) or as part of the core Barman distribution (Barman 2.8 and later).

To use barman-wal-restore with repmgr, assuming Barman is located on the host "barmansrv" under the "barman" user account, and that barman-wal-restore is located as an executable at /usr/bin/barman-wal-restore, repmgr.conf should include the following lines:

    barman_host='barman@barmansrv'
    barman_server='pg'
    restore_command='/usr/bin/barman-wal-restore barmansrv pg %f %p'

Note

barman-wal-restore supports command line switches to control parallelism (--parallel=N) and compression (--bzip2, --gzip).