mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +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:
@@ -20,6 +20,9 @@
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_POLL_H
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
@@ -204,6 +207,7 @@ static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource sourc
|
||||
static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
|
||||
static bool check_maintenance_io_concurrency(int *newval, void **extra, GucSource source);
|
||||
static bool check_huge_page_size(int *newval, void **extra, GucSource source);
|
||||
static bool check_client_connection_check_interval(int *newval, void **extra, GucSource source);
|
||||
static void assign_pgstat_temp_directory(const char *newval, void *extra);
|
||||
static bool check_application_name(char **newval, void **extra, GucSource source);
|
||||
static void assign_application_name(const char *newval, void *extra);
|
||||
@@ -3501,6 +3505,17 @@ static struct config_int ConfigureNamesInt[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"client_connection_check_interval", PGC_USERSET, CLIENT_CONN_OTHER,
|
||||
gettext_noop("Sets the time interval between checks for disconnection while running queries."),
|
||||
NULL,
|
||||
GUC_UNIT_MS
|
||||
},
|
||||
&client_connection_check_interval,
|
||||
0, 0, INT_MAX,
|
||||
check_client_connection_check_interval, NULL, NULL
|
||||
},
|
||||
|
||||
/* End-of-list marker */
|
||||
{
|
||||
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
|
||||
@@ -11980,6 +11995,20 @@ check_huge_page_size(int *newval, void **extra, GucSource source)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
check_client_connection_check_interval(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
#ifndef POLLRDHUP
|
||||
/* Linux only, for now. See pq_check_connection(). */
|
||||
if (*newval != 0)
|
||||
{
|
||||
GUC_check_errdetail("client_connection_check_interval must be set to 0 on platforms that lack POLLRDHUP.");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
assign_pgstat_temp_directory(const char *newval, void *extra)
|
||||
{
|
||||
|
Reference in New Issue
Block a user