java - (此连接已关闭。)。使用 hikari 连接 PostgreSQL 时可能考虑使用更短的 maxLifetime 值
问题描述
我在 Spring Boot 项目中使用 Hikari 连接 PostgreSQL 13 数据库,现在日志显示以下警告:
[12:23:49:633] [WARN] - com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:158) - HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@a54a5357 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
[12:23:49:634] [WARN] - com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:158) - HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@5d8a4eb4 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
[12:23:49:636] [WARN] - com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:158) - HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@18564799 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
第一步,我idle_in_transaction_session_timeout
像这样调整 PostgreSQL 13 数据库参数:
alter system set idle_in_transaction_session_timeout='30min';
show idle_in_transaction_session_timeout;
我确保将 PostgreSQL 13 数据库idle_in_transaction_session_timeout
参数设置为 30 分钟。下一步我application.properties
像这样调整我的 Hikari 的 maxLifeTime:
spring.datasource.hikari.max-lifetime=900000
Hikari maxLifeTime 已经小于数据库连接空闲连接时间,但是警告信息并没有消失。我错过了什么吗?我应该怎么做才能修复警告消息?
解决方案
推荐阅读
- java - 我该如何处理这个错误“在任何可用的数据中心中找不到合适的主机。”?
- vue.js - Route.push 在第二次尝试中无法正常工作
- python - 如何调试由 crontab 执行的 python 脚本?
- java - 粘贴输入时,Java Stream 仅复制第一行
- reactjs - JWT 身份验证令牌未定义
- javascript - VueJS没有在for循环内渲染数据集
- php - 无法安装php包?
- pickle - 如何保存带有 Drake 植物对象的类对象?
- r - r中的异常值处理极端异常值
- javascript - 带有 Vue.Js 的 CanvasJS - 在 mousemove 上更新 JSON 数据