PGPool无法在SpringBoot应用程序中与HikariCP配合使用

时间:2018-08-10 02:30:40

标签: postgresql spring-boot spring-data-jpa pgpool

我已为Postgresql启用复制,并且我正在使用PGPool进行负载平衡。

使用HikariCP甚至使用Apache DBCP连接到Postgres时遇到问题。

是否可以在SpringBoot应用程序中使用PGPool?

请找到配置文件

spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://192.168.177.148:9999/test
    username: myUser
    password: XXXXXXX
  jpa:
    properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    hibernate.ddl-auto: update
logging:
  level:
    org.springframework: DEBUG

请找到堆栈跟踪:

  

2018-08-10 10:20:19.124 INFO 37879 --- [主]   com.zaxxer.hikari.HikariDataSource:HikariPool-1-正在启动...   2018-08-10 10:20:20.617错误37879 --- [main] com.zaxxer.hikari.pool.HikariPool:HikariPool-1-池初始化期间发生异常。

     

org.postgresql.util.PSQLException:严重:无法绑定     详细信息:无法解析消息“”       在org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.SetupQueryRunner.run(SetupQueryRunner.java:53)〜[postgresql-42.2.4.jar:42.2.4]

     

018-08-10 10:20:20.620警告37879 --- [main] o.s.b.a.orm.jpa.DatabaseLookup:无法从数据源确定jdbc网址

更多跟踪

  

org.springframework.jdbc.support.MetaDataAccessException:无法获取用于提取元数据的Connection。嵌套的异常是org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取JDBC连接。嵌套的异常是org.postgresql.util.PSQLException:致命:无法绑定     详细信息:无法解析消息“”       在org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:328)〜[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]       在org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)〜[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]       在org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)〜[spring-boot-autoconfigure-2.0.4.RELEASE.jar:2.0.4.RELEASE]

更多跟踪

  

由以下原因引起:org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取JDBC连接。嵌套的异常是org.postgresql.util.PSQLException:致命:无法绑定     详细信息:无法解析消息“”       在org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81)〜[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]       在org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)〜[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]       ...省略了61个通用框架   引起原因:org.postgresql.util.PSQLException:致命:无法绑定     详细信息:无法解析消息“”       在org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.SetupQueryRunner.run(SetupQueryRunner.java:53)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.ConnectionFactoryImpl.runInitialQueries(ConnectionFactoryImpl.java:674)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:223)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.jdbc.PgConnection。(PgConnection.java:195)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.Driver.makeConnection(Driver.java:454)〜[postgresql-42.2.4.jar:42.2.4]       在org.postgresql.Driver.connect(Driver.java:256)〜[postgresql-42.2.4.jar:42.2.4]       在com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)〜[HikariCP-2.7.9.jar:na]       在com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)〜[HikariCP-2.7.9.jar:na]       在com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)〜[HikariCP-2.7.9.jar:na]

1 个答案:

答案 0 :(得分:0)

我们的场景

我们在Kubernetes集群上也遇到了几乎相同的问题。数据库已关闭,HikariCP无法正确验证连接。春季启动应用程序给出了以下异常:

2020-01-06 09:38:13.013  WARN 1 --- [nio-8080-exec-8] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@490c2ee7 (This connection has been closed.)

2020-01-06 09:38:13.045  WARN 1 --- [nio-8080-exec-8] org.postgresql.jdbc.PgConnection         : Validating connection.

org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:333) ~[postgresql-42.2.2.jar!/:42.2.2]

    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) ~[postgresql-42.2.2.jar!/:42.2.2]
... common frames omitted

Caused by: java.io.EOFException: null

    at org.postgresql.core.PGStream.receiveChar(PGStream.java:295) ~[postgresql-42.2.2.jar!/:42.2.2]

    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1947) ~[postgresql-42.2.2.jar!/:42.2.2]

    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306) ~[postgresql-42.2.2.jar!/:42.2.2]

    ... 111 common frames omitted
解决方案

为解决此问题,我们在春季启动应用程序中为Hikari提供了以下属性。

spring.datasource.hikari.leakDetectionThreshold=5000  
spring.datasource.hikari.maxLifetime=900000  
logging.level.com.zaxxer.hikari=DEBUG
参考