]> git.immae.eu Git - github/fretlink/ansible-postgresql-role.git/commitdiff
recovery: optional restore_command & allow custom command if needed
authorPaul B <paul@bonaud.fr>
Thu, 28 May 2020 13:21:12 +0000 (15:21 +0200)
committerPaul B <paul@bonaud.fr>
Thu, 28 May 2020 16:41:06 +0000 (18:41 +0200)
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))

README.md
templates/postgresql.12.conf.j2
templates/recovery.conf.j2
test/main.yml

index 3ab415303facdca56a0a423b1d4afb3d8551cab1..e27734a6fa1c069691cb83891b2c57a115a10520 100644 (file)
--- a/README.md
+++ b/README.md
@@ -49,6 +49,17 @@ postgres_clusters:                         # Mandatory
     checksums: True                          # Optional
     fsync_enabled: False                     # Optional
     archive_enabled: False                   # Optional
+    wal_level: 'logical'                     # Optional
+    max_replication_slots: 10                # Optional
+    barman_directory: None                   # Optional
+    # Define cluster as a standby server
+    primary:                                 # Optional
+      host: '127.0.1.1'                        # Mandatory
+      port: 5433                               # Mandatory
+      replication_user:     'replicator'       # Mandatory
+      replication_password: 'SuperSecret'      # Mandatory
+      restore_command: None                    # Optional
+      restore_barman_directory: None           # Optional
     # List of users to be created (optional)
     users:
       - username: 'replicator'                 # Mandatory
index b49b8365ee047e71b985945170e4155292308dfe..35983194ab913238a46740cfaab5184a15bbe657 100644 (file)
@@ -260,20 +260,18 @@ archive_command = ''
 
 # These are only used in recovery mode.
 
-{% if postgres_primary %}
 {# In PG < 12 versions all the recovery settings were in a separate recovery.conf file #}
-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
-                               # placeholders: %p = path of file to restore
-                               #               %f = file name only
-                               # e.g. 'cp /mnt/server/archivedir/%f %p'
-                               # (change requires restart)
+{% if postgres_primary and postgres_primary.restore_command is defined %}
+restore_command = '{{ postgres_primary.restore_command }}'             # command to use to restore an archived logfile segment
+{% elif postgres_primary and postgres_primary.restore_barman_directory is defined %}
+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
 {% else %}
 #restore_command = ''          # command to use to restore an archived logfile segment
+{% endif %}
                                # placeholders: %p = path of file to restore
                                #               %f = file name only
                                # e.g. 'cp /mnt/server/archivedir/%f %p'
                                # (change requires restart)
-{% endif %}
 #archive_cleanup_command = ''  # command to execute at every restartpoint
 #recovery_end_command = ''     # command to execute at completion of recovery
 
index 059b2348c28feac1d44c14f6101583a42431d3bc..7078429ef62c8e197666d80da912155cd5d61950 100644 (file)
@@ -2,7 +2,11 @@
 # {{ ansible_managed }}
 
 standby_mode = 'on'
-restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_directory }} %f %p'
+{% if postgres_primary.restore_command is defined %}
+restore_command = '{{ postgres_primary.restore_command }}'
+{% elif postgres_primary.restore_barman_directory is defined %}
+restore_command = '/usr/bin/barman-wal-restore --user barman --parallel 8 {{ postgres_barman_server }} {{ postgres_primary.restore_barman_directory }} %f %p'
+{% endif %}
 primary_conninfo = 'host={{ postgres_primary.host }} port={{ postgres_primary.port }} user={{ postgres_primary.replication_user }} password={{ postgres_primary.replication_password }} sslmode=require'
 trigger_file = '/var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/failover.trigger'
 recovery_target_timeline='latest'
index 6a819d833f309b1f6766610e875c693be4cb2153..7d86f8df5193a4e050e2f9941076216669b00bba 100644 (file)
@@ -91,7 +91,7 @@
             primary:
               host: postgres_one
               port: 5432
-              restore_directory: "{{ postgres_barman_directory }}"
+              restore_barman_directory: "{{ postgres_barman_directory }}"
               replication_user: "replicator"
               replication_password: "secret_repli"