PSQLException: An I/O error occurred问题排查和解决
环境
- bootstrap 2.5.x
- postgres,13.3
- druid连接池
- jdk11
问题描述
- 生产环境web页面上查询数据频繁报Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
An I/O error occurred while sending to the backend.; nested exception is org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend. - 单独编写jdbc程序测试,单独执行SQL结果都正常
- 数据库迁移到本地测试,web页面响应正常。
排查结果
- 中间过程不细说了,一波三折的。最后结论是,生产环境客户的postgres不知怎么配置的,反正是连接后很快就连接失效,有可能是设置了超时时间等,没时间详查了。
- 起初为了提高性能,我的druid的testOnBorrow和testOnReturn都设置的是false,这样就不能及时检测到连接失效,当SQL使用一个无效的连接查询的时候,就会报出以上错误。
- 本案中,将以上两个参数设置为true,当发现连接无效时,重新获取新连接放入连接池,就解决问题了。
- 如果还想继续调优,可以考虑再调调testWhileIdle、maxEvictableIdleTimeMillis、minEvictableIdleTimeMillis、timeBetweenEvictionRunsMillis等参数。