#! /bin/sh # Failover command for streaming replication. # This script assumes that DB node 0 is primary, and 1 is standby. # # If standby goes down, do nothing. If primary goes down, create a # trigger file so that standby takes over primary node. # %d Backend ID of a detached node. # %h Hostname of a detached node. # %P Old primary node ID. # %m New master node ID. # %H Hostname of the new master node. detached_node_id=$1 detached_node_hostname=$2 old_primary_node=$3 new_master_node_id=$4 hostname_new_master=$5 trigger_file='/tmp/trigger_file' # Do nothing if standby goes down. if [ $detached_node_id = $old_primary_node ]; then # Create the trigger file. /usr/bin/ssh -T postgres@$hostname_new_master /bin/touch $trigger_file fi #Properties for sending email HOSTNAME=`/bin/hostname` MAIL=/bin/mail ADMIN_EMAIL="lazaro3487@gmail.com" SUBJECT="[PGPOOL ALERT] Node $detached_node_hostname was detached" TIMESTAMP=`/bin/date +'%Y-%m-%d %H:%M:%S'` MESSAGE=" --------------------------------------------- Pgpool-II Hostname: ${HOSTNAME} Date: ${TIMESTAMP} --------------------------------------------- ERROR: The postgresql service seems not working in $detached_node_hostname" sendmail(){ MESSAGE=$1 SUBJECT=$2 echo "$MESSAGE" | $MAIL -s "$SUBJECT" $ADMIN_EMAIL } sendmail "$MESSAGE" "$SUBJECT" exit 0;