1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

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.cherkashin@postgrespro.ru>
Author: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Tatsuo Ishii <ishii@sraoss.co.jp>
Reviewed-by: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
Reviewed-by: Zhihong Yu <zyu@yugabyte.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Maksim Milyutin <milyutinma@gmail.com>
Reviewed-by: Tsunakawa, Takayuki/綱川 貴之 <tsunakawa.takay@fujitsu.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> (much earlier version)
Discussion: https://postgr.es/m/77def86b27e41f0efcba411460e929ae%40postgrespro.ru
This commit is contained in:
Thomas Munro
2021-04-03 08:52:30 +13:00
parent 174edbe9f9
commit c30f54ad73
11 changed files with 156 additions and 0 deletions

View File

@ -998,6 +998,43 @@ include_dir 'conf.d'
</listitem>
</varlistentry>
<varlistentry id="guc-client-connection-check-interval" xreflabel="client_connection_check_interval">
<term><varname>client_connection_check_interval</varname> (<type>integer</type>)
<indexterm>
<primary><varname>client_connection_check_interval</varname> configuration parameter</primary>
</indexterm>
</term>
<listitem>
<para>
Sets the time interval between optional checks that the client is still
connected, while running queries. The check is performed by polling
the socket, and allows long running queries to be aborted sooner if
the kernel reports that the connection is closed.
</para>
<para>
This option is currently available only on systems that support the
non-standard <symbol>POLLRDHUP</symbol> extension to the
<symbol>poll</symbol> system call, including Linux.
</para>
<para>
If the value is specified without units, it is taken as milliseconds.
The default value is <literal>0</literal>, which disables connection
checks. Without connection checks, the server will detect the loss of
the connection only at the next interaction with the socket, when it
waits for, receives or sends data.
</para>
<para>
For the kernel itself to detect lost TCP connections reliably and within
a known timeframe in all scenarios including network failure, it may
also be necessary to adjust the TCP keepalive settings of the operating
system, or the <xref linkend="guc-tcp-keepalives-idle"/>,
<xref linkend="guc-tcp-keepalives-interval"/> and
<xref linkend="guc-tcp-keepalives-count"/> settings of
<productname>PostgreSQL</productname>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>