【发布时间】:2014-05-06 23:10:07
【问题描述】:
在让数据库连接闲置一段时间后,我的应用程序中出现以下异常:
... An I/O error occured while sending to the backend.; nested exception is org.postgresql.util.PSQLException: An I/O error occured while sending to the backend.] with root cause
java.net.SocketException: Operation timed out
at java.net.SocketInputStream.socketRead0(Native Method)
同样的问题发生在 psql 中,我没有连接到本地数据库的问题,所以我很确定问题出在 RDS 上。
psql=> select 'ok';
SSL SYSCALL error: Operation timed out
psql=> select 'ok';
SSL SYSCALL error: EOF detected
The connection to the server was lost. Attempting reset: Succeeded.
我发现了这个other question,它提出了一种解决方法,可以改善这种情况(超时现在需要更长的时间),但没有解决。
我正在使用带有 JDBC(tomcat 连接池)和 JDBCTemplate 的 Spring Boot。
有解决方法或修复方法吗? 也许强制连接池测试并重新连接? 在这种环境下我该怎么做?
编辑: 这是我的连接字符串
jdbc:postgresql://myhost.c2estvxozjm3.eu-west-1.rds.amazonaws.com/dashboard?tcpKeepAlive=true
解决方案:
按照所选答案中的建议编辑了 RDS 服务器端 TCP_KeepAlive 参数。我使用的参数是:
tcp_keepalives_count 5
tcp_keepalives_idle 200
tcp_keepalives_interval 200
【问题讨论】:
标签: postgresql amazon-rds spring-jdbc spring-boot