diff --git a/configfile.c b/configfile.c index f5200acf..2601a60b 100644 --- a/configfile.c +++ b/configfile.c @@ -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, diff --git a/configfile.h b/configfile.h index 1001f7d7..ed13e245 100644 --- a/configfile.h +++ b/configfile.h @@ -40,6 +40,7 @@ typedef enum typedef enum { CHECK_PING, + CHECK_QUERY, CHECK_CONNECTION } ConnectionCheckType; diff --git a/repmgrd-physical.c b/repmgrd-physical.c index e3e328fb..ecd3313e 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -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) diff --git a/repmgrd.c b/repmgrd.c index 05e2c7e4..1ce12d77 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -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 */