From 62ac56c3f5363b690a798398dc0e7214de0c48a3 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 18 Oct 2018 16:50:13 +0900 Subject: [PATCH] repmgrd: handle case where upstream is no longer primary If the upstream comes back on line (e.g. after a switchover), and its status is no longer primary, restart monitoring to ensure the correct primary (potentially the current node) is being monitored. --- repmgrd-physical.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/repmgrd-physical.c b/repmgrd-physical.c index d5c0d8e3..58d84058 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -778,6 +778,16 @@ monitor_streaming_standby(void) if (upstream_node_info.type == PRIMARY) { primary_conn = upstream_conn; + + if (get_recovery_type(primary_conn) != RECTYPE_PRIMARY) + { + log_notice(_("current upstream node \"%s\" (node ID: %i) is not primary, restarting monitoring"), + upstream_node_info.node_name, upstream_node_info.node_id); + PQfinish(upstream_conn); + upstream_conn = NULL; + termPQExpBuffer(&event_details); + return; + } } initPQExpBuffer(&event_details);