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
+42-31Lines changed: 42 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,16 @@
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
@@ -35,14 +33,14 @@ Do the following steps on the `backup` node.
35
33
1. Create environment variables to simplify the config file creation:
36
34
37
35
```{.bash data-prompt="$"}
38
-
$ export SRV_NAME="backup"
39
-
$ export NODE1_NAME="node1"
40
-
$ export NODE2_NAME="node2"
41
-
$ export NODE3_NAME="node3"
42
-
$ 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"
43
41
```
44
42
45
-
2. Create the `pgBackRest` repository, *if necessary*
43
+
2. Create the `pgBackRest` repository, *if necessary*.
46
44
47
45
A repository is where `pgBackRest` stores backups. In this example, the backups will be saved to `/var/lib/pgbackrest`.
48
46
@@ -118,8 +116,8 @@ Do the following steps on the `backup` node.
118
116
pg1-port=5432
119
117
pg1-path=/var/lib/postgresql/{{pgversion}}/main
120
118
pg1-host-type=tls
121
-
pg1-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
122
-
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
123
121
pg1-host-ca-file=${CA_PATH}/ca.crt
124
122
pg1-socket-path=/var/run/postgresql
125
123
@@ -128,8 +126,8 @@ Do the following steps on the `backup` node.
128
126
pg2-port=5432
129
127
pg2-path=/var/lib/postgresql/{{pgversion}}/main
130
128
pg2-host-type=tls
131
-
pg2-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
132
-
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
133
131
pg2-host-ca-file=${CA_PATH}/ca.crt
134
132
pg2-socket-path=/var/run/postgresql
135
133
@@ -138,8 +136,8 @@ Do the following steps on the `backup` node.
138
136
pg3-port=5432
139
137
pg3-path=/var/lib/postgresql/{{pgversion}}/main
140
138
pg3-host-type=tls
141
-
pg3-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
142
-
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
143
141
pg3-host-ca-file=${CA_PATH}/ca.crt
144
142
pg3-socket-path=/var/run/postgresql
145
143
@@ -200,8 +198,8 @@ Do the following steps on the `backup` node.
200
198
pg1-port=5432
201
199
pg1-path=/var/lib/postgresql/{{pgversion}}/main
202
200
pg1-host-type=tls
203
-
pg1-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
204
-
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
205
203
pg1-host-ca-file=${CA_PATH}/ca.crt
206
204
pg1-socket-path=/var/run/postgresql
207
205
@@ -210,8 +208,8 @@ Do the following steps on the `backup` node.
210
208
pg2-port=5432
211
209
pg2-path=/var/lib/postgresql/{{pgversion}}/main
212
210
pg2-host-type=tls
213
-
pg2-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
214
-
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
215
213
pg2-host-ca-file=${CA_PATH}/ca.crt
216
214
pg2-socket-path=/var/run/postgresql
217
215
@@ -220,15 +218,27 @@ Do the following steps on the `backup` node.
220
218
pg3-port=5432
221
219
pg3-path=/var/lib/postgresql/{{pgversion}}/main
222
220
pg3-host-type=tls
223
-
pg3-host-cert-file=${CA_PATH}/${SRV_NAME}.crt
224
-
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
225
223
pg3-host-ca-file=${CA_PATH}/ca.crt
226
224
pg3-socket-path=/var/run/postgresql
227
225
228
226
" | sudo tee /etc/pgbackrest.conf
229
227
```
230
228
231
-
*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`.
232
242
233
243
### Create the certificate files
234
244
@@ -252,21 +262,21 @@ Run the following commands as a root user or with `sudo` privileges
5. Remove temporary files, set ownership of the remaining files to the `postgres` user, and restrict their access:
288
+
7. Remove temporary files, set ownership of the remaining files to the `postgres` user, and restrict their access:
279
289
280
290
```{.bash data-prompt="$"}
281
291
$ sudo rm -f ${CA_PATH}/*.csr
@@ -445,7 +455,7 @@ Run the following commands on `node1`, `node2`, and `node3`.
445
455
WantedBy=multi-user.target
446
456
```
447
457
448
-
8. Reload the `systemd`, the start the service
458
+
8. Reload `systemd` and start the service:
449
459
450
460
```{.bash data-prompt="$"}
451
461
$ sudo systemctl daemon-reload
@@ -511,13 +521,14 @@ Run the following commands on `node1`, `node2`, and `node3`.
511
521
512
522
It may take a while to reload the new configuration.
513
523
514
-
*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.
515
526
516
527
## Create backups
517
528
518
529
Run the following commands on the **backup server**:
519
530
520
-
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