Blame SOURCES/bz1795535-pgsql-1-add-postgresql-12-support.patch

8b04f5
From a43075be72683e1d4ddab700ec16d667164d359c Mon Sep 17 00:00:00 2001
8b04f5
From: Kazutomo Nakahira <kazutomo_nakahira@newson.co.jp>
8b04f5
Date: Mon, 25 Nov 2019 17:40:33 +0900
8b04f5
Subject: [PATCH 1/2] High: pgsql: Support for PostgreSQL 12
8b04f5
8b04f5
---
8b04f5
 heartbeat/pgsql | 32 +++++++++++++++++++++++++++++++-
8b04f5
 1 file changed, 31 insertions(+), 1 deletion(-)
8b04f5
8b04f5
diff --git a/heartbeat/pgsql b/heartbeat/pgsql
8b04f5
index b1c070ead..5bc76cc4c 100755
8b04f5
--- a/heartbeat/pgsql
8b04f5
+++ b/heartbeat/pgsql
8b04f5
@@ -1612,12 +1612,24 @@ make_recovery_conf() {
8b04f5
     fi
8b04f5
 
8b04f5
 cat > $RECOVERY_CONF <
8b04f5
-standby_mode = 'on'
8b04f5
 primary_conninfo = 'host=${OCF_RESKEY_master_ip} port=${OCF_RESKEY_pgport} user=${OCF_RESKEY_repuser} application_name=${NODENAME} ${OCF_RESKEY_primary_conninfo_opt}'
8b04f5
 restore_command = '${OCF_RESKEY_restore_command}'
8b04f5
 recovery_target_timeline = 'latest'
8b04f5
 END
8b04f5
 
8b04f5
+    if "${USE_STANDBY_SIGNAL}"; then
8b04f5
+        # create a standby.signal to start standby server.
8b04f5
+        runasowner "touch ${OCF_RESKEY_pgdata}/standby.signal"
8b04f5
+        if [ $? -ne 0 ]; then
8b04f5
+            ocf_exit_reason "Can't create ${OCF_RESKEY_pgdata}/standby.signal."
8b04f5
+            return 1
8b04f5
+        fi
8b04f5
+    else
8b04f5
+cat >> $RECOVERY_CONF <
8b04f5
+standby_mode = 'on'
8b04f5
+END
8b04f5
+    fi
8b04f5
+
8b04f5
     user_recovery_conf >> $RECOVERY_CONF
8b04f5
     ocf_log debug "Created recovery.conf. host=${OCF_RESKEY_master_ip}, user=${OCF_RESKEY_repuser}"
8b04f5
     return 0
8b04f5
@@ -1835,6 +1847,7 @@ pgsql_validate_all() {
8b04f5
     local version
8b04f5
     local check_config_rc
8b04f5
     local rep_mode_string
8b04f5
+    local recovery_conf_string
8b04f5
     local socket_directories
8b04f5
     local rc
8b04f5
 
8b04f5
@@ -1898,6 +1911,22 @@ pgsql_validate_all() {
8b04f5
             ocf_exit_reason "Replication mode needs PostgreSQL 9.1 or higher."
8b04f5
             return $OCF_ERR_INSTALLED
8b04f5
         fi
8b04f5
+        ocf_version_cmp "$version" "12"
8b04f5
+        rc=$?
8b04f5
+        if [ $rc -eq 1 ]||[ $rc -eq 2 ]; then
8b04f5
+            # change the standby method for PosrgreSQL 12 or later.
8b04f5
+            USE_STANDBY_SIGNAL=true
8b04f5
+            # change the path to recovery.conf because it cause PostgreSQL start error.
8b04f5
+            RECOVERY_CONF=${OCF_RESKEY_tmpdir}/recovery.conf
8b04f5
+            if [ $check_config_rc -eq 0 ]; then
8b04f5
+                # adding recovery parameters to postgresql.conf.
8b04f5
+                recovery_conf_string="include '$RECOVERY_CONF' # added by pgsql RA"
8b04f5
+                if ! grep -q "^[[:space:]]*$recovery_conf_string" $OCF_RESKEY_config; then
8b04f5
+                    ocf_log info "adding include directive $recovery_conf_string into $OCF_RESKEY_config"
8b04f5
+                    echo "$recovery_conf_string" >> $OCF_RESKEY_config
8b04f5
+                fi
8b04f5
+            fi
8b04f5
+        fi
8b04f5
         if [ ! -n "$OCF_RESKEY_master_ip" ]; then
8b04f5
             ocf_exit_reason "master_ip can't be empty."
8b04f5
             return $OCF_ERR_CONFIGURED
8b04f5
@@ -2107,6 +2136,7 @@ RESOURCE_NAME=`echo $OCF_RESOURCE_INSTANCE | cut -d ":" -f 1`
8b04f5
 PGSQL_WAL_RECEIVER_STATUS_ATTR="${RESOURCE_NAME}-receiver-status"
8b04f5
 RECOVERY_CONF=${OCF_RESKEY_pgdata}/recovery.conf
8b04f5
 NODENAME=$(ocf_local_nodename | tr '[A-Z]' '[a-z]')
8b04f5
+USE_STANDBY_SIGNAL=false
8b04f5
 
8b04f5
 case "$1" in
8b04f5
     methods)    pgsql_methods
8b04f5
8b04f5
From 5ab3339e8cb236583d375f5577f5a4dc129d5b27 Mon Sep 17 00:00:00 2001
8b04f5
From: munenari <munenari@gmail.com>
8b04f5
Date: Thu, 16 Jan 2020 09:27:59 +0900
8b04f5
Subject: [PATCH 2/2] Remove standby.signal when promote with restart
8b04f5
8b04f5
---
8b04f5
 heartbeat/pgsql | 6 +++++-
8b04f5
 1 file changed, 5 insertions(+), 1 deletion(-)
8b04f5
8b04f5
diff --git a/heartbeat/pgsql b/heartbeat/pgsql
8b04f5
index 5bc76cc4c..d5baa7b35 100755
8b04f5
--- a/heartbeat/pgsql
8b04f5
+++ b/heartbeat/pgsql
8b04f5
@@ -720,7 +720,11 @@ pgsql_promote() {
8b04f5
         ocf_log info "Restarting PostgreSQL instead of promote."
8b04f5
         #stop : this function returns $OCF_SUCCESS only.
8b04f5
         pgsql_real_stop slave
8b04f5
-        rm -f $RECOVERY_CONF
8b04f5
+        if "${USE_STANDBY_SIGNAL}"; then
8b04f5
+            rm -f ${OCF_RESKEY_pgdata}/standby.signal
8b04f5
+        else
8b04f5
+            rm -f $RECOVERY_CONF
8b04f5
+        fi
8b04f5
         pgsql_real_start
8b04f5
         rc=$?
8b04f5
         if [ $rc -ne $OCF_RUNNING_MASTER ]; then