mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Add support TCP user timeout in libpq and the backend server
Similarly to the set of parameters for keepalive, a connection parameter for libpq is added as well as a backend GUC, called tcp_user_timeout. Increasing the TCP user timeout is useful to allow a connection to survive extended periods without end-to-end connection, and decreasing it allows application to fail faster. By default, the parameter is 0, which makes the connection use the system default, and follows a logic close to the keepalive parameters in its handling. When connecting through a Unix-socket domain, the parameters have no effect. Author: Ryohei Nagaura Reviewed-by: Fabien Coelho, Robert Haas, Kyotaro Horiguchi, Kirk Jamison, Mikalai Keida, Takayuki Tsunakawa, Andrei Yahorau Discussion: https://postgr.es/m/EDA4195584F5064680D8130B1CA91C45367328@G01JPEXMBYT04
This commit is contained in:
@ -182,9 +182,11 @@ static const char *show_archive_command(void);
|
||||
static void assign_tcp_keepalives_idle(int newval, void *extra);
|
||||
static void assign_tcp_keepalives_interval(int newval, void *extra);
|
||||
static void assign_tcp_keepalives_count(int newval, void *extra);
|
||||
static void assign_tcp_user_timeout(int newval, void *extra);
|
||||
static const char *show_tcp_keepalives_idle(void);
|
||||
static const char *show_tcp_keepalives_interval(void);
|
||||
static const char *show_tcp_keepalives_count(void);
|
||||
static const char *show_tcp_user_timeout(void);
|
||||
static bool check_maxconnections(int *newval, void **extra, GucSource source);
|
||||
static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
|
||||
static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
|
||||
@ -530,6 +532,7 @@ char *application_name;
|
||||
int tcp_keepalives_idle;
|
||||
int tcp_keepalives_interval;
|
||||
int tcp_keepalives_count;
|
||||
int tcp_user_timeout;
|
||||
|
||||
/*
|
||||
* SSL renegotiation was been removed in PostgreSQL 9.5, but we tolerate it
|
||||
@ -3182,6 +3185,17 @@ static struct config_int ConfigureNamesInt[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"tcp_user_timeout", PGC_USERSET, CLIENT_CONN_OTHER,
|
||||
gettext_noop("TCP user timeout."),
|
||||
gettext_noop("A value of 0 uses the system default."),
|
||||
GUC_UNIT_MS
|
||||
},
|
||||
&tcp_user_timeout,
|
||||
0, 0, INT_MAX,
|
||||
NULL, assign_tcp_user_timeout, show_tcp_user_timeout
|
||||
},
|
||||
|
||||
/* End-of-list marker */
|
||||
{
|
||||
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
|
||||
@ -11238,6 +11252,23 @@ show_tcp_keepalives_count(void)
|
||||
return nbuf;
|
||||
}
|
||||
|
||||
static void
|
||||
assign_tcp_user_timeout(int newval, void *extra)
|
||||
{
|
||||
/* See comments in assign_tcp_keepalives_idle */
|
||||
(void) pq_settcpusertimeout(newval, MyProcPort);
|
||||
}
|
||||
|
||||
static const char *
|
||||
show_tcp_user_timeout(void)
|
||||
{
|
||||
/* See comments in assign_tcp_keepalives_idle */
|
||||
static char nbuf[16];
|
||||
|
||||
snprintf(nbuf, sizeof(nbuf), "%d", pq_gettcpusertimeout(MyProcPort));
|
||||
return nbuf;
|
||||
}
|
||||
|
||||
static bool
|
||||
check_maxconnections(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
|
Reference in New Issue
Block a user