repmgrd: optionally check upstream availability through connection attempts

This commit is contained in:
Ian Barwick
2019-03-14 14:53:45 +09:00
parent feb90ee50c
commit 9347d34ce0
4 changed files with 25 additions and 3 deletions

View File

@@ -638,6 +638,10 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
{
options->connection_check_type = CHECK_CONNECTION;
}
else if (strcasecmp(value, "query") == 0)
{
options->connection_check_type = CHECK_QUERY;
}
else
{
item_list_append(error_list,

View File

@@ -40,6 +40,7 @@ typedef enum
typedef enum
{
CHECK_PING,
CHECK_QUERY,
CHECK_CONNECTION
} ConnectionCheckType;

View File

@@ -1034,7 +1034,7 @@ monitor_streaming_standby(void)
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);
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 (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);
if (PQstatus(primary_conn) == CONNECTION_OK)

View File

@@ -836,11 +836,28 @@ check_upstream_connection(PGconn **conn, const char *conninfo)
if (config_file_options.connection_check_type == CHECK_PING)
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 (;;)
{
if (PQstatus(*conn) != CONNECTION_OK)
{
log_debug("connection not OK");
log_debug("check_upstream_connection(): connection not OK");
if (twice)
return false;
/* reconnect */