postgresql – 从Azure上连接到Amazon RDS上的Postgres数据库的
发布时间:2020-12-13 16:32:43 所属栏目:百科 来源:网络整理
导读:在数据库连接空闲一段时间后,我的应用程序中会收到以下异常: ... 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 ja
在数据库连接空闲一段时间后,我的应用程序中会收到以下异常:
... 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,这表明一个工作,改善了情况(超时现在需要更长的时间),但没有解决它. 我使用Spring引导与JDBC(tomcat连接池)和JDBCTemplate. 有没有工作或修复? 编辑: 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
它看起来像是一些东西 – 也许你的终端上的NAT路由器,也许是在AWS的一端 – 连接跟踪,并在一段时间后忘记连接.
我建议enabling TCP keepalives.您可能可以在AWS RDS配置中启用它们的服务器端;如果没有,您可以在JDBC驱动程序中向客户端请求它们. TCP keepalives比验证/测试查询好多了,因为它们的开销要低得多,并且不会在服务器查询日志中导致不必要的日志垃圾邮件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |