从Azure连接到Amazon RDS上的Postgres数据库的超时

编程入门 行业动态 更新时间:2024-10-26 00:27:49
本文介绍了从Azure连接到Amazon RDS上的Postgres数据库的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在数据库连接保持空闲一段时间后,我的应用程序中出现以下异常:

...发送到后端时发生I/O错误.嵌套的异常是org.postgresql.util.PSQLException:发送到后端时发生I/O错误.java.SocketException:操作超时在java.SocketInputStream.socketRead0(本地方法)

psql中也发生了同样的问题,而且我没有连接到本地数据库的问题,所以我很确定问题出在RDS上.

psql =>选择确定";SSL SYSCALL错误:操作超时psql =>选择确定";SSL SYSCALL错误:检测到EOF与服务器的连接已丢失.尝试重置:成功.

我发现了这个其他问题,这表明围绕该问题的一项工作可以改善情况(超时现在需要更长的时间),但并没有解决.

我正在将Spring Boot与JDBC(tomcat连接池)和JDBCTemplate一起使用.

是否有解决方法或解决方法?也许强迫连接池进行测试并重新连接?在这种环境下我该怎么做?

这是我的连接字符串

jdbc:postgresql://myhost.c2estvxozjm3.eu-west-1.rds.amazonaws/dashboard?tcpKeepAlive = true

解决方案:

根据所选答案中的建议,编辑了RDS服务器端TCP_KeepAlive参数.我正在使用的参数是:

tcp_keepalives_count 5tcp_keepalives_idle 200tcp_keepalives_interval 200

解决方案

连接跟踪,或者在一段时间后忘记连接./p>

我建议启用TCP Keepalive .您可能可以在AWS RDS配置中在服务器端启用它们.如果没有,则可以在JDBC驱动程序中请求它们在客户端.

TCP保持连接比验证/测试查询要好得多,因为它们的开销要低得多,并且不会在服务器查询日志中导致不必要的日志垃圾邮件.

I get the following exception in my application after leaving a database connection idle for some amount of time:

... 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.SocketException: Operation timed out at java.SocketInputStream.socketRead0(Native Method)

The same issue happens in psql AND I don't have issues connecting to a local database, so I'm pretty sure the problem is on 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.

I found this other question which suggests a work around that improved the situation (timeouts now take a lot longer) but didn't fix it.

I'm using Spring Boot with JDBC (tomcat connection pooling) and JDBCTemplate.

Is there a work around or a fix? Perhaps forcing the connection pool to test and reconnect? How do I do that in this environment?

EDIT: This is my connection string

jdbc:postgresql://myhost.c2estvxozjm3.eu-west-1.rds.amazonaws/dashboard?tcpKeepAlive=true

SOLUTION:

Edited the RDS server side TCP_KeepAlive parameters as suggested in the selected answer. The parameters I'm using are:

tcp_keepalives_count 5 tcp_keepalives_idle 200 tcp_keepalives_interval 200

解决方案

It looks like something - maybe a NAT router on your end, maybe something on AWS's end - is connection tracking, and is forgetting about connections after a while.

I suggest enabling TCP keepalives. You might be able to enable them server side in the AWS RDS configuration; if not, you can request them client-side in the JDBC driver.

TCP keepalives are a lot better than a validation/test query, because they're much lower overhead, and they don't result in unnecessary log spam in the server query logs.

更多推荐

从Azure连接到Amazon RDS上的Postgres数据库的超时

本文发布于:2023-10-23 22:32:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522193.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   数据库   Azure   Amazon   Postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!