[英]Postgres 11.8 on AWS Losing Connection/Terminating Query After 15 Minutes with No Notification or Error
I am running into an issue where multiple different clients apps (DataGrip, DBeaver, Looker) have their queries cancelled after exactly 15 minutes, but no termination message or connection error is ever sent to the app.我遇到了一个问题,即多个不同的客户端应用程序(DataGrip、DBeaver、Looker)在 15 分钟后取消了他们的查询,但没有向应用程序发送终止消息或连接错误。 As far as the app is concerned, the query is still running even though it has been terminated in Postgres.就应用程序而言,即使查询已在 Postgres 中终止,它仍在运行。
For example, if I run the following query, according to the client app it just runs forever.例如,如果我运行以下查询,根据客户端应用程序,它会永远运行。 If I check pg_stat_activity, it shows the query no longer running after 15 minutes.如果我检查 pg_stat_activity,它会显示查询在 15 分钟后不再运行。
SELECT pg_sleep(16 * 60);
Does anyone know of a Postgres or AWS setting that would cause this?有谁知道会导致这种情况的 Postgres 或 AWS 设置? I've checked the configuration and couldn't find any settings set to a value of 15 minutes (or 900 seconds).我检查了配置,但找不到任何设置为 15 分钟(或 900 秒)值的设置。
There is probably a ill-configured firewall that closes your session.可能有一个配置不当的防火墙会关闭您的会话。
Assuming that the clients you are mentioning use libpq
to connect to PostgreSQL, include this in the connection string:假设您提到的客户端使用libpq
连接到 PostgreSQL,请将其包含在连接字符串中:
keepalives_idle=300
See the documentation for details.有关详细信息,请参阅文档。
You could of course also configure the TCP stack on your operating system to use that value, so the problem will never surface again.您当然也可以在操作系统上配置 TCP 堆栈以使用该值,这样问题就不会再次出现。
Your DB log might be able to tell you what happened.您的数据库日志可能会告诉您发生了什么。
In addition, check your statement_timeout
setting.此外,请检查您的statement_timeout
设置。 The units are milliseconds so you should be looking for 900000
, not 900
.单位是毫秒,所以你应该寻找900000
,而不是900
。
If it's not that, there exist firewalls that kill idle connections.如果不是这样,则存在杀死空闲连接的防火墙。 Setting tcp_keepalives_idle
could help avoid those types of problems.设置tcp_keepalives_idle
可以帮助避免这些类型的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.