-
Notifications
You must be signed in to change notification settings - Fork 1
/
replication
35 lines (24 loc) · 1.21 KB
/
replication
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
#!/bin/bash
#
# postgresql/replication/setup
#
# On the replica server perform the following:
# Stop the replica server
sm postgresql stop
master=pg-master
replica=pg-slave
# Connect the SSH dots
# Note that this must succeed before replication can be setup properly below.
su - postgres -c "ssh -o StrictHostKeyChecking=no postgres@$master 'hostname; ssh -o StrictHostKeyChecking=no postgres@$replica hostname'"
su - postgres -c "mkdir -p /var/db/postgresql/active/data/wal/"
# Remove all wal files on the replica
rm -f /var/db/postgresql/active/data/wal/*
# Signal a start backup on the $master
#psql -U postgres -h $master -c"select pg_start_backup('$(date)');"
psql -U postgres -h $master -c"select pg_start_backup('replication-setup',true);"
# Touch a starting wal file
su - postgres -c "touch /var/db/postgresql/active/data/wal/00000001.history"
su - postgres -c "rsync -avPz --delete --exclude .svn --exclude recovery.conf --exclude recovery.py --exclude postgresql.conf --exclude pg_log --exclude pg_xlog $master:/var/db/postgresql/active/data/ /var/db/postgresql/active/data/"
find /var/db/postgresql/active/data/pg_xlog -type f | xargs rm -f
psql -U postgres -h $master -c"select pg_stop_backup();"
sm postgresql start