Fix pgpool_setup to deal with PostgreSQL 9.1.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 28 Aug 2019 05:48:11 +0000 (14:48 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 28 Aug 2019 05:48:11 +0000 (14:48 +0900)
"---data-checksums" was unconditionally added to initdb's arg but
PostgreSQL 9.1's initdb does not have the option. To solve the issue,
internal variable $PGVERSION now represents "major version" * 100:
e.g. 120 for PostgreSQL 12.x (including 12beta), 91 for PostgreSQL
9.1.x, so that pgpool_setup can check if the option can be added to
initdb options.

src/test/pgpool_setup

index 2bd193fe79452133a88691d55a81a7964f95de29..77218b59929aefdb1bd4add8c5044bfb33ca5916 100755 (executable)
@@ -76,7 +76,7 @@ LPATH=${PGLIB:-"/usr/local/pgsql/lib"}
 # unix socket directory
 PGSOCKET_DIR=${PGSOCKET_DIR:-"/tmp"}
 # initdb args
-INITDBARG="--no-locale -E UTF_8 --data-checksums"
+INITDBARG="--no-locale -E UTF_8"
 # Use replication slot
 USE_REPLICATION_SLOT=${USE_REPLICATION_SLOT:-"false"}
 # Use pg_rewind
@@ -99,9 +99,33 @@ PG_CTL=$PGBIN/pg_ctl
 PSQL=$PGBIN/psql
 
 # get PostgreSQL major version
-PGVERSION=`$INITDB -V|awk '{print $3}'|sed 's/\..*//'|sed 's/\([0-9]*\)[a-zA-Z].*/\1/'`
+vstr=`$INITDB -V|awk '{print $3}'|sed 's/\./ /g'`
+#vstr="12beta1"
+#vstr="9.1.24"
+#vstr="11.1"
+
+# check if alpha or beta
+echo $vstr|egrep "[a-z]" > /dev/null
+if [ $? = 0 ];then
+    vstr=`echo $vstr|sed 's/\([0-9]*\).*/\1/'`
+    major1=`echo $vstr|awk '{print $1}'`
+    major2=`echo $vstr|awk '{print $2}'`
+    if [ -z $major2 ];then
+       major2=0
+    fi
+else
+    vstr=`echo $vstr|sed 's/\./ /g'`
+    major1=`echo $vstr|awk '{print $1}'`
+    major2=`echo $vstr|awk '{print $2}'`
+fi
+major1=`expr $major1 \* 10`
+PGVERSION=`expr $major1 + $major2`
 echo PostgreSQL major version: $PGVERSION
 
+if [ $PGVERSION -gt 91 ];then
+    INITDBARG="$INITDBARG --data-checksums"
+fi
+
 # pgpool-II configuration file localtion.
 CONF=$BASEDIR/etc/pgpool.conf
 # failover script
@@ -309,7 +333,7 @@ function set_postgresql_conf
                    echo "max_replication_slots = $num_slots" >> $PGCONF
                fi
 
-               if [ $PGVERSION -ge 12 ];then
+               if [ $PGVERSION -ge 120 ];then
                    echo "include_if_exists = 'myrecovery.conf'" >> $PGCONF
                fi
 
@@ -325,7 +349,7 @@ function set_postgresql_conf
     sed -i '/host.*all.*all.*trust$/s/^/#/g' $PGHBACONF
     sed -i '/local.*all.*all.*trust$/s/^/#/g' $PGHBACONF
 
-    if [ $PGVERSION -gt 9 ];
+    if [ $PGVERSION -ge 100 ];
     then
        echo "host      all   scram_user     0/0    scram-sha-256" >> $PGHBACONF
        echo "host      all   md5_user       0/0    md5" >> $PGHBACONF
@@ -333,7 +357,7 @@ function set_postgresql_conf
 
     echo "host      all   all       0/0    trust" >> $PGHBACONF
 
-    if [ $PGVERSION -gt 9 ];
+    if [ $PGVERSION -ge 100 ];
     then
        echo "local      all   scram_user      scram-sha-256" >> $PGHBACONF
        echo "local      all   md5_user        md5" >> $PGHBACONF
@@ -428,7 +452,7 @@ $psql -p $PORT -c "SELECT * FROM pg_create_physical_replication_slot('pgpool_set
 EOF
 fi
 
-if [ $PGVERSION -ge 12 ];then
+if [ $PGVERSION -ge 120 ];then
     cat >> $1/$SCRIPT <<'EOF'
 cat > $DEST_CLUSTER/myrecovery.conf <<REOF
 primary_conninfo      = 'port=$PORT user=$PGSUPERUSER application_name=''server$recovery_node'''
@@ -581,7 +605,7 @@ chmod 755 $1/$SCRIPT
 # argument2: cluster No. We assume that data0 is primary
 #-------------------------------------------
 function create_recovery_conf {
-    if [ $PGVERSION -ge 12 ];then
+    if [ $PGVERSION -ge 120 ];then
        fname=myrecovery.conf
     elif [ $2 = "0" ];then
        fname=recovery.done
@@ -589,7 +613,7 @@ function create_recovery_conf {
        fname=recovery.conf
     fi
 
-    if [ $PGVERSION -lt 12 ];then
+    if [ $PGVERSION -lt 120 ];then
        cat > $1/$fname <<EOF
 standby_mode          = 'on'
 EOF
@@ -613,7 +637,7 @@ function set_pool_hba_conf {
     sed -i '/host.*all.*all.*trust$/s/^/#/g' $POOL_HBACONF
     sed -i '/local.*all.*all.*trust$/s/^/#/g' $POOL_HBACONF
 
-    if [ $PGVERSION -gt 9 ];
+    if [ $PGVERSION -ge 100 ];
     then
        echo "host    all         scram_user  0/0                   scram-sha-256" >> $POOL_HBACONF
        echo "host    all         md5_user    0/0                   md5" >> $POOL_HBACONF