pgbouncer-install

简介: pgbouncer install

pgbouncer-install

 

前言

 

   每次应用程序和postgres连接,都会克隆出一个服务进程来为应用程序服务,在频繁的创建和销毁进程,会耗费比较多的资源。而pgbouncer会把与后端postgresql数据库的连接缓存住,当有前端请求时,只为分配一个空闲的连接给前端程序使用,这样就降低了资源的消耗。

 

要求

 

软件:pgbouncer-1.5.5.tar.gzlibevent-2.0.22-stable.tar.gz

 

 

安装

 

1、上传软件到opt并解压

 

# tar xvf libevent-2.0.22-stable.tar.gz

# tar xvf pgbouncer-1.5.5.tar.gz

 

2、安装libevent

 

# ./configure --prefix=/home/postgres/libevent

# make

# make install

 

 

3、安装pgbouncer

 

# ./configure --prefix=/home/postgres/pgbouncer/ --with-libevent=/home/postgres/libevent/

# make

# make install

 

 

4、配置.bash_profile,修改文件权限

 

 

# cp /opt/pgbouncer-1.5.5/etc/pgbouncer.ini /home/postgres/pgbouncer/

 

# chown -R postgres:postgres pgbouncer/

# chown -R postgres:postgres libevent/

 

# su - postgres

$ vim .bash_profile

 

export LD_LIBRARY_PATH=/home/postgres/libevent/lib:$LD_LIBRARY_PATH

 

5、修改配置文件pgbouncer.ini文件并参考该文件要求创建userlist.txt

 

$ vim pgbouncer.ini

 

[databases]

postgres = host=localhost port=5432 dbname=postgres user=postgres password=postgres connect_query='SELECT 1'

 

[pgbouncer]

logfile = /home/postgres/pgbouncer/pgbouncer.log

pidfile = /home/postgres/pgbouncer/pgbouncer.pid

listen_addr = *

listen_port = 6432

auth_type = trust

auth_file = /home/postgres/pgbouncer/userlist.txt

pool_mode = transaction

server_reset_query = DISCARD ALL

max_client_conn = 100

default_pool_size = 20

 

 

$ vim userlist.txt

 

"postgres" "postgres"

 

 

 

6、启动pgbouncer

 

./pgbouncer  -d /home/postgres/pgbouncer/pgbouncer.ini

 

7、登录

 

$ psql -p 6432 postgres

 

8、停止pgbouncer

 

$ cat /home/postgres/pgbouncer/pgbouncer.pid

$ kill number

 

 

9、查看连接池信息

 

$ psql -p 6432 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

 

=# show clients;

 

=# show pools;

 

 

 

 

报错信息

 

error 1:

[postgres@postgres93 bin]$ ./pgbouncer -d /home/postgres/pgbouncer/pgbouncer.ini

./pgbouncer: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

 

[solution]

# su - postgres

$ vim .bash_profile

 

export LD_LIBRARY_PATH=/home/postgres/libevent/lib:$LD_LIBRARY_PATH

 

error 2:

[postgres@postgres93 ~]$ psql -p 6432 pgbouncer

psql: ERROR:  not allowed

 

[solution]

 

$ vim pgbouncer.init

admin_users = postgres

 

需要重启pgbouncer

 

$ psql -p 6432 pgbouncer

 

 

 

参考文档:

http://pgbouncer.github.io/downloads/

https://yq.aliyun.com/articles/43328

http://www.bubuko.com/infodetail-1203143.html

http://blog.csdn.net/lk_db/article/details/77939005?locationNum=8&fps=1

 

目录
相关文章
安装MySQ报错 warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.
安装MySQ报错 warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.
1145 0
安装MySQ报错 warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.
|
关系型数据库 MySQL
MySQL安装--Starting the sever安装失败
MySQL安装--Starting the sever安装失败
355 0
|
关系型数据库 MySQL
安装percona-xtrabackup-24报错: file /etc/my.cnf from install of ..解决
安装percona-xtrabackup-24报错: file /etc/my.cnf from install of ..解决
209 0
|
关系型数据库 MySQL Linux
yum install mysql-community-server 出现类似报错:Requires: libtirpc.so.3()(64bit)
原因:Linux 版本与下载的 Mysql 的yum 库版本不兼容,例如 Centos7 安装 el8 版本的 Mysql;
yum install mysql-community-server 出现类似报错:Requires: libtirpc.so.3()(64bit)
|
关系型数据库 MySQL 数据库
|
关系型数据库 数据库 数据安全/隐私保护
|
关系型数据库 MySQL Shell
MySQL5.7安装与配置(YUM)
原文链接:http://blog.csdn.net/xyang81/article/details/51759200 安装环境:CentOS7 64位,MySQL5.7 1、配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.
3248 0
|
监控 关系型数据库 MySQL