Sunteți pe pagina 1din 3

2/1/2017 Replication and Load Balance in PosgreSQL 9.

4 with PgPool2 - Nguyen Sy Thanh Son

Nguyen Sy Thanh Son

REPLICATION AND LOAD BALANCE IN POSGRESQL


9.4 WITH PGPOOL2
7
When you design a scale, high availability, high performance system, I sure that you have to apply Replication, AUGUST 21, 2015

Sharding and Load Balance technologies for your database layer. In this post, I will show you the way how to setup a | THANHSON1085
load balance with PgPool2 for your PostgreSQL Master-Slave Replication.

My scenario as image below:

Step 1: Install PostgreSQL Replication for your servers

At rst, Please refer to 2 posts:

Install PostgreSQL 9.4


Install PostgreSQL Replication master-slave

After that, install Pgpool Lib:

1 sudoaptgetinstallpostgresql9.4pgpool2

Step 2, Install PgPool2 for server 192.168.1.3

1 sudoaptgetinstallpgpool2

Edit /etc/pgpool2/pgpool.conf as below:

1 #BackendConnectionSettings
2
3 backend_hostname0='192.168.1.4'
4 #HostnameorIPaddresstoconnecttoforbackend0
backend_port0=5432
5 #Portnumberforbackend0
6 backend_weight0=1
7 #Weightforbackend0(onlyinloadbalancingmode)
8 backend_data_directory0='/var/lib/postgresql/9.4/main/'
#Datadirectoryforbackend0
9 backend_flag0='ALLOW_TO_FAILOVER'
10 #Controlsvariousbackendbehavior
11 #ALLOW_TO_FAILOVERorDISALLOW_TO_FAILOVER
12 backend_hostname1='192.168.1.5'
backend_port1=5432
13 backend_weight1=1
backend_data_directory1='/var/lib/postgresql/9.4/main/'
14 backend_flag1='ALLOW_TO_FAILOVER'
15
16 #Authentication
17
18 enable_pool_hba=on

https://sonnguyen.ws/replication-load-balance-in-posgresql-replication-with-pgpool2/ 1/3
2/1/2017 Replication and Load Balance in PosgreSQL 9.4 with PgPool2 - Nguyen Sy Thanh Son
19
20
21
22

Make sure you set enable_pool_hba=on

And change /etc/pgpool2/pool_hba.conf to enable md5 for authentication:

1 hostallall192.168.1.0/24md5

Add account to /etc/pgpool2/pool_passwd.conf (just a example)

1 postgres:md5xxxxxxxxxxxxxxxxxxxxxxxxxxx

Now, run pgpool with log:

1 pgpoolnd>/tmp/pgpool.log2>&1&

And stop Pgpool if you need:

1 pgpoolstop

Finally, test your installation. Good Luck!

RELATED POSTS

Replication Master-Slave with PostgreSQL 9.4 in Ubuntu 14.04


Install PostgreSQL 9.4 in Ubuntu 14.04

Share

PGPOOL2 POSTGRESQL REPLICATION

6Comments NguyenSyThanhSon
1 Login

SortbyBest
Recommend Share

Jointhediscussion

PriyeshKarathaayearago
afterdoingthisihaverunfollowingcommand
createdbp5433Upostgreshello
itresultsanerror:
createdb:couldnotconnecttodatabasetemplate1:FATAL:passwordauthenticationfailedforuser"postgres"

Itwascomingbecausewehavetoaddaccountdetailsto/etc/pgpool2/pool_passwdfile,not/etc/pgpool2/pool_passwd.conf.

Isuggetyoutoeditthosepart
Thanks
1 Reply Share

NguyenDacHuynh8monthsago
Iamstuckat
#aptgetinstallpostgresql9.4pgpool2

Readingpackagelists...Done

Buildingdependencytree

Readingstateinformation...Done

Somepackagescouldnotbeinstalled.Thismaymeanthatyouhave

requestedanimpossiblesituationorifyouareusingtheunstable

distributionthatsomerequiredpackageshavenotyetbeencreated

orbeenmovedoutofIncoming.

Thefollowinginformationmayhelptoresolvethesituation:

Thefollowingpackageshaveunmetdependencies:
https://sonnguyen.ws/replication-load-balance-in-posgresql-replication-with-pgpool2/ 2/3
2/1/2017 Replication and Load Balance in PosgreSQL 9.4 with PgPool2 - Nguyen Sy Thanh Son
Thefollowingpackageshaveunmetdependencies:

postgresql9.4pgpool2:Depends:libpgpool0(=3.4.31.pgdg80+1)butitisnotgoingtobeinstalled

E:Unabletocorrectproblems,youhaveheldbrokenpackages.

Doyouknowit?
Reply Share

NguyenSyThanhSon Mod >NguyenDacHuynh8monthsago

Youneedtorun`aptgetinstalllibpgpool0`beforerunningthecommandabove.
Reply Share

Chantiayearago
IhavedoneMasterSlavereplicationwithSlony.CanifollowthesameprocedureforSlonyreplicationalso???
Reply Share

NguyenSyThanhSon Mod >Chantiayearago

Yep,youcan,justtakenoteaboutPostgreSQLversion
Reply Share

Chantiayearago
NicePost,.Veryusefulforbeginnerslikeme.
Reply Share

ALSOONNGUYENSYTHANHSON

InstallMongoDBandMongoPHPinUbuntu Laravel4andcrontab
1comment3yearsago 1comment2yearsago
avisinghthanks.Reallyhelpful..!! justinExtremelyhelpful!Thankyou!

InstallDockerandDockerSwarmonCentOS7 InstallXHProfinUbuntu14.04
6comments6monthsago 1comment2yearsago
KhoiThinhThanksbnnha. KariTraceInstallXHProffrompecl:sudopeclinstallxhprof
0.9.4...Test:$phpi|grep

Subscribe d AddDisqustoyoursiteAddDisqusAdd Privacy

https://sonnguyen.ws/replication-load-balance-in-posgresql-replication-with-pgpool2/ 3/3

S-ar putea să vă placă și