Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 102 lines (83 sloc) 1.711 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#!/bin/bash

. pgcommon.sh

ARCHIVE_OPT=
SYNC_OPT=
SBYNUM=1
CASCADE=false
CHECKSUM=""

usage ()
{
cat <<EOF
$PROGNAME sets up the master and standby(s).

Usage:
$PROGNAME [OPTIONS]

Options:
-a enables WAL archiving
-k uses data page checksums
-n NUM number of standbys (default: 1)
-A sets Async mode (default)
-S sets Sync mode
-C sets up Cascade standby
--conflict creates standby query conflict

Note:
-n option specifies the number of only standbys
connecting directly to the master.
EOF
}

here_is_installation
validate_replication

make_conflict ()
{
ACTDATA=data
ACTPORT=5432
ACTPSQL="$PGBIN/psql -p $ACTPORT -c"

SBYDATA=sby1
SBYPORT=5433
SBYPSQL="$PGBIN/psql -p $SBYPORT -c"

pgsql_is_alive $ACTDATA
pgsql_is_alive $SBYDATA

TMPTBL=tmptable_$(date +%Y%m%d%H%M%S)

$ACTPSQL "CREATE TABLE $TMPTBL (id int)"
$ACTPSQL "INSERT INTO $TMPTBL VALUES (1)"
sleep 1

$SBYPSQL "SELECT pg_sleep(60) FROM $TMPTBL" &
sleep 1

$ACTPSQL "DELETE FROM $TMPTBL"
$ACTPSQL "VACUUM $TMPTBL"

exit 0
}

while [ $# -gt 0 ]; do
case "$1" in
"-?"|--help)
usage
exit 0;;
-a)
ARCHIVE_OPT="-a";;
-k)
CHECKSUM="-k";;
-n)
SBYNUM=$2
if [ $SBYNUM -lt $SBYMIN ]; then
elog "number of standbys must be >=$SBYMIN"
fi
shift;;
-A)
SYNC_OPT="";;
-S)
SYNC_OPT="-S";;
-C)
CASCADE=true
validate_cascade_replication;;
--conflict)
make_conflict;;
*)
elog "invalid option: $1";;
esac
shift
done

validate_datapage_checksums "$CHECKSUM"

pgmaster.sh $ARCHIVE_OPT $SYNC_OPT $CHECKSUM
pgstandby.sh $ARCHIVE_OPT -n $SBYNUM

if [ "$CASCADE" = "true" ]; then
pgstandby.sh $ARCHIVE_OPT -c sby1
fi
Something went wrong with that request. Please try again.