diff options
author | Paul B <paul@bonaud.fr> | 2020-05-28 15:21:12 +0200 |
---|---|---|
committer | Paul B <paul@bonaud.fr> | 2020-05-28 18:41:06 +0200 |
commit | 587f87bbf278a80b14a182146724a9ebf1fd98a2 (patch) | |
tree | 0e7e023c1b7f580db314c78bf3b65b70563efcc7 | |
parent | ebe451adda84672f9872187164df279dbfed7a35 (diff) | |
download | ansible-postgresql-role-587f87bbf278a80b14a182146724a9ebf1fd98a2.tar.gz ansible-postgresql-role-587f87bbf278a80b14a182146724a9ebf1fd98a2.tar.zst ansible-postgresql-role-587f87bbf278a80b14a182146724a9ebf1fd98a2.zip |
recovery: optional restore_command & allow custom command if needed
Right now the role assumes you always want to use barman-wal-restore
script as a restore command to recover WAL files at startup time of a
standby server.
This PR adds a new `primary.restore_command` option which lets you
override the command to use.
⚠️ Breaking change: the PR renames the existing
`primary.restore_directory` option to
`primary.restore_barman_directory` ⚠️ in order to give more context to
this option which will automatically use the `barman-wal-restore`
script as a restore command.
Finally if none of the two options specified above are specified in
the `primary:` object then the `restore_command` is left commented out
in the PG configuration (which is totally fine as it will try to
recover WALs from the primary server directly see
[documentation](https://www.postgresql.org/docs/12/warm-standby.html#STANDBY-SERVER-OPERATION))
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | templates/postgresql.12.conf.j2 | 12 | ||||
-rw-r--r-- | templates/recovery.conf.j2 | 6 | ||||
-rw-r--r-- | test/main.yml | 2 |
4 files changed, 22 insertions, 9 deletions
@@ -49,6 +49,17 @@ postgres_clusters: # Mandatory | |||
49 | checksums: True # Optional | 49 | checksums: True # Optional |
50 | fsync_enabled: False # Optional | 50 | fsync_enabled: False # Optional |
51 | archive_enabled: False # Optional | 51 | archive_enabled: False # Optional |
52 | wal_level: 'logical' # Optional | ||
53 | max_replication_slots: 10 # Optional | ||
54 | barman_directory: None # Optional | ||
55 | # Define cluster as a standby server | ||
56 | primary: # Optional | ||
57 | host: '127.0.1.1' # Mandatory | ||
58 | port: 5433 # Mandatory | ||
59 | replication_user: 'replicator' # Mandatory | ||
60 | replication_password: 'SuperSecret' # Mandatory | ||
61 | restore_command: None # Optional | ||
62 | restore_barman_directory: None # Optional | ||
52 | # List of users to be created (optional) | 63 | # List of users to be created (optional) |
53 | users: | 64 | users: |
54 | - username: 'replicator' # Mandatory | 65 | - username: 'replicator' # Mandatory |
diff --git a/templates/postgresql.12.conf.j2 b/templates/postgresql.12.conf.j2 index b49b836..3598319 100644 --- a/templates/postgresql.12.conf.j2 +++ b/templates/postgresql.12.conf.j2 | |||
@@ -260,20 +260,18 @@ archive_command = '' | |||
260 | 260 | ||
261 | # These are only used in recovery mode. | 261 | # These are only used in recovery mode. |
262 | 262 | ||
263 | {% if postgres_primary %} | ||
264 | {# In PG < 12 versions all the recovery settings were in a separate recovery.conf file #} | 263 | {# In PG < 12 versions all the recovery settings were in a separate recovery.conf file #} |
265 | restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_directory }} %f %p' # command to use to restore an archived logfile segment | 264 | {% if postgres_primary and postgres_primary.restore_command is defined %} |
266 | # placeholders: %p = path of file to restore | 265 | restore_command = '{{ postgres_primary.restore_command }}' # command to use to restore an archived logfile segment |
267 | # %f = file name only | 266 | {% elif postgres_primary and postgres_primary.restore_barman_directory is defined %} |
268 | # e.g. 'cp /mnt/server/archivedir/%f %p' | 267 | restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_barman_directory }} %f %p' # command to use to restore an archived logfile segment |
269 | # (change requires restart) | ||
270 | {% else %} | 268 | {% else %} |
271 | #restore_command = '' # command to use to restore an archived logfile segment | 269 | #restore_command = '' # command to use to restore an archived logfile segment |
270 | {% endif %} | ||
272 | # placeholders: %p = path of file to restore | 271 | # placeholders: %p = path of file to restore |
273 | # %f = file name only | 272 | # %f = file name only |
274 | # e.g. 'cp /mnt/server/archivedir/%f %p' | 273 | # e.g. 'cp /mnt/server/archivedir/%f %p' |
275 | # (change requires restart) | 274 | # (change requires restart) |
276 | {% endif %} | ||
277 | #archive_cleanup_command = '' # command to execute at every restartpoint | 275 | #archive_cleanup_command = '' # command to execute at every restartpoint |
278 | #recovery_end_command = '' # command to execute at completion of recovery | 276 | #recovery_end_command = '' # command to execute at completion of recovery |
279 | 277 | ||
diff --git a/templates/recovery.conf.j2 b/templates/recovery.conf.j2 index 059b234..7078429 100644 --- a/templates/recovery.conf.j2 +++ b/templates/recovery.conf.j2 | |||
@@ -2,7 +2,11 @@ | |||
2 | # {{ ansible_managed }} | 2 | # {{ ansible_managed }} |
3 | 3 | ||
4 | standby_mode = 'on' | 4 | standby_mode = 'on' |
5 | restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_directory }} %f %p' | 5 | {% if postgres_primary.restore_command is defined %} |
6 | restore_command = '{{ postgres_primary.restore_command }}' | ||
7 | {% elif postgres_primary.restore_barman_directory is defined %} | ||
8 | restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_barman_directory }} %f %p' | ||
9 | {% endif %} | ||
6 | primary_conninfo = 'host={{ postgres_primary.host }} port={{ postgres_primary.port }} user={{ postgres_primary.replication_user }} password={{ postgres_primary.replication_password }} sslmode=require' | 10 | primary_conninfo = 'host={{ postgres_primary.host }} port={{ postgres_primary.port }} user={{ postgres_primary.replication_user }} password={{ postgres_primary.replication_password }} sslmode=require' |
7 | trigger_file = '/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/failover.trigger' | 11 | trigger_file = '/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/failover.trigger' |
8 | recovery_target_timeline='latest' | 12 | recovery_target_timeline='latest' |
diff --git a/test/main.yml b/test/main.yml index 6a819d8..7d86f8d 100644 --- a/test/main.yml +++ b/test/main.yml | |||
@@ -91,7 +91,7 @@ | |||
91 | primary: | 91 | primary: |
92 | host: postgres_one | 92 | host: postgres_one |
93 | port: 5432 | 93 | port: 5432 |
94 | restore_directory: "{{ postgres_barman_directory }}" | 94 | restore_barman_directory: "{{ postgres_barman_directory }}" |
95 | replication_user: "replicator" | 95 | replication_user: "replicator" |
96 | replication_password: "secret_repli" | 96 | replication_password: "secret_repli" |
97 | 97 | ||