php
git
github
cd libevent-2.0.21-stable ./configure --prefix=/opt/libevent make make install
cd pgbouncer-1.5.4 ./configure --prefix=/opt/pgbouncer --with-libevent=/opt/libevent make make install chown -R gpadmin:gpadmin /opt/pgbouncer
配置環境變量:本實驗數據庫對象是greenplum;數據庫
export LD_LIBRARY_PATH=/opt/libevent/lib:$LD_LIBRARY_PATH export PGB_HOME=/opt/pgbouncer export PATH=$PGB_HOME/bin:$PATH
建立一個PgBouncer配置文件pgbouncer.ini服務器
vi /opt/pgbouncer/config/pgbouncer.ini [databases] db_lottu = host=localhost port=5432 dbname=lottu user=lottu [pgbouncer] listen_port = 6432 listen_addr = * auth_type = md5 auth_file = /opt/pgbouncer/userlist.txt logfile = /opt/pgbouncer/pgbouncer.log pidfile = /opt/pgbouncer/pgbouncer.pid admin_users = lottu pool_mode = Transaction max_client_conn = 100
建立一個認證文件。該文件的名稱必須匹配pgbouncer.ini文件中的 auth_file參數;這裏是/opt/pgbouncer/userlist.txtsession
vi /opt/pgbouncer/userlist.txt "lottu" "××××××"
配置服務器重置查詢;當一個鏈接被返回給鏈接池時,它必須被重置爲剛建立的鏈接的狀態。在把一個鏈接返回給鏈接池以前,PgBouncer經過發出一個查詢來實現這種重置。PostgreSQL 8.3及其後的版本有一個用於此種目的的DISCARD ALL命令,它標準PgBouncer發佈的默認重置查詢。Greenplum數據庫不支持DISCARD ALL。須要配置參數server_reset_query性能
server_reset_query = RESET ALL; SET SESSION AUTHORIZATION DEFAULT;
spa
pgbouncer=# RELOAD;
pgbouncer -d /opt/pgbouncer/config/pgbouncer.ini
鏈接pgbouncercode
psql -p 6432 db_lottu lottu Password for user lottu: psql (8.2.15) Type "help" for help.
psql -p 6432 pgbouncer lottu
要看可用的命令,可運行show help命令
pgbouncer=# show help; NOTICE: Console usage DETAIL: SHOW HELP|CONFIG|DATABASES|POOLS|CLIENTS|SERVERS|VERSION SHOW STATS|FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM SHOW DNS_HOSTS|DNS_ZONES SET key = arg RELOAD PAUSE [<db>] RESUME [<db>] KILL <db> SUSPEND SHUTDOWN SHOW
若是用戶對pgbouncer.ini文件作了修改,用戶能夠用 RELOAD命令重載它:
pgbouncer=# RELOAD;