能否仅使用Pgpool-II实现负载均衡并禁用其连接池功能?——关于connection_cache参数的有效性咨询
connection_cache = false disable Pgpool-II's connection pooling? Great question—yes, setting connection_cache = false is exactly the right way to disable Pgpool-II's connection pooling functionality, which aligns perfectly with your goal of using only HikariCP as your connection pool layer.
Here's a breakdown of what this does:
- By default,
connection_cacheistrue, which means Pgpool maintains a persistent pool of connections to your PostgreSQL master and slave nodes. It reuses these connections for incoming client requests to avoid the overhead of establishing new connections repeatedly. - When you set it to
false, Pgpool stops maintaining this cache entirely. Instead, it creates a fresh direct connection to the appropriate PostgreSQL backend node for every incoming client connection request, and closes that connection immediately when the client disconnects. This effectively removes Pgpool's connection pooling layer from the equation.
This is the ideal setup for your Java app using HikariCP. Having multiple layers of connection pooling (like Pgpool + HikariCP, or the earlier issue you had with PgBouncer) often leads to problems like connection exhaustion, timeouts, and inefficient use of database resources. With connection_cache = false, your app's HikariCP will handle all connection pooling logic to Pgpool, while Pgpool focuses solely on what you need it for: routing write queries to the master and read queries to the slaves.
A couple of quick reminders to make this work smoothly:
- Don’t forget to restart Pgpool-II after updating the configuration—changes to
connection_cachewon’t take effect until you do. - While other connection pool-related settings (like
max_pool) won’t have any impact whenconnection_cacheisfalse, it’s still a good idea to keep them configured sensibly in case you ever need to re-enable pooling later.
内容的提问来源于stack exchange,提问作者cgon

