Fixed sample failover script.
authorBo Peng <pengbo@sraoss.co.jp>
Mon, 7 Feb 2022 03:06:45 +0000 (12:06 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Mon, 7 Feb 2022 03:12:20 +0000 (12:12 +0900)
This script did not consider the case when the old primary node id is "-1".

src/sample/scripts/failover.sh.sample

index b9fac7dc541fd14707c3765a0755a0a6ed62c34d..91b5411792c479ad65d0e8bd9e1c471a6237f470 100755 (executable)
@@ -52,8 +52,14 @@ if [ $? -ne 0 ]; then
     exit 1
 fi
 
+## Check if all node is down
+if [ $NEW_MAIN_NODE_ID = "-1" ]; then
+    echo failover.sh: end: no new main node is available. Skipping failover.
+    exit 0
+fi
+
 ## If Standby node is down, skip failover.
-if [ $FAILED_NODE_ID -ne $OLD_PRIMARY_NODE_ID ]; then
+if [ $OLD_PRIMARY_NODE_ID != "-1" -a $FAILED_NODE_ID != $OLD_PRIMARY_NODE_ID ]; then
 
     # If Standby node is down, drop replication slot.
     ${PGHOME}/bin/psql -h ${OLD_PRIMARY_NODE_HOST} -p ${OLD_PRIMARY_NODE_PORT} \