Simple step by step command to setup up postgres server for HA with pgpool
Streaming Replication
Create primary db:
Change in postgresql.conf
. For now I am just setting the listen_address to *
but in real scenarios we only allow specific server address to listen at. Also change the port no
Create user rep_user
with replication flag set
Add repuser in pg_hba.conf as ipv connections
Now restart server. We have to make a replica db now. For than we can use pg_basebackup
, use the following command to make the secondary server
New data cluster will be cerated, open it and configure the port no to be different from the primary server. Set it to 5434
for now.
Now our primary server would be running by now, start the recently created replica sever. It will be automatically be connected to the primary server and will start the streaming replication. You can notice that the streaming replication is been started successfully in the sever logs.
Setting up Pgpool
Now we can add pgpool over our setup for the connection pooling. Install the pgpool maybe from the rpms availables at there site or may be from the source. Open up the pgpool.sample
if not available copy it from the sample conf file.
Now change some configrations for the pgpool.
Settings for HA
Now we should add some handling for the failover scenarios and improve our HA. First open the postgersql.conf
for the primary server and change following confs.
Now we need a simple script that will be executed in case of the fail over. Make a script fail_over.sh and place it somewhere.
Now open the pgpool.conf
and set the following confs.
Open configrations for the replica_db and set this.
Now the setup is done for handling the failover scenario. Now when ever the primary db fials, the pgpool creates the trigger file. The replica db will keep on looking the for the trigger file, when ever the pgpool creates the trigger file the failover script will be executed.
Комментарии