首页 > 代码库 > 如何使用pgpool failover_stream.sh自己控制选择指定的master节点

如何使用pgpool failover_stream.sh自己控制选择指定的master节点

集群架构:

h236:master

h237:standby sync

h238:standby sync

h239:stadnby async

h240:standby async

h241:standby async

failover_stream.sh

#!/bin/sh
h238=172.19.33.238
h239=172.19.33.239
h240=172.19.33.240
h241=172.19.33.241
h236=172.19.33.236
h237=172.19.33.237
trigger_command="pg_ctl promote -D /data/pgdata"
fix_rec="sed -i ‘s/172\.19\.33\.236\./172.19.33.237/‘ /data/pgdata/recovery.conf;\
pg_ctl -D /data/pgdata/ stop -m fast;pg_ctl -D /data/pgdata/ start"

#primary down
#236(node 0) , 237(node1)
if [$2 -eq $3 ];then
        #node 236 down          
        if [ $2 -eq 0 ];then
                /usr/bin/ssh -T $h237 $trigger_command
        fi
        #node 237 down
        if [ $2 -eq 1 ];then
                $fix_rec="sed -i ‘s/172\.19\.33\.237\./172.19.33.236/‘ /data/pgdata/recovery.conf;\
                pg_ctl -D /data/pgdata/ stop -m fast;pg_ctl -D /data/pgdata/ start"
                /usr/bin/ssh -T $h236 $trigger_command
        fi

        #238-241 follow new primary
        /usr/bin/ssh -T $h238 $fix_rec &
        /usr/bin/ssh -T $h239 $fix_rec &
        /usr/bin/ssh -T $h240 $fix_rec &
        /usr/bin/ssh -T $h241 $fix_rec &

#do nothing for other  standby down
fi
exit 0;

如何使用pgpool failover_stream.sh自己控制选择指定的master节点