Re: Long running query - connection and keepalives enabled but query not canceled

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tomasz Ostrowski <tometzky+pg(at)ato(dot)waw(dot)pl>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Long running query - connection and keepalives enabled but query not canceled
Date: 2019-06-04 16:24:09
Message-ID: f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tomasz Ostrowski wrote:
> I have database users which have to run some ad-hoc queries on the
> database. These queries sometimes are pretty long running, especially
> when a user messes up a join condition for two 1Grows tables and
> therefore tries to count the number of quarks in the universe or
> something like this.
>
> After a query fails to return result for some time the user sometimes
> just closes his laptop lid, dropping his VPN connection and goes home to
> watch some cats on the Internet.
>
> The TCP keepalives functionality on the database server's operating
> system would figure out that the connection is not working anymore and
> close it.
>
> You'd assume that the database would get the info and cancel the query.
> Except - it does not.
>
> The database would get an error on the connection socket only after it
> tries to read or write to it next time. But it does not try to do this -
> it's busy counting those quarks until statement_timeout is reached.

By default "tcp_keepalives_idle" is quite large: 2 hours.

Are you sure that the queries keep running for longer than that?

Try to experiment with lower settings. It will cause marginally more
network traffic, but dead connections will be detected more quickly.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthias Apitz 2019-06-04 16:26:50 Re: Two small questions re/ COPY CSV data into table
Previous Message Tomasz Ostrowski 2019-06-04 15:54:24 Long running query - connection and keepalives enabled but query not canceled