;; 数据库名 = 连接串;;;; 连接串包括这些参数:;; dbname= host= port= user= password=;; client_encoding= datestyle= timezone=;; pool_size= connect_query=;; auth_user=[databases]instanceA=host=10.1.1.1 dbname=coreinstanceB=host=102.2.2.2 dbname=payment; 通过Unix套接字的 foodb;foodb =; 将bardb在localhost上重定向为bazdb ;bardb = host=localhost dbname=bazdb; 使用单个用户访问目标数据库;forcedb = host=127.0.0.1 port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO connect_query='SELECT 1'; 使用定制的连接池大小;nondefaultdb = pool_size=50 reserve_pool=10; 如果用户不在认证文件中,替换使用的auth_user; auth_user必须在认证文件中; foodb = auth_user=bar; 保底的通配连接串;* = host=testserver;; Pgbouncer配置区域[pgbouncer];;;;;; 管理设置;;;logfile=/var/log/pgbouncer/pgbouncer.logpidfile=/var/run/pgbouncer/pgbouncer.pid;;;;;; 监听哪里的客户端;;;; 监听IP地址,* 代表所有IPlisten_addr=*listen_port=6432; -R选项也会处理Unix Socket.; 在Debian上是 /var/run/postgresql;unix_socket_dir = /tmp;unix_socket_mode = 0777;unix_socket_group =;;;;;; TLS配置;;;;; 选项:disable, allow, require, verify-ca, verify-full;client_tls_sslmode = disable;; 信任CA证书的路径;client_tls_ca_file = <system default>;; 代表客户端的私钥与证书路径;; 从客户端接受TLS连接时,这是必须参数;client_tls_key_file =;client_tls_cert_file =;; fast, normal, secure, legacy, <ciphersuite string>;client_tls_ciphers = fast;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2;client_tls_protocols = all;; none, auto, legacy;client_tls_dheparams = auto;; none, auto, <curve name>;client_tls_ecdhcurve = auto;;;;;; 连接到后端数据库时的TLS设置;;;;; disable, allow, require, verify-ca, verify-full;server_tls_sslmode = disable;; 信任CA证书的路径;server_tls_ca_file = <system default>;; 代表后端的私钥与证书;; 只有当后端服务器需要客户端证书时需要;server_tls_key_file =;server_tls_cert_file =;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2;server_tls_protocols = all;; fast, normal, secure, legacy, <ciphersuite string>;server_tls_ciphers = fast;;;;;; 认证设置;;;; any, trust, plain, crypt, md5, cert, hba, pamauth_type=trustauth_file=/etc/pgbouncer/userlist.txt;; HBA风格的认证配置文件# auth_hba_file = /pg/data/pg_hba.conf;; 从数据库获取密码的查询,结果必须包含两列: 用户名 与 密码哈希值.;auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1;;;;;; 允许访问虚拟数据库'pgbouncer'的用户;;;; 允许修改设置,逗号分隔的用户名列表。admin_users=postgres; 允许使用SHOW命令,逗号分隔的用户名列表。stats_users=stats, postgres;;;;;; 连接池设置;;;; 什么时候服务端连接会被放回到池中?(默认为session); session - 会话模式,当客户端断开连接时; transaction - 事务模式,当事务结束时; statement - 语句模式,当语句结束时pool_mode=session; 客户端释放连接后,用于立刻清理连接的查询。; 不用把ROLLBACK放在这儿,当事务还没结束时,Pgbouncer是不会重用连接的。;; 8.3及更高版本的查询:; DISCARD ALL;;; 更老的版本:; RESET ALL; SET SESSION AUTHORIZATION DEFAULT;; 如果启用事务级别的连接池,则为空。;server_reset_query=DISCARD ALL; server_reset_query 是否需要在任何情况下执行。; 如果关闭(默认),server_reset_query 只会在会话级连接池中使用。;server_reset_query_always = 0;; Comma-separated list of parameters to ignore when given; in startup packet. Newer JDBC versions require the; extra_float_digits here.;;ignore_startup_parameters = extra_float_digits;; When taking idle server into use, this query is ran first.; SELECT 1;;server_check_query = select 1; If server was used more recently that this many seconds ago,; skip the check query. Value 0 may or may not run in immediately.;server_check_delay = 30; Close servers in session pooling mode after a RECONNECT, RELOAD,; etc. when they are idle instead of at the end of the session.;server_fast_close = 0;; Use <appname - host> as application_name on server.;application_name_add_host = 0;;;;;; 连接限制;;;; 最大允许的连接数max_client_conn=100; 默认的连接池尺寸,当使用事务连接池时,20是一个合适的值。对于会话级连接池而言; 该值是你想在同一时刻处理的最大连接数。default_pool_size=20;; 连接池中最少的保留连接数;min_pool_size = 0; 出现问题时,最多允许多少条额外连接;reserve_pool_size = 0; 如果客户端等待超过这么多秒,使用备用连接池;reserve_pool_timeout = 5; 单个数据库/用户最多允许多少条连接;max_db_connections = 0;max_user_connections = 0; If off, then server connections are reused in LIFO manner;server_round_robin = 0;;;;;; Logging;;;;; Syslog settings;syslog = 0;syslog_facility = daemon;syslog_ident = pgbouncer; log if client connects or server connection is made;log_connections = 1; log if and why connection was closed;log_disconnections = 1; log error messages pooler sends to clients;log_pooler_errors = 1;; Period for writing aggregated stats into log.;stats_period = 60;; Logging verbosity. Same as -v switch on command line.;verbose = 0;;;;;; Timeouts;;;;; Close server connection if its been connected longer.;server_lifetime = 3600;; Close server connection if its not been used in this time.;; Allows to clean unnecessary connections from pool after peak.;server_idle_timeout = 600;; Cancel connection attempt if server does not answer takes longer.;server_connect_timeout = 15;; If server login failed (server_connect_timeout or auth failure);; then wait this many second.;server_login_retry = 15;; Dangerous. Server connection is closed if query does not return;; in this time. Should be used to survive network problems,;; _not_ as statement_timeout. (default: 0);query_timeout = 0;; Dangerous. Client connection is closed if the query is not assigned;; to a server in this time. Should be used to limit the number of queued;; queries in case of a database or network failure. (default: 120);query_wait_timeout = 120;; Dangerous. Client connection is closed if no activity in this time.;; Should be used to survive network problems. (default: 0);client_idle_timeout = 0;; Disconnect clients who have not managed to log in after connecting;; in this many seconds.;client_login_timeout = 60;; Clean automatically created database entries (via "*") if they;; stay unused in this many seconds.; autodb_idle_timeout = 3600;; How long SUSPEND/-R waits for buffer flush before closing connection.;suspend_timeout = 10;; Close connections which are in "IDLE in transaction" state longer than;; this many seconds.;idle_transaction_timeout = 0;;;;;; Low-level tuning options;;;;; buffer for streaming packets;pkt_buf = 4096;; man 2 listen;listen_backlog = 128;; Max number pkt_buf to process in one event loop.;sbuf_loopcnt = 5;; Maximum PostgreSQL protocol packet size.;max_packet_size = 2147483647;; networking options, for info: man 7 tcp;; Linux: notify program about new connection only if there;; is also data received. (Seconds to wait.);; On Linux the default is 45, on other OS'es 0.;tcp_defer_accept = 0;; In-kernel buffer size (Linux default: 4096);tcp_socket_buffer = 0;; whether tcp keepalive should be turned on (0/1);tcp_keepalive = 1;; The following options are Linux-specific.;; They also require tcp_keepalive=1.;; count of keepalive packets;tcp_keepcnt = 0;; how long the connection can be idle,;; before sending keepalive packets;tcp_keepidle = 0;; The time between individual keepalive probes.;tcp_keepintvl = 0;; DNS lookup caching time;dns_max_ttl = 15;; DNS zone SOA lookup period;dns_zone_check_period = 0;; DNS negative result caching time;dns_nxdomain_ttl = 15;;;;;; Random stuff;;;;; Hackish security feature. Helps against SQL-injection - when PQexec is disabled,;; multi-statement cannot be made.;disable_pqexec = 0;; Config file to use for next RELOAD/SIGHUP.;; By default contains config file from command line.;conffile;; Win32 service name to register as. job_name is alias for service_name,;; used by some Skytools scripts.;service_name = pgbouncer;job_name = pgbouncer;; Read additional config from the /etc/pgbouncer/pgbouncer-other.ini file;%include /etc/pgbouncer/pgbouncer-other.ini