mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Always set "connect_timeout" when pinging a PostgreSQL instance
Insert "connect_timeout=2" into the connection parameters, if not explicitly set by the user. This will prevent excessive wait time for the host operating system to report a connection timeout.
This commit is contained in:
1
HISTORY
1
HISTORY
@@ -1,6 +1,7 @@
|
||||
4.0.5 2018-??-??
|
||||
repmgr: fix display of conninfo parsing error messages (Ian)
|
||||
repmgrd: fix memory leaks in witness code (AndrzejNowicki, Martín)
|
||||
repmgrd: set "connect_timeout=2" when pinging a server (Ian)
|
||||
|
||||
4.0.4 2018-03-09
|
||||
repmgr: add "standby clone --recovery-conf-only" option; GitHub #382 (Ian)
|
||||
|
||||
22
dbutils.c
22
dbutils.c
@@ -3849,6 +3849,28 @@ is_server_available(const char *conninfo)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_server_available_params(t_conninfo_param_list *param_list)
|
||||
{
|
||||
PGPing status = PQpingParams((const char **) param_list->keywords,
|
||||
(const char **) param_list->values,
|
||||
false);
|
||||
|
||||
/* deparsing the param_list adds overhead, so only do it if needed */
|
||||
if (log_level == LOG_DEBUG)
|
||||
{
|
||||
char *conninfo_str = param_list_to_string(param_list);
|
||||
log_verbose(LOG_DEBUG, "ping status for %s is %i", conninfo_str, (int)status);
|
||||
pfree(conninfo_str);
|
||||
}
|
||||
|
||||
if (status == PQPING_OK)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* ==================== */
|
||||
/* monitoring functions */
|
||||
/* ==================== */
|
||||
|
||||
@@ -465,6 +465,7 @@ int wait_connection_availability(PGconn *conn, long long timeout);
|
||||
|
||||
/* node availability functions */
|
||||
bool is_server_available(const char *conninfo);
|
||||
bool is_server_available_params(t_conninfo_param_list *param_list);
|
||||
|
||||
/* monitoring functions */
|
||||
void
|
||||
|
||||
23
repmgrd.c
23
repmgrd.c
@@ -703,17 +703,29 @@ PGconn *
|
||||
try_reconnect(t_node_info *node_info)
|
||||
{
|
||||
PGconn *conn;
|
||||
t_conninfo_param_list conninfo_params = T_CONNINFO_PARAM_LIST_INITIALIZER;
|
||||
|
||||
int i;
|
||||
|
||||
int max_attempts = config_file_options.reconnect_attempts;
|
||||
|
||||
initialize_conninfo_params(&conninfo_params, false);
|
||||
|
||||
|
||||
/* we assume by now the conninfo string is parseable */
|
||||
(void) parse_conninfo_string(node_info->conninfo, &conninfo_params, NULL, false);
|
||||
|
||||
/* set some default values if not explicitly provided */
|
||||
param_set_ine(&conninfo_params, "connect_timeout", "2");
|
||||
param_set_ine(&conninfo_params, "fallback_application_name", "repmgr");
|
||||
|
||||
for (i = 0; i < max_attempts; i++)
|
||||
{
|
||||
log_info(_("checking state of node %i, %i of %i attempts"),
|
||||
node_info->node_id, i + 1, max_attempts);
|
||||
if (is_server_available(node_info->conninfo) == true)
|
||||
if (is_server_available_params(&conninfo_params) == true)
|
||||
{
|
||||
|
||||
log_notice(_("node has recovered, reconnecting"));
|
||||
|
||||
/*
|
||||
@@ -721,9 +733,13 @@ try_reconnect(t_node_info *node_info)
|
||||
* connection denied due to connection exhaustion - fall back to
|
||||
* degraded monitoring? - make that configurable
|
||||
*/
|
||||
conn = establish_db_connection(node_info->conninfo, false);
|
||||
|
||||
conn = establish_db_connection_by_params(&conninfo_params, false);
|
||||
|
||||
if (PQstatus(conn) == CONNECTION_OK)
|
||||
{
|
||||
free_conninfo_params(&conninfo_params);
|
||||
|
||||
node_info->node_status = NODE_STATUS_UP;
|
||||
return conn;
|
||||
}
|
||||
@@ -740,13 +756,14 @@ try_reconnect(t_node_info *node_info)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log_warning(_("unable to reconnect to node %i after %i attempts"),
|
||||
node_info->node_id,
|
||||
max_attempts);
|
||||
|
||||
node_info->node_status = NODE_STATUS_DOWN;
|
||||
|
||||
free_conninfo_params(&conninfo_params);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user