Skip to content
xmm edited this page Aug 13, 2012 · 3 revisions

This is the QuickStart for using repmgr with pacemaker.

PostgreSQL

PostgreSQL version 9.0 is installed from pitti ppa.
Native Hot Standby Replication feature of PostgreSQl v9.0 is used for db replication.
Pacemaker (cluster resource manager) is used for automatic postgresql migration. RepMgr package is modified for using as OCF ResourceAgent of Pacemaker.

Notice:
(Pri) - do this on primary server.
(Sec) - on secondary server.
(ALL) - on both servers.

  1. Prepare PostgreSQL
  2. (ALL) Install postgresql and run it.
  3. (Pri) Load databases and make optimization of postgresql. (optional. recommended for huge data.)
  4. (Pri) Shutdown PG.
  5. (ALL) update-rc.d -f postgresql remove
  6. (ALL) Rename /var/lib/postgresql/9.0 to /var/lib/postgresql/ha
  7. (ALL) Move config files postgresql.conf, pg_hba.conf, pg_ident.conf from /etc/postgresql/9.0/main to /var/lib/postgresql/ha/main
  8. Configure replication
  9. Set up trusted copy between postgres accounts
    1. (Pri) Create ssh key for postgres user
    2. (Pri) Put the public key into file ~postgres/.ssh/authorized_keys
    3. (Pri) Copy files authorized_keys id_rsa.pub id_rsa from primary to secondary server in dir /var/lib/postgresql/.ssh
    4. (All) Test that ssh in both directions works.
  10. (ALL) install my version of repmgr from https://github.com/downloads/xmm/repmgr/postgresql-repmgr-9.0_1.1.1.deb
    1. [https://github.com/xmm/repmgr Here's] good install guide. But don't run repmgrd daemon.
    2. (Pri) /var/lib/postgresql/ha/repmgr.conf:
    cluster=main
    node=1
    conninfo='host=srv01 user=repmgr dbname=postgres'
    1. (Pri) repmgr -f /var/lib/postgresql/ha/repmgr.conf --verbose master register
    2. (Sec) repmgr -D /var/lib/postgresql/ha/main -d postgres -U repmgr -R postgres --force standby clone srv01
    3. (Sec) /var/lib/postgresql/ha/repmgr.conf
    cluster=main
    node=3
    conninfo='host=srv03 user=repmgr dbname=postgres'
    1. (Sec) repmgr -f /var/lib/postgresql/ha/repmgr.conf --verbose standby register
  11. Add PostgreSQL to pacemaker
    (ALL)
    mkdir /usr/lib/ocf/resource.d/<your_resource_dir>
    wget -O /usr/lib/ocf/resource.d//pgsql https://github.com/xmm/repmgr/blob/master/ocf-ra-pgsql 
    
    (Pri) Example of pacemaker's configuration with repmgr:
primitive dbip ocf:heartbeat:IPaddr2 \
	params ip="10.0.0.200" cidr_netmask="24" nic="br1"
primitive pgdb ocf::pgsql \
	params repmgr_conf="/var/lib/postgresql/ha/repmgr.conf" pgctl="/usr/lib/postgresql/9.0/bin/pg_ctl" pgdata="/var/lib/postgresql/ha/main" logfile="/var/log/postgresql/postgresql-ha-main.log" \
	op start interval="0" timeout="90s" \
	op stop interval="0" timeout="60s" \
	op promote interval="0" timeout="120s" \
	op monitor interval="53s" role="Master" \
	op monitor interval="60s" role="Slave"
ms MS_pgdb pgdb \
	meta clone-max="2" target-role="Started" resource-stickiness="100" notify="true"
location LC-cl_pdns-srv01 CL_pdns -inf: srv01
location LC-ms_pgdb-srv01 MS_pgdb 200: srv01
location LC-ms_pgdb-srv03 MS_pgdb 150: srv02
colocation CO_pgdb_ip_master inf: dbip MS_pgdb:Master
order OR-promote-pgdb-then-dbip inf: MS_pgdb:promote dbip:start
property $id="cib-bootstrap-options" \
	dc-version="1.0.8-042548a451fce8400660f6031f4da6f0223dd5dd" \
	cluster-infrastructure="openais" \
	stonith-enabled="false" \
	expected-quorum-votes="3" \
	symmetric-cluster="true" \
	no-quorum-policy="freeze"
   

Clone this wiki locally