mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
repmgrd: optionally check upstream availability through connection attempts
This commit is contained in:
@@ -638,6 +638,10 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
|||||||
{
|
{
|
||||||
options->connection_check_type = CHECK_CONNECTION;
|
options->connection_check_type = CHECK_CONNECTION;
|
||||||
}
|
}
|
||||||
|
else if (strcasecmp(value, "query") == 0)
|
||||||
|
{
|
||||||
|
options->connection_check_type = CHECK_QUERY;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item_list_append(error_list,
|
item_list_append(error_list,
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ typedef enum
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
CHECK_PING,
|
CHECK_PING,
|
||||||
|
CHECK_QUERY,
|
||||||
CHECK_CONNECTION
|
CHECK_CONNECTION
|
||||||
} ConnectionCheckType;
|
} ConnectionCheckType;
|
||||||
|
|
||||||
|
|||||||
@@ -1034,7 +1034,7 @@ monitor_streaming_standby(void)
|
|||||||
|
|
||||||
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == true)
|
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == true)
|
||||||
{
|
{
|
||||||
if (config_file_options.connection_check_type == CHECK_PING)
|
if (config_file_options.connection_check_type != CHECK_QUERY)
|
||||||
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||||
|
|
||||||
if (PQstatus(upstream_conn) == CONNECTION_OK)
|
if (PQstatus(upstream_conn) == CONNECTION_OK)
|
||||||
@@ -1707,7 +1707,7 @@ monitor_streaming_witness(void)
|
|||||||
|
|
||||||
if (check_upstream_connection(&primary_conn, upstream_node_info.conninfo) == true)
|
if (check_upstream_connection(&primary_conn, upstream_node_info.conninfo) == true)
|
||||||
{
|
{
|
||||||
if (config_file_options.connection_check_type == CHECK_PING)
|
if (config_file_options.connection_check_type != CHECK_QUERY)
|
||||||
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||||
|
|
||||||
if (PQstatus(primary_conn) == CONNECTION_OK)
|
if (PQstatus(primary_conn) == CONNECTION_OK)
|
||||||
|
|||||||
19
repmgrd.c
19
repmgrd.c
@@ -836,11 +836,28 @@ check_upstream_connection(PGconn **conn, const char *conninfo)
|
|||||||
if (config_file_options.connection_check_type == CHECK_PING)
|
if (config_file_options.connection_check_type == CHECK_PING)
|
||||||
return is_server_available(conninfo);
|
return is_server_available(conninfo);
|
||||||
|
|
||||||
|
if (config_file_options.connection_check_type == CHECK_CONNECTION)
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
PGconn *test_conn = PQconnectdb(conninfo);
|
||||||
|
|
||||||
|
log_debug("check_upstream_connection(): attempting to connect to \"%s\"", conninfo);
|
||||||
|
|
||||||
|
if (PQstatus(test_conn) != CONNECTION_OK)
|
||||||
|
{
|
||||||
|
log_warning(_("unable to connect to \"%s\""), conninfo);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
PQfinish(test_conn);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (PQstatus(*conn) != CONNECTION_OK)
|
if (PQstatus(*conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_debug("connection not OK");
|
log_debug("check_upstream_connection(): connection not OK");
|
||||||
if (twice)
|
if (twice)
|
||||||
return false;
|
return false;
|
||||||
/* reconnect */
|
/* reconnect */
|
||||||
|
|||||||
Reference in New Issue
Block a user