Multiple Stanzas
pgBackRest supports multiple stanzas. The most common usage is sharing a repository host among multiple stanzas.
Installation
A new host named pg-alt is created to run the new primary.
Install from package
apt-get install pgbackrest
apt-get install pgbackrest
yum install pgbackrest
yum install pgbackrest
Update permissions on configuration file and directories
chown <br-install-user>:<br-install-group> /var/log/pgbackrest
chown <br-install-user>:<br-install-group> /etc/pgbackrest/pgbackrest.conf
Setup Passwordless SSH
pgBackRest can use passwordless SSH to enable communication between the hosts. It is also possible to use TLS, see Setup TLS.
Create
mkdir -m 750 -p <setup-ssh-user-home-path>/.ssh
ssh-keygen -f <setup-ssh-user-home-path>/.ssh/id_rsa
-t rsa -b 4096 -N ""
Exchange keys between repository and <setup-ssh-host>.
Copy
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' &&
echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' &&
sudo ssh root@<setup-ssh-host> cat <setup-ssh-user-home-path>/.ssh/id_rsa.pub) |
sudo -u pgbackrest tee -a /home/pgbackrest/.ssh/authorized_keys
Copy repository public key to
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' &&
echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' &&
sudo ssh root@repository cat /home/pgbackrest/.ssh/id_rsa.pub) |
sudo -u <setup-ssh-user> tee -a <setup-ssh-user-home-path>/.ssh/authorized_keys
Test that connections can be made from repository to <setup-ssh-host> and vice versa.
Test connection from repository to
ssh <setup-ssh-user>@<setup-ssh-host>
Test connection from
ssh pgbackrest@repository
Configuration
pgBackRest configuration is nearly identical to pg-primary except that the demo-alt stanza will be used so backups and archive will be stored in a separate location.
Configure on the new primary
[demo-alt]
pg1-path=/var/lib/postgresql/17/demo
[global]
repo1-host=repository
[global]
repo1-host-type=tls
[global]
repo1-host-ca-file=/etc/pgbackrest/cert/ca.crt
[global]
repo1-host-cert-file=/etc/pgbackrest/cert/client.crt
[global]
repo1-host-key-file=/etc/pgbackrest/cert/client.key
[global]
tls-server-auth=pgbackrest-client=demo-alt
[global]
tls-server-address=*
[global]
tls-server-ca-file=/etc/pgbackrest/cert/ca.crt
[global]
tls-server-cert-file=/etc/pgbackrest/cert/server.crt
[global]
tls-server-key-file=/etc/pgbackrest/cert/server.key
[global]
log-level-file=detail
[global]
log-timestamp=n
Configure pg1-host/pg1-host-user and pg1-path
[demo-alt]
pg1-path=/var/lib/postgresql/17/demo
[demo-alt]
pg1-host=pg-alt
[demo-alt]
pg1-host-type=tls
[demo-alt]
pg1-host-ca-file=/etc/pgbackrest/cert/ca.crt
[demo-alt]
pg1-host-cert-file=/etc/pgbackrest/cert/client.crt
[demo-alt]
pg1-host-key-file=/etc/pgbackrest/cert/client.key
Setup pgBackRest Server
cat /etc/systemd/system/pgbackrest.service
systemctl enable pgbackrest
systemctl start pgbackrest
Setup Demo Cluster
Create the demo cluster
/usr/lib/postgresql/17/bin/initdb
-D /var/lib/postgresql/17/demo -k -A peer
pg_createcluster 17 demo
Configure settings
archive_command = 'pgbackrest --stanza=demo-alt archive-push %p'
archive_mode = on
log_filename = 'postgresql.log'
Start the demo cluster
pg_ctlcluster 17 demo restart
Create the Stanza and Check Configuration
The stanza-create command must be run to initialize the stanza. It is recommended that the check command be run after stanza-create to ensure archiving and backups are properly configured.
Create the stanza and check the configuration
pgbackrest --stanza=demo-alt --log-level-console=info stanza-create
pgbackrest --log-level-console=info check
If the check command is run from the repository host then all stanzas will be checked.
Check the configuration for all stanzas
pgbackrest --log-level-console=info check