$ vi /opt/PostgreSQL/9.1/data/basebackup.sh
内容如下:
#/bin/sh -x
PRIMARY_PORT=5432
STANDBY_PORT=5433
PRIMARY=/opt/PostgreSQL/9.1/data
STANDBY=/opt/PostgreSQL/9.1/standby
master_db_cluster=$1
recovery_node_host_name=$2
recovery_db_cluster=$3
if [ $master_db_cluster = $PRIMARY
];then
PORT=$PRIMARY_PORT
SOURCE_CLUSTER=$PRIMARY
DEST_CLUSTER=$STANDBY
else
PORT=$STANDBY_PORT
SOURCE_CLUSTER=$STANDBY
DEST_CLUSTER=$PRIMARY
fi
psql -p $PORT -c "SELECT
pg_start_backup('Streaming Replication', true)" postgres
rsync -C -a -c --delete --exclude
postgresql.conf --exclude postmaster.pid \
--exclude postmaster.opts --exclude
pg_log \
--exclude recovery.conf --exclude
recovery.done \
--exclude pg_xlog \
$SOURCE_CLUSTER/
$DEST_CLUSTER/
mkdir
$DEST_CLUSTER/pg_xlog
chmod 700
$DEST_CLUSTER/pg_xlog
rm
$DEST_CLUSTER/recovery.done
cat >
$DEST_CLUSTER/recovery.conf <
standby_mode =
'on'
primary_conninfo = 'port=$PORT
user=postgres'
trigger_file =
'/var/log/pgpool/trigger/trigger_file1'
EOF
psql -p $PORT -c "SELECT
pg_stop_backup()" postgres
$ chmod 755 basebackup.sh
$ vi /opt/PostgreSQL/9.1/data/pgpool_remote_start
内容如下:
#! /bin/sh
#
# Start PostgreSQL on the recovery
target node
#
if [ $# -ne 2 ]
then
echo "pgpool_remote_start
remote_host remote_datadir"
exit 1
fi
DEST=$1
DESTDIR=$2
PGCTL=/usr/local/pgsql/bin/pg_ctl
$PGCTL -w -D $DESTDIR start
2>/dev/null 1>/dev/null < /dev/null &
$ chmod 755 pgpool_remote_start
vi /usr/local/etc/failover.sh
内容如下:
#!/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
# %% = '%'
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
trigger=/var/log/pgpool/trigger/trigger_file1
if [ $failed_node_id =
$old_primary_node_id ];then # master failed
touch $trigger # let
standby take over