[pgpool-general: 5618] Re: about failover_command and follow_master_command

Tatsuo Ishii ishii at sraoss.co.jp
Wed Jul 12 07:59:04 JST 2017


> Can anyone help me to understand failover_command and follow_master_command?
> 
> 
>   1.  Pgpool will accept connections again until failover_command is completed, is this true?

Pgpool-II will *not* accept new connections until fail over command is completed.

>   2.  What is follow_master_command? If it is defined, will it be running as part of failover procedure? Or running after pgpool accept connections?

In streaming replication, when a new primary is created by promoting
one of standbys, other standby will keep on trying to connect to the
old primary. You need to let such standbys down and take base back
from the new primary so that each standby properly connects to the new
primary.

You can do the same thing automatically by defining
follow_master_command, which will be called for each standby nodes by
Pgpool-II after fail over completed. Note that Pgpool-II will accept
connections while executing follow_master_command.

Here is a sample follow master script generated by pgpool_setup which
comes with Pgpool-II.

#! /bin/sh
# Execute command by failover.
# special values:  %d = node id
#                  %h = host name
#                  %p = port number
#                  %D = database cluster path
#                  %m = new master node id
#                  %M = old master node id
#                  %H = new master node host name
#                  %P = old primary node id
#                  %R = new master database cluster path
#                  %r = new master port number
#                  %% = '%' character
failed_node_id=$1
failed_host_name=$2
failed_port=$3
failed_db_cluster=$4
new_master_id=$5
old_master_id=$6
new_master_host_name=$7
old_primary_node_id=$8
new_master_port_number=$9
new_master_db_cluster=${10}
mydir=/home/t-ishii/work/pgpool-II/current/aaa
log=$mydir/log/failover.log
pg_ctl=/usr/local/pgsql/bin/pg_ctl
cluster0=$mydir/data0
cluster1=$mydir/data1
cluster2=$mydir/data2
PCP_PORT=11001
export PCPPASSFILE=/home/t-ishii/work/pgpool-II/current/aaa/pcppass

date >> $log
echo "failed_node_id $failed_node_id failed_host_name $failed_host_name failed_port $failed_port failed_db_cluster $failed_db_cluster new_master_id $new_master_id old_master_id $old_master_id new_master_host_name $new_master_host_name old_primary_node_id $old_primary_node_id new_master_port_number $new_master_port_number new_master_db_cluster $new_master_db_cluster" >> $log

# Stop standby node if it's running
if $pg_ctl -D $failed_db_cluster status|grep "is running" >/dev/null 2>&1
then
	$pg_ctl -w -m f -D $failed_db_cluster stop >> $log 2>&1
	sleep 10
	# recovery the node
	pcp_recovery_node -w -h localhost -p $PCP_PORT -n $failed_node_id >> $log 2>&1
else
	echo "$failed_db_cluster is not running. skipping follow master command." >> $log
fi

--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp


More information about the pgpool-general mailing list