3

I have a few long-running queries that I'm executing against a remote instance of Postgres (AWS RDS). When I execute any of these queries, I get a network timeout on my client after a couple of minutes.

Does the query continue to run even though the client connection timed-out?

These particular queries do updates and deletes, so I don't need any information back from the query, I just need to know that they completed. I've tried with both psql (locally on my machine, not on the server; I can't run it on the server because it's on RDS), and Datagrip, but the timeout happens for both.

There's a similar question here, but it contains two contradictory answers. Alternatively, is there a way to execute a query fire-and-forget style, where the server wont send information back at all?

  • As far as I can tell the update / delete completes eventually. This is more of a one-off migration situation. I don't need it as a service. – Jordan Sep 6 at 20:29
4

If your database connection is terminated without properly closing it (from the server side: if the client just silently dies), and running query will continue until one of these two things happen:

  • The query produces a result row, the server tries to send it to the client and gets a network error.

  • The operating system starts sending keepalive packages, because the connection has been idle for a long time (by default, 2 hours). The system will lend a couple of these packages, and when there is no answer, the connection is closed. As soon as PostgreSQL checks for interrupts, the running query should terminate.

You can set the tcp_keepalives_idle parameter to adjust that timeout. This can help the server to detect broken connections more quickly.

When the client is gone, and the query is still running, system resources are used, but there is no danger that this will cause any modifications in the database: eventually the transaction (be it a single statement or a longer transaction) will encounter an error and will be rolled back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.