postgres availability learning articles II: by pgbouncer connection pool management tools to connect postgres

Installation pgbouncer

 yum -y install pgbouncer 

node1: edit configuration files pgbouncer.ini

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.130
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

Configuration management postgres account and password

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

node2: edit configuration files pgbouncer.ini

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.132
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

Configuration management postgres account and password

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

node3: edit configuration files pgbouncer.ini

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.134
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

Configuration management postgres account and password

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

/Etc/systemd/system/pgbouncer.service file created by systemctl management services pgbouncer

cat /etc/systemd/system/pgbouncer.service
[Unit]
Description=pgBouncer connection pooling for PostgreSQL
After=syslog.target network.target

[Service]
Type=forking

User=postgres
Group=postgres

PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /var/run/pgbouncer /var/log/pgbouncer
ExecStartPre=/bin/chown -R postgres:postgres /var/run/pgbouncer /var/log/pgbouncer
ExecStart=/usr/bin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini
ExecReload=/bin/kill -SIGHUP $MAINPID
PIDFile=/var/run/pgbouncer/pgbouncer.pid

LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

  

 

Guess you like

Origin www.cnblogs.com/caidingyu/p/11567033.html