Created
October 14, 2013 15:25
-
-
Save holly/6977416 to your computer and use it in GitHub Desktop.
follow_master_command = '/path/to/pgpool_follow_master.sh %d %h %H %r %R'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
SSH=/usr/bin/ssh | |
PGCTL=/usr/bin/pg_ctl | |
PCP_ATTACH_NODE=/usr/sbin/pcp_attach_node | |
DEVNULL=/dev/null | |
if [ -z "$PCP_HOST" ]; then | |
PCP_HOST=localhost | |
fi | |
if [ -z "$PCP_PORT" ]; then | |
PCP_PORT=9898 | |
fi | |
if [ -z "$PCP_USER" ]; then | |
PCP_USER=your_pcp_account | |
fi | |
if [ -z "$PCP_PASSWORD" ]; then | |
PCP_PASSWORD=your_pcp_pass | |
fi | |
if [ -z "$REPLICATION_USER" ]; then | |
REPLICATION_USER=replication | |
fi | |
if [ $# != 5 ]; then | |
echo "Usage: $(basename $0) failed_node failed_host new_master new_master_port cluster_path" >&2 | |
exit 1 | |
fi | |
failed_node=$1 | |
failed_host=$2 | |
new_master=$3 | |
new_master_port=$4 | |
cluster_path=$5 | |
recovery_conf=$cluster_path/recovery.conf | |
# Do nothing if standby goes down. | |
if [ $failed_node = 0 -o $failed_node = 1 ]; then | |
echo "node number:$failed_node is not target node number. skip" | |
exit 0; | |
fi | |
# execute new master restart | |
$SSH -T $new_master "$PGCTL restart -w -m fast -D $cluster_path >$DEVNULL 2>&1 <$DEVNULL" | |
echo "$new_master postgres restart. ok" | |
# make recovery.conf for slave host | |
cat <<EOL | $SSH -T $failed_host "cat >$recovery_conf" | |
standby_mode = 'on' | |
primary_conninfo = 'host=$new_master port=$new_master_port user=$REPLICATION_USER application_name=$failed_host' | |
trigger_file = '$cluster_path/trigger_file' | |
recovery_target_timeline='latest' | |
restore_command = '/bin/cp /data/pgsql/archlog/%f "%p"' | |
archive_cleanup_command = 'pg_archivecleanup /data/pgsql/archlog %r' | |
EOL | |
echo "make recovery.conf for $failed_host. ok" | |
# execute slave restart | |
$SSH -T $failed_host "$PGCTL restart -w -m fast -D $cluster_path >$DEVNULL 2>&1 <$DEVNULL" | |
echo "$failed_host postgres restart. ok" | |
# attach failed node | |
$PCP_ATTACH_NODE 0 $PCP_HOST $PCP_PORT $PCP_USER $PCP_PASSWORD $failed_node | |
echo "pcp_attach_node:$failed_node. ok" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment