Springboot HikariCP

Fab*_*ner 5 postgresql spring-data-jpa spring-boot hikaricp

我将 springboot 与 HikariCP 一起使用,但过了一段时间我的应用程序崩溃并出现错误:

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
...

Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

....
Caused by: java.sql.SQLTransientConnectionException: HikariPool-6 - Connection is not available, request timed out after 30000ms.
Run Code Online (Sandbox Code Playgroud)

这是我的 aplication.properties

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/db_dnaso
#spring.datasource.url=jdbc:postgresql://172.16.1.10:5432/db_dnaso
spring.datasource.username=postgres
spring.datasource.password=dna44100
spring.datasource.driver-class-name=org.postgresql.Driver
Run Code Online (Sandbox Code Playgroud)

所以我有很多保存、查找和其他人访问数据库的权限,我如何可视化方法如何阻止我的连接?

tks

Smi*_*t K 7

您的数据库服务器似乎失去了连接。Hikari 中属性的默认值为maximumPoolSize10。这意味着它将在服务器启动时尝试创建 10 个连接,如果无法获取 10 个连接,它将不会启动,或者如果您的数据库服务器池大小在池中的连接数少于您,则可能会失败正在使用 Hikari 配置进行创建。如果您能够启动 Spring Boot 服务器,然后遇到此问题,请尝试启用leakDetectionThreshold并检查哪个连接花费更多时间并且未返回 Hikari 池。

spring:
  datasource:        
    hikari:                    
      leak-detection-threshold: 2000
Run Code Online (Sandbox Code Playgroud)


bre*_*ttw 2

启用leakDetectionThreshold,设置为 1 分钟(60000 毫秒)之类的值。您可能在某处存在连接泄漏...连接被借用但从未关闭(返回)。