Pgbouncer - 我可以使用 pgbouncer 对 postgres 集群中的请求进行负载平衡吗?

Pgbouncer - Can I use pgbouncer for load balancing the request in postgres cluster?

目前,我在 postgresql 集群中使用 pgbouncer 进行连接池。我只是想确定,是否可以使用 pgbouncer 在 postgresql 集群中的节点之间负载平衡请求。

来自PgBouncer FAQ

How to load-balance queries between several servers?

PgBouncer does not have internal multi-host configuration. It is possible via some external tools:

  1. DNS round-robin. Use several IPs behind one DNS name. PgBouncer does not look up DNS each time new connection is launched. Instead it caches all IPs and does round-robin internally. Note: if there is more than 8 IPs behind one name, the DNS backend must support EDNS0 protocol. See README for details.

  2. Use a TCP connection load-balancer. Either LVS or HAProxy seem to be good choices. On PgBouncer side it may be good idea to make server_lifetime smaller and also turn server_round_robin on - by default idle connections are reused by LIFO algorithm which may work not so well when load-balancing is needed

现在 pgbouncer-rr-patch(AWS 的 pgbouncer 分支)可以进行负载平衡:

Routing: intelligently send queries to different database servers from one client connection; use it to partition or load balance across multiple servers/clusters.