From 17987a26908a3ebf327487404f58701524f52b25 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 28 Jul 2021 11:50:57 +0900 Subject: [PATCH] standby switchover: detect if demotion candidate is running as a primary This shouldn't happen, but if it does, log the fact for easier analysis. --- repmgr-action-standby.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 69121541..7d466106 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -5428,6 +5428,27 @@ do_standby_switchover(void) remote_node_record.node_name, remote_node_record.node_id); + /* + * Speculatively check if the demotion candidate has been restarted, e.g. by + * an external watchdog process which isn't aware a switchover is happening. + * This falls into the category "thing outside of our control which shouldn't + * happen, but if it does, make it easier to find out what happened". + */ + remote_conn = establish_db_connection(remote_node_record.conninfo, false); + + if (PQstatus(remote_conn) == CONNECTION_OK) + { + if (get_recovery_type(remote_conn) == RECTYPE_PRIMARY) + { + appendPQExpBuffer(&detailmsg, + _("PostgreSQL instance on demotion candidate \"%s\" (ID: %i) is running as a primary\n"), + remote_node_record.node_name, + remote_node_record.node_id); + log_warning("%s", detailmsg.data); + } + } + PQfinish(remote_conn); + appendPQExpBuffer(&detailmsg, "check log file \"%s\" on \"%s\" for details", node_rejoin_log,