概述前端
pgbouncer是PostgreSQL的一個輕量級鏈接池,能夠給客戶端提供一個統一的視圖。node
pgbouncer的做用:git
a)pgbouncer能夠在後端數據庫和前端應用間簡歷鏈接的橋樑,由pgbouncer去處理和後端的鏈接關係。github
b)對客戶端的鏈接進行限制,防止過多的惡意鏈接。sql
pgbouncer的特色:數據庫
a)內存消耗低。(默認2k/鏈接)vim
b)能夠把不一樣的數據庫鏈接到一個機器上,而對客戶端保持透明。後端
c)支持在線的重行配置而無需重啓。bash
需求服務器
postgresql-xl在架構上,coordiantor節點具備鏈接池做用,可是在多個coordiantor節點的時候,須要配置一個
管理多個coordinator節點的鏈接池。考慮到只須要要簡單的鏈接池功能,因此選擇pgbouncer這種輕量級的鏈接池
相對比較合適。
背景
服務器配置
10.0.1.13 gtm
10.0.1.14 dbnode01
10.0.1.15 dbnode02
邏輯節點配置
gtm gtm節點
dbnode01 1個coordinator節點,2個datanode節點
dbnode02 1個coordinator節點,2個datanode節點
環境
CentOS7.1
postgresql-xl9.2
編譯安裝
依賴包安裝
yum install –y libevent-devel
若是yum不行,直接下載libevent包,編譯安裝便可。
源碼編譯安裝
下載源碼包,目前最新版本爲1.7
https://pgbouncer.github.io/downloads/files/1.7/pgbouncer-1.7.tar.gz
解壓
tar xvf pgbouncer-1.7.tar.gz
./configure
make & make install
配置環境變量
vim .bashrc
增長pgbouncer目錄
export PATH=/usr/local/pgbouncer/bin:$PATH
source .bashrc
配置
pgbouncer.ini
[database]
postgres = host=10.0.1.14 port=10010 user=postgres dbname=postgres
postgres = host=10.0.1.15 port=10020 user=postgres dbname=postgres
[pgbouncer]logfile = /home/postgres/pgbouncer/pgbouncer.log
pidfile = /home/postgres/pgbouncer/pgbouncer.pid
listen_addr = 127.0.0.1
listen_port = 6432
auth_file = /home/postgres/pgbouncer/userlist.txt
userlist.txt
用戶密碼配置文件,測試使用明文,能夠使用md5加密
增長:
「postgres」 「「
由於自己postgresql的用戶postgres沒有使用密碼,因此能夠直接用" ",在用戶名和密碼中間須要使用一個空格。
測試
鏈接測試
psql -h 127.0.0.1 -p 6432 -U postgres postgres
建立表
create table t1(f1 int);
\dt
insert記錄
insert into t1 values(1);
insert into t1 values(22);
查看insert數據
select * from t1;
數據傳輸狀況
7.
完
![](http://static.javashuo.com/static/loading.gif)