Odoo Postgresql Master-Slave
Odoo Postgresql Master-Slave
What is:
1. repmgr is an open-source tool suite for managing replication and failover in a
cluster of PostgreSQL servers.
2. pgbouncer is a lightweight connection pooler for PostgreSQL.
Scenario:
The scenario is, we have 2 PostgreSQL servers master & slave and pgbouncer server
to relay connection between servers on failover.
1. DBHOST1 (Master) 192.168.1.10
2. DBHOST2 (Slave) 192.168.1.11
3. PgBouncer 192.168.1.12
Odoo will connect to PostgreSQL database indirectly via pgbouncer.
As shown in this figure Odoo will connect to PgBouncer server to relay requests to
PostgreSQL Master DB.
As shown in these figures, when the real Master DB fails, you promote Slave DB to be new
Master DB and configure PgBouncer to switch to new Master and then when all issues got
fixed on the old Master demote it to be the new Slave DB.
Setup:
All servers have to be running & Ubuntu server 16.04 installed on them.
Important Note: before running installation scripts, you have to edit script parameters specified in it.
ODOO_DB_PASS="odoo"
SLAVE_PASS="sammy"
sudo ./01-master-install.sh
Basically, the script will install PostgreSQL and repmgr then configure both of them in
addition to generating & transferring password-less SSH key to Slave Server and creating
ready scripts in the home directory to help DB admin to promote or demote server easily.
The password-less key file will be used by both PostgreSQL servers to sync data together
without manual authenticating.
Step 3 (PgBouncer):
Download final script to install PgBouncer server.
ODOO_DB_PASS="odoo"
If you already have an Odoo server deployed, open Odoo configuration file and modify DB
settings:
Important Notes:
1. On both PostgrsSQL servers, you should find 2 scripts promote-server & demote-
server to help you change the role of the servers easily in case of failure.
2. On PgBouncer server, you should find 2 scripts also switch-node1 & switch-
node2 to help you switch easily between Nodes.
Master Failover:
In case the Master DB failover, login to the Slave server and promote it with promote-
server script & then login to PgBouncer server and run switch-node# script in order to switch
to the new Master (Promoted) DB.
After fixing issues with the old Master server, run demote-server script to change the role of it
to be the new Slave.