diff --git a/repmgr-action-primary.c b/repmgr-action-primary.c index 16f22f85..818d8f4c 100644 --- a/repmgr-action-primary.c +++ b/repmgr-action-primary.c @@ -275,7 +275,7 @@ do_primary_unregister(void) log_error(_("unable to connect to primary server")); - if (get_primary_node_record(local_conn, &primary_node_info)) + if (get_primary_node_record(local_conn, &primary_node_info) == true) { log_detail(_("current primary registered as node %s (id: %i, conninfo: \"%s\")"), primary_node_info.node_name, diff --git a/repmgrd-physical.c b/repmgrd-physical.c index fc2499c3..c270624c 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -904,9 +904,7 @@ do_upstream_standby_failover(void) PQfinish(upstream_conn); upstream_conn = NULL; - record_status = get_primary_node_record(local_conn, &primary_node_info); - - if (record_status != RECORD_FOUND) + if (get_primary_node_record(local_conn, &primary_node_info) == false) { log_error(_("unable to retrieve primary node record")); return false; @@ -1007,9 +1005,18 @@ do_upstream_standby_failover(void) terminate(ERR_BAD_CONFIG); } - /* update own internal node record */ - record_status = get_node_record(primary_conn, local_node_info.node_id, &local_node_info); + /* refresh own internal node record */ + record_status = get_node_record(primary_conn, local_node_info.node_id, &local_node_info); + + /* + * highly improbable this will happen, but in case we're unable to retrieve + * our node record from the primary, update it ourselves, and hope for the best + */ + if (record_status != RECORD_FOUND) + { + local_node_info.upstream_node_id = primary_node_info.node_id; + } appendPQExpBuffer(&event_details, _("node %i is now following primary node %i"), @@ -1027,11 +1034,9 @@ do_upstream_standby_failover(void) termPQExpBuffer(&event_details); - PQfinish(primary_conn); primary_conn = NULL; - return true; }