escalation.sh脚本相对简单,Pgpool-II在产生新leader后,需要在新leader上绑定浮动IP,为确保绑定成功,会先调用此脚本遍历所有节点,解绑浮动IP。
# 本脚本由wd_escalation_command调用,为在新的leader节点上绑定浮动IP。# 需要先调用些脚本遍历所有Pgpool节点,解绑浮动IP。set-o xtrace # PostgreSQL启动用户POSTGRESQL_STARTUP_USER=postgres SSH_KEY_FILE=id_rsa SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/${SSH_KEY_FILE}"# 节点列表PGPOOLS=(db01 db2 db03) # 浮动IPVIP=192.168.0.5 # 绑定浮动IP的设备名DEVICE=eth0 for pgpool in"${PGPOOLS[@]}"; do [ "$HOSTNAME"="$pgpool" ] && continue ssh-T${SSH_OPTIONS}${POSTGRESQL_STARTUP_USER}@$pgpool" /usr/bin/sudo /usr/sbin/ip addr del $VIP/32 dev $DEVICE "doneexit0
pgpool_remote_start脚本用online recovery第一阶段(对应pgpool.conf中的recovery_1st_stage_command)执行完成后启动standby节点(对应pgpool.conf中的recovery_2nd_stage_command),这个脚本非常简单,就不加注释了。
# This script is run after recovery_1st_stage to start Standby node.set-o xtrace DEST_NODE_HOST="$1"DEST_NODE_PGDATA="$2"PGHOME=/usr/local/pgsql14 POSTGRESQL_STARTUP_USER=postgres SSH_KEY_FILE=id_rsa SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/${SSH_KEY_FILE}"echo pgpool_remote_start: start: remote start Standby node$DEST_NODE_HOST## Test passwordless SSHssh-T${SSH_OPTIONS}${POSTGRESQL_STARTUP_USER}@${DEST_NODE_HOST}ls /tmp > /dev/null if [ $?-ne0 ]; thenecho ERROR: pgpool_remote_start: passwordless SSH to ${POSTGRESQL_STARTUP_USER}@${DEST_NODE_HOST} failed. Please setup passwordless SSH. exit1fi## Start Standby nodessh-T${SSH_OPTIONS}${POSTGRESQL_STARTUP_USER}@${DEST_NODE_HOST}"$PGHOME/bin/pg_ctl -l /dev/null -w -D ${DEST_NODE_PGDATA} status if [ \$? -eq 0 ]; then exit 0 fi$PGHOME/bin/pg_ctl -l /dev/null -w -D ${DEST_NODE_PGDATA} start"if [ $?-ne0 ]; thenecho ERROR: pgpool_remote_start: ${DEST_NODE_HOST} PostgreSQL start failed. exit1fiecho pgpool_remote_start: end: PostgreSQL on ${DEST_NODE_HOST} is started successfully. exit0