pgsql: Detect POLLHUP/POLLRDHUP while running queries.

From: Thomas Munro <tmunro(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Detect POLLHUP/POLLRDHUP while running queries.
Date: 2021-04-02 20:25:25
Message-ID: E1lSQM9-00050p-FR@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Detect POLLHUP/POLLRDHUP while running queries.

Provide a new GUC check_client_connection_interval that can be used to
check whether the client connection has gone away, while running very
long queries. It is disabled by default.

For now this uses a non-standard Linux extension (also adopted by at
least one other OS). POLLRDHUP is not defined by POSIX, and other OSes
don't have a reliable way to know if a connection was closed without
actually trying to read or write.

In future we might consider trying to send a no-op/heartbeat message
instead, but that could require protocol changes.

Author: Sergey Cherkashin <s(dot)cherkashin(at)postgrespro(dot)ru>
Author: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Reviewed-by: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Reviewed-by: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>
Reviewed-by: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
Reviewed-by: Zhihong Yu <zyu(at)yugabyte(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Maksim Milyutin <milyutinma(at)gmail(dot)com>
Reviewed-by: Tsunakawa, Takayuki/綱川 貴之 <tsunakawa(dot)takay(at)fujitsu(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> (much earlier version)
Discussion: https://postgr.es/m/77def86b27e41f0efcba411460e929ae%40postgrespro.ru

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c30f54ad732ca5c8762bb68bbe0f51de9137dd72

Modified Files
--------------
doc/src/sgml/config.sgml | 37 +++++++++++++++++++++++++
src/backend/libpq/pqcomm.c | 40 +++++++++++++++++++++++++++
src/backend/tcop/postgres.c | 32 +++++++++++++++++++++
src/backend/utils/init/globals.c | 1 +
src/backend/utils/init/postinit.c | 10 +++++++
src/backend/utils/misc/guc.c | 29 +++++++++++++++++++
src/backend/utils/misc/postgresql.conf.sample | 3 ++
src/include/libpq/libpq.h | 1 +
src/include/miscadmin.h | 1 +
src/include/tcop/tcopprot.h | 1 +
src/include/utils/timeout.h | 1 +
11 files changed, 156 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2021-04-02 20:42:45 pgsql: Use macro MONTHS_PER_YEAR instead of '12' in /ecpg/pgtypeslib
Previous Message Joe Conway 2021-04-02 17:51:52 pgsql: Clarify documentation of RESET ROLE