Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYCEi-0001OA-8n for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2019 16:24:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hYCEh-00042d-56 for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2019 16:24:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYCEg-00042S-R3 for pgsql-general@lists.postgresql.org; Tue, 04 Jun 2019 16:24:30 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYCEd-0005pC-Hw for pgsql-general@lists.postgresql.org; Tue, 04 Jun 2019 16:24:30 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 1B7F1A01BB; Tue, 4 Jun 2019 18:24:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id FNFzYe3Jq-Yk; Tue, 4 Jun 2019 18:24:10 +0200 (CEST) Message-ID: Subject: Re: Long running query - connection and keepalives enabled but query not canceled From: Laurenz Albe To: Tomasz Ostrowski , pgsql-general@lists.postgresql.org Date: Tue, 04 Jun 2019 18:24:09 +0200 In-Reply-To: <3dff056c-ac66-301f-e4be-cf0dca87c076@ato.waw.pl> References: <3dff056c-ac66-301f-e4be-cf0dca87c076@ato.waw.pl> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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