You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/solutions/pgbackrest.md
+45-38Lines changed: 45 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,21 @@
1
1
# pgBackRest setup
2
2
3
-
[pgBackRest :octicons-link-external-16:](https://pgbackrest.org/) is a backup tool used to perform PostgreSQL database backup, archiving, restoration, and point-in-time recovery.
3
+
[pgBackRest :octicons-link-external-16:](https://pgbackrest.org/) is a tool used to perform PostgreSQL database backups, archiving, restoration, and point-in-time recovery.
4
4
5
-
In our solution we deploy a [pgBackRest server on a dedicated host :octicons-link-external-16:](https://pgbackrest.org/user-guide-rhel.html#repo-host) and also deploy pgBackRest on the PostgreSQL servers. Them we configure PostgreSQL servers to use it for backups and archiving.
6
-
7
-
You also need a backup storage to store the backups. It can either be a remote storage such as AWS S3, S3-compatible storages or Azure blob storage, or a filesystem-based one.
5
+
In this solution, a [pgBackRest server on a dedicated host :octicons-link-external-16:](https://pgbackrest.org/user-guide-rhel.html#repo-host) is deployed. pgBackRest is also installed and configured on the PostgreSQL servers to perform backups and manage WAL archiving.
8
6
9
7
## Preparation
10
8
11
9
Make sure to complete the [initial setup](ha-init-setup.md) steps.
12
10
13
11
## Install pgBackRest
14
12
15
-
Install pgBackRest on the following nodes: `node1`, `node2`, `node3`, `backup`
13
+
Install pgBackRest on all nodes: `node1`, `node2`, `node3`, and `backup`.
16
14
17
15
=== ":material-debian: On Debian/Ubuntu"
18
16
19
17
```{.bash data-prompt="$"}
20
-
$ export SRV_NAME="backup"
21
-
$ export NODE1_NAME="node1"
22
-
$ export NODE2_NAME="node2"
23
-
$ export NODE3_NAME="node3"
24
-
$ export CA_PATH="/etc/ssl/certs/pg_ha"
18
+
$ sudo apt install percona-pgbackrest
25
19
```
26
20
27
21
=== ":material-redhat: On RHEL/derivatives"
@@ -39,14 +33,14 @@ Do the following steps on the `backup` node.
39
33
1. Create environment variables to simplify the config file creation:
40
34
41
35
```{.bash data-prompt="$"}
42
-
$ export SRV_NAME="backup"
43
-
$ export NODE1_NAME="node1"
44
-
$ export NODE2_NAME="node2"
45
-
$ export NODE3_NAME="node3"
46
-
$ export CA_PATH="/etc/ssl/certs/pg_ha"
36
+
export SRV_NAME="backup"
37
+
export NODE1_NAME="node1"
38
+
export NODE2_NAME="node2"
39
+
export NODE3_NAME="node3"
40
+
export CA_PATH="/etc/ssl/certs/pg_ha"
47
41
```
48
42
49
-
2. Create the `pgBackRest` repository, *if necessary*
43
+
2. Create the `pgBackRest` repository, *if necessary*.
50
44
51
45
A repository is where `pgBackRest` stores backups. In this example, the backups will be saved to `/var/lib/pgbackrest`.
52
46
@@ -122,8 +116,8 @@ Do the following steps on the `backup` node.
122
116
pg1-port=5432
123
117
pg1-path=/var/lib/postgresql/{{pgversion}}/main
124
118
pg1-host-type=tls
125
-
pg1-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
126
-
pg1-host-key-file=${CA_PATH}/${SRV_NAME}.key
119
+
pg1-host-cert-file=${CA_PATH}/${NODE1_NAME}.crt
120
+
pg1-host-key-file=${CA_PATH}/${NODE1_NAME}.key
127
121
pg1-host-ca-file=${CA_PATH}/ca.crt
128
122
pg1-socket-path=/var/run/postgresql
129
123
@@ -132,8 +126,8 @@ Do the following steps on the `backup` node.
132
126
pg2-port=5432
133
127
pg2-path=/var/lib/postgresql/{{pgversion}}/main
134
128
pg2-host-type=tls
135
-
pg2-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
136
-
pg2-host-key-file=${CA_PATH}/${SRV_NAME}.key
129
+
pg2-host-cert-file=${CA_PATH}/${NODE2_NAME}.crt
130
+
pg2-host-key-file=${CA_PATH}/${NODE2_NAME}.key
137
131
pg2-host-ca-file=${CA_PATH}/ca.crt
138
132
pg2-socket-path=/var/run/postgresql
139
133
@@ -142,8 +136,8 @@ Do the following steps on the `backup` node.
142
136
pg3-port=5432
143
137
pg3-path=/var/lib/postgresql/{{pgversion}}/main
144
138
pg3-host-type=tls
145
-
pg3-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
146
-
pg3-host-key-file=${CA_PATH}/${SRV_NAME}.key
139
+
pg3-host-cert-file=${CA_PATH}/${NODE3_NAME}.crt
140
+
pg3-host-key-file=${CA_PATH}/${NODE3_NAME}.key
147
141
pg3-host-ca-file=${CA_PATH}/ca.crt
148
142
pg3-socket-path=/var/run/postgresql
149
143
@@ -204,8 +198,8 @@ Do the following steps on the `backup` node.
204
198
pg1-port=5432
205
199
pg1-path=/var/lib/postgresql/{{pgversion}}/main
206
200
pg1-host-type=tls
207
-
pg1-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
208
-
pg1-host-key-file=${CA_PATH}/${SRV_NAME}.key
201
+
pg1-host-cert-file=${CA_PATH}/${NODE1_NAME}.crt
202
+
pg1-host-key-file=${CA_PATH}/${NODE1_NAME}.key
209
203
pg1-host-ca-file=${CA_PATH}/ca.crt
210
204
pg1-socket-path=/var/run/postgresql
211
205
@@ -214,8 +208,8 @@ Do the following steps on the `backup` node.
214
208
pg2-port=5432
215
209
pg2-path=/var/lib/postgresql/{{pgversion}}/main
216
210
pg2-host-type=tls
217
-
pg2-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
218
-
pg2-host-key-file=${CA_PATH}/${SRV_NAME}.key
211
+
pg2-host-cert-file=${CA_PATH}/${NODE2_NAME}.crt
212
+
pg2-host-key-file=${CA_PATH}/${NODE2_NAME}.key
219
213
pg2-host-ca-file=${CA_PATH}/ca.crt
220
214
pg2-socket-path=/var/run/postgresql
221
215
@@ -224,15 +218,27 @@ Do the following steps on the `backup` node.
224
218
pg3-port=5432
225
219
pg3-path=/var/lib/postgresql/{{pgversion}}/main
226
220
pg3-host-type=tls
227
-
pg3-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
228
-
pg3-host-key-file=${CA_PATH}/${SRV_NAME}.key
221
+
pg3-host-cert-file=${CA_PATH}/${NODE3_NAME}.crt
222
+
pg3-host-key-file=${CA_PATH}/${NODE3_NAME}.key
229
223
pg3-host-ca-file=${CA_PATH}/ca.crt
230
224
pg3-socket-path=/var/run/postgresql
231
225
232
226
" | sudo tee /etc/pgbackrest.conf
233
227
```
234
228
235
-
*NOTE*: The option `backup-standby=y` above indicates the backups should be taken from a standby server. If you are operating with a primary only, or if your secondaries are not configured with `pgBackRest`, set this option to `n`.
229
+
Where:
230
+
231
+
* `pgX-host` specifies the hostname of the PostgreSQL node
232
+
* `pgX-host-port` specifies the port used by the pgBackRest server daemon on that node. The default pgBackRest server port is `8432`
233
+
* `pgX-port` specifies the PostgreSQL server port (default `5432`)
234
+
* `pgX-path` specifies the PostgreSQL data directory on the node
235
+
236
+
The `pgX` prefix is repeated for each PostgreSQL node in the cluster (for example `pg1`, `pg2`, `pg3`).
237
+
238
+
The numbering (`pg1`, `pg2`, `pg3`) represents individual PostgreSQL nodes defined in the cluster stanza.
239
+
240
+
!!! note
241
+
The option `backup-standby=y` above indicates the backups should be taken from a standby server. If you are operating with a primary only, or if your secondaries are not configured with `pgBackRest`, set this option to `n`.
236
242
237
243
### Create the certificate files
238
244
@@ -256,21 +262,21 @@ Run the following commands as a root user or with `sudo` privileges
5. Make a copy of the configuration file. The path to it can be either `/etc/pgbackrest/pgbackrest.conf` or `/etc/pgbackrest.conf`:
@@ -449,7 +455,7 @@ Run the following commands on `node1`, `node2`, and `node3`.
449
455
WantedBy=multi-user.target
450
456
```
451
457
452
-
8. Reload the `systemd`, the start the service
458
+
8. Reload `systemd` and start the service:
453
459
454
460
```{.bash data-prompt="$"}
455
461
$ sudo systemctl daemon-reload
@@ -492,7 +498,7 @@ Run the following commands on `node1`, `node2`, and `node3`.
492
498
max_replication_slots: 10
493
499
max_wal_senders: 5
494
500
max_wal_size: 10GB
495
-
wal_keep_segments: 10
501
+
wal_keep_size: 10
496
502
wal_level: logical
497
503
wal_log_hints: true
498
504
recovery_conf:
@@ -515,13 +521,14 @@ Run the following commands on `node1`, `node2`, and `node3`.
515
521
516
522
It may take a while to reload the new configuration.
517
523
518
-
*NOTE*: When configuring a PostgreSQL server that is not managed by Patroni to archive/restore WALs from the `pgBackRest` server, edit the server's main configuration file directly and adjust the `archive_command` and `restore_command` variables as shown above.
524
+
!!! note
525
+
When configuring a PostgreSQL server that is not managed by Patroni to archive/restore WALs from the `pgBackRest` server, edit the server's main configuration file directly and adjust the `archive_command` and `restore_command` variables as shown above.
519
526
520
527
## Create backups
521
528
522
529
Run the following commands on the **backup server**:
523
530
524
-
1. Create the stanza. A stanza is the configuration for a PostgreSQL database cluster that defines where it is located, how it will be backed up, archiving options, etc.
531
+
1. Create the stanza. A stanza is the configuration for a PostgreSQL database cluster that defines where it is located, how it will be backed up, archiving options, etc.
0 commit comments