简体   繁体   中英

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. As far as the app is concerned, the query is still running even though it has been terminated in 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.

SELECT pg_sleep(16 * 60);

Does anyone know of a Postgres or AWS setting that would cause this? I've checked the configuration and couldn't find any settings set to a value of 15 minutes (or 900 seconds).

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:

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.

Your DB log might be able to tell you what happened.

In addition, check your statement_timeout setting. The units are milliseconds so you should be looking for 900000 , not 900 .

If it's not that, there exist firewalls that kill idle connections. Setting tcp_keepalives_idle could help avoid those types of problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM