-yum install etckeeper\r
+# instalirati etckeeper da čuva /etc/ direktorij u git-u\r
+# (nije na produkcijskom enviromentu)\r
+\r
+yum install etckeeper\r
cd /etc/\r
git config --global user.email "dpavlin@rot13.org"\r
git config --global user.name "Dobrica Pavlinusic"\r
‘.ssh/id_rsa.pub’ -> ‘.ssh/authorized_keys’\r
\r
\r
-prekopirati isti kljuc i authoriorized keys na slave:\r
+## prekopirati isti kljuc i authoriorized keys na slave:\r
\r
\r
[root@edozvola-db-01 pgsql]# rsync -rav .ssh edozvola-db-02:`pwd`\r
\r
[root@edozvola-db-01 ~]# vi /var/lib/pgsql/9.6/data/postgresql.conf\r
wal_level = replica\r
-archive_mode = on\r
-max_wal_senders = 3 \r
-max_replication_slots = 3\r
-archive_command = 'test ! -f /shared/pgsql/%f && cp %p /shared/pgsql/%f'\r
-hot_standby = on\r
-\r
-\r
\r
+# https://www.postgresql.org/docs/9.6/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT\r
+synchronous_commit = on\r
\r
+archive_mode = on\r
+archive_command = 'test ! -f /shared/pgsql/%f && cp %p /shared/pgsql/%f'\r
\r
+max_wal_senders = 3 \r
+max_replication_slots = 3\r
\r
+hot_standby = on\r
\r
\r
[root@edozvola-db-01 ~]# systemctl restart postgresql-9.6.service\r
\r
\r
\r
+# kreirati replication korisnika\r
\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-kreirati replication korisnika\r
[root@edozvola-db-01 ~]# sudo -u postgres psql\r
\r
-\r
postgres=# create user replication with password 'replication123' login replication ;\r
CREATE ROLE\r
\r
\r
host replication replication 10.200.1.62/24 md5\r
\r
-\r
-netmask je /24 da mozemo imati istu konfiguraciju na oba node-a\r
+## netmask je /24 da mozemo imati istu konfiguraciju na oba node-a\r
\r
\r
\r
\r
\r
-\r
-testirati replikaciju\r
+# testirati replikaciju\r
[root@edozvola-db-01 ~]# sudo -u postgres psql test\r
test=# insert into test1 (a,b) values ('baz',3);\r
INSERT 0 1\r
\r
\r
\r
-skripte\r
-promoviranje slave-a u master\r
+# skripte\r
\r
\r
[root@edozvola-db-01 pgsql]# pwd\r
/var/lib/pgsql\r
-[root@edozvola-db-01 pgsql]# cat promote-slave-to-master.sh\r
-#!/bin/sh -xe\r
-\r
\r
\r
+## promoviranje slave-a u master\r
\r
+[root@edozvola-db-01 pgsql]# cat promote-slave-to-master.sh\r
+#!/bin/sh -xe\r
/usr/pgsql-9.6/bin/pg_ctl --pgdata=/var/lib/pgsql/9.6/data promote\r
\r
\r
+## kreiranje slave instance od mastera\r
\r
-\r
-\r
-\r
-kreiranje slave instance od mastera\r
[root@edozvola-db-01 pgsql]# cat create-pgsql-slave.sh\r
#!/bin/sh -e\r
\r
--- /dev/null
+#!/bin/sh -e
+
+# WARNING: this script depends that two database nodes have IPs which and in x1 and x2
+# tr 12 21 does swap from currnet node number/ip to other one!
+
+test "`whoami`" != "postgres" && echo "$0 needs to be run as postgres user!" && exit 1
+
+here=`hostname -s`
+there=`hostname -s | tr 12 21`
+
+my_ip=`ip addr | grep 10.200.1. | sed 's/^.*\(10\.200\.1\.[0-9]*\)\/.*$/\1/'`
+other_ip=`echo $my_ip | tr 12 21`
+
+echo "Create slave on $here $my_ip using data from master on $there $other_ip"
+echo "[enter] to start"
+read
+
+#systemctl stop postgresql-9.6.service || true
+/usr/pgsql-9.6/bin/pg_ctl --pgdata=/var/lib/pgsql/9.6/data stop || true
+
+echo "select pg_start_backup('slave')" | ssh $there psql
+
+rsync -rav --delete --exclude pg_xlog $there:/var/lib/pgsql/9.6/data/ /var/lib/pgsql/9.6/data/
+
+echo "select pg_stop_backup()" | ssh $there psql
+
+test -e /var/lib/pgsql/9.6/data/recovery.done || ( echo "ERROR: no recovery.done !" && exit 1 )
+cat /var/lib/pgsql/9.6/data/recovery.done | sed -e s/$my_ip/$other_ip/ > /var/lib/pgsql/9.6/data/recovery.conf
+
+