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:
Ian Barwick
2018-03-21 10:33:05 +09:00
parent 85a4adc99c
commit 0219f4c91f
4 changed files with 44 additions and 3 deletions

View File

@@ -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 */
/* ==================== */