使用PgBouncer连接池
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.txt
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;
pgbouncer=# RELOAD;
3.启动pgbouncer
pgbouncer -d /opt/pgbouncer/config/pgbouncer.ini
连接pgbouncer
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;