java - 无法从 PgBouncer 打开连接(连接尝试超时)

标签 java spring hibernate hikaricp pgbouncer

我们使用 PgBouncer 作为基于 spring 的应用程序的连接池中间件。在应用程序中,我们使用 HikariCP 进行应用程序级连接池。

我们将 HikariCP 的 maxLifeTime 值设置为一小时,并将 idleTimeOut 设置为 30 秒。

我观察到,当应用程序在长时间空闲时间后收到请求时,我们会收到此错误:

Caused by: org.postgresql.util.PSQLException: Connection attempt timed out. at 
org.postgresql.Driver$ConnectThread.getResult(Driver.java:376) at
org.postgresql.Driver.connect(Driver.java:288) at
java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:247) at
org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:88) at
org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:71) at
com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:398) at
com.zaxxer.hikari.pool.HikariPool.lambda$addBagItem$2(HikariPool.java:309) at 

最佳答案

仅选择一个连接池 PGBouncer/HikariCP

Consider using either PGBouncer in front your Postgres installation or any library for your language that deals with reusable connections by its own. Say, for Clojure, HikariCP would be a good choice

注意有一个 open issue for Hikari to support PGBouncer

Each app is using hikariCp with a maxPool of 10 and I have ~10 apps using it. I have a PgPool in front but it doesn't seem to be reusing connection that much. It seems like each app instance is trying to maintain it's own pool alive all the time making PgPool useless.

关于java - 无法从 PgBouncer 打开连接(连接尝试超时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57756239/

相关文章:

java - 我想编辑我的类的第四个变量,但我似乎将它们全部编辑

java - Java 中的全局异常处理程序

spring - 从 AuthenticationSuccessHandler 访问 RequestContextHolder 和 HttpServletRequest.getUserPrincipal()

java - Spring Controller LoggingAspect不拦截方法

java - 调用 Query.uniqueResult() 时出现 ClassCastException

java - 是什么导致 JBoss 7.1.1 中出现此 SQL/Hibernate 错误?

java - jackson 无法用连字符反序列化字段

spring - 如何配置 "health"Actuator 端点以使用 token 身份验证?

mysql - 尝试在 Spring Boot 中更新时间表时出错

java - java注解能做什么,不能做什么?