使用 HikariPool数据源,连接postgresql 超时之后,一直连接不上

postgresql 连接超时:Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 10000ms.

img


出现这个问题后,会一直连接不上数据库,重启jar包之后就没事了,之前修改了一下数据源相关的连接数配置,pgsql的最大连接配置设置成了100,没有什么效果。

数据源配置:


hikari:
  auto-commit: false
  connection-timeout: 10000
  idle-timeout: 25000
  login-timeout: 5
  max-lifetime: 30000
  read-only: false
  validation-timeout: 3000
  maximum-pool-size: 100
  minimum-idle: 30
  data-source-properties:
    cachePrepStmts: true
    prepStmtCacheSize: 250
    prepStmtCacheSqlLimit: 2048
    useServerPrepStmts: true
    useLocalSessionState: true
    rewriteBatchedStatements: true
    cacheResultSetMetadata: true
    cacheServerConfiguration: true
    elideSetAutoCommits: true
    maintainTimeStats: false

这个项目每隔20s会执行两三个定时任务,我怀疑是不是定时任务产生的这个问题。

是不是连接池中的连接一直被占用,没有被释放。
可以参考:https://www.cnblogs.com/chengmuyu/p/16512251.html

应该是你使用原生的Jdbc连接,没有关闭连接导致的,或者使用JDbc连接的时候,设置一下超时时间。