-
Notifications
You must be signed in to change notification settings - Fork 10
AutoFailover Setup
Ok, so the database is now replicated between several machines and the read queries are load balanced among them in a transparent way to the user. It's not highly available yet, though, since a failure of the Master machine will put the database into a read-only state.
I made a script, failover.sh, that will be used to automate the process described on the Manual Failover page. The script is called by PgPool II whenever a node is detached, so you'll have to repeat these steps for both PgPool machines:
-
copy the failover.sh script to
/etc/pgpool-II/
-
open the script file and edit the nodeIDs, nodeIPs and nodePorts arrays to match your PostgreSQL machines. Also change the sudo user and postgres user (the postgres user is the one that owns the data folder where recovery.conf is located)
-
open the file
/etc/pgpool-II/pgpool.conf
,
find the linefailover_command = ''
and change it tofailover_command = '/etc/pgpool-II/failover.sh %d %h %p %D %M %m %H %P %r %R >> /tmp/failover.log'
Note that the failover command redirects the logs to
/tmp/failover.log
- enable passwordless ssh (RSA-keys) login from both PgPool servers to all the PostgreSQL machines for both the postgres user and a user with sudo access
To do this open a terminal, change to the respective user (
su user
) and run:
-
ssh-keygen -t rsa
- do not enter any password -
ssh-copy-id -i 192.168.1.1
- change the IP for the respective machine - try logging in to the machine to check if it requires a password:
ssh user@192.168.1.1
check
/var/log/secure
if you have issues
- run
sudo pgpool reload
(or start it if it wasn't running)
If you want to change something in the script behaviour, here is a handy table of what each of the arguments passed by pgpool to the script mean:
Bash Variable | Symbol | Description | Example |
---|---|---|---|
$1 | %d | Backend ID of a detached node | 1 |
$2 | %h | Hostname of a detached node | 192.168.129.143 |
$3 | %p | Port number of a detached node | 5432 |
$4 | %D | Database cluster directory of a detached node | /var/lib/pgsqli/9.4/data |
$5 | %M | Old master node ID | 1 |
$6 | %m | New master node ID | 2 |
$7 | %H | Hostname of the new master node | 192.168.129.202 |
$8 | %P | Old primary node ID | 1 |
$9 | %r | New master port number | 5432 |
$10 | %R | New master database cluster directory | /var/lib/pgsqli/9.4/data |
- Home
- Overview
- Requirements
- Setup
- Summary and Quick Start
- Database (PostgreSQL) 1. PostgreSQL Installation 2. Configuring the Master 3. Configuring the Slaves 4. Testing Replication 5. Manual Failover
- Load Balancing (PgPool II) 1. PgPool II Installation 2. Configuration 3. Managing and Testing
- Automatic Failover 1. Setting it up 2. Testing
- Troubleshooting
- References