diff --git a/repmgr.c b/repmgr.c index f0866e88..e77652d8 100644 --- a/repmgr.c +++ b/repmgr.c @@ -582,6 +582,7 @@ main(int argc, char **argv) { maxlen_snprintf(repmgr_slot_name, "repmgr_slot_%i", options.node); repmgr_slot_name_ptr = repmgr_slot_name; + log_verbose(LOG_DEBUG, "slot name initialised as: %s\n", repmgr_slot_name); } @@ -2031,6 +2032,39 @@ do_standby_follow(void) strncpy(runtime_options.masterport, PQport(master_conn), MAXLEN); strncpy(runtime_options.username, PQuser(master_conn), MAXLEN); + /* + * If 9.4 or later, and replication slots in use, we'll need to create a + * slot on the new master + */ + + if (options.use_replication_slots) + { + if (create_replication_slot(master_conn, repmgr_slot_name) == false) + { + PQExpBufferData event_details; + initPQExpBuffer(&event_details); + + appendPQExpBuffer(&event_details, + _("Unable to create slot '%s' on the master node: %s"), + repmgr_slot_name, + PQerrorMessage(master_conn)); + + log_err("%s\n", event_details.data); + + create_event_record(master_conn, + &options, + options.node, + "repmgr_follow", + false, + event_details.data); + + PQfinish(conn); + PQfinish(master_conn); + exit(ERR_DB_QUERY); + } + } + + log_info(_("changing standby's master\n")); /* Get the data directory full path */ diff --git a/repmgrd.c b/repmgrd.c index 7944f1cd..688a4595 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1521,35 +1521,6 @@ do_master_failover(void) fflush(stderr); } - /* - * If 9.4 or later, and replication slots in use, we'll need to create a - * slot on the new master - */ - new_master_conn = establish_db_connection(best_candidate.conninfo_str, true); - - if (local_options.use_replication_slots) - { - if (create_replication_slot(new_master_conn, node_info.slot_name) == false) - { - - appendPQExpBuffer(&event_details, - _("Unable to create slot '%s' on the master node: %s"), - node_info.slot_name, - PQerrorMessage(new_master_conn)); - - log_err("%s\n", event_details.data); - - create_event_record(new_master_conn, - &local_options, - node_info.node_id, - "repmgrd_failover_follow", - false, - event_details.data); - - PQfinish(new_master_conn); - terminate(ERR_DB_QUERY); - } - } log_debug(_("executing follow command: \"%s\"\n"), local_options.follow_command);