pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Tomasz Ostrowski <tometzky+pg@ato.waw.pl>
To: pgsql-general@lists.postgresql.org
Subject: Re: Long running query - connection and keepalives enabled but query not canceled
Date: Tue, 04 Jun 2019 18:24:09 +0200
Message-ID: <f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at> (raw)
In-Reply-To: <3dff056c-ac66-301f-e4be-cf0dca87c076@ato.waw.pl>
References: <3dff056c-ac66-301f-e4be-cf0dca87c076@ato.waw.pl>

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






view thread (5+ messages)  latest in thread

Message-ID: <f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at>
Permalink:  ../f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at/
Also on:    postgresql.org/message-id/f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, tometzky+pg@ato.waw.pl
  Subject: Re: Long running query - connection and keepalives enabled but query not canceled
  In-Reply-To: <f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at>
  References: <3dff056c-ac66-301f-e4be-cf0dca87c076@ato.waw.pl> <f45d9032fad8d875a612df552e5b6a6a84b70da3.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox