diff --git a/dbutils.c b/dbutils.c index f068ff23..6f3b5010 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1571,6 +1571,7 @@ _populate_node_record(PGresult *res, t_node_info *node_info, int row) strncpy(node_info->location, PQgetvalue(res, row, 7), MAXLEN); node_info->priority = atoi(PQgetvalue(res, row, 8)); node_info->active = atobool(PQgetvalue(res, row, 9)); + strncpy(node_info->config_file, PQgetvalue(res, row, 10), MAXLEN); /* This won't normally be set */ strncpy(node_info->upstream_node_name, PQgetvalue(res, row, 10), MAXLEN); diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 6a358ec3..b773f62c 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1648,7 +1648,7 @@ do_standby_switchover(void) * Check this standby is attached to the demotion candidate * TODO: * - check standby is attached to demotion candidate - * (compare primary_conninfo from recovery.conf) + * - check application_name in pg_stat_replication */ if (local_node_record.upstream_node_id != remote_node_record.node_id) @@ -1725,7 +1725,7 @@ do_standby_switchover(void) bool command_success; initPQExpBuffer(&remote_command_str); - make_remote_repmgr_path(&remote_command_str); + make_remote_repmgr_path(&remote_command_str, &remote_node_record); appendPQExpBuffer(&remote_command_str, "node check --terse -LERROR --archiver --optformat"); @@ -1848,112 +1848,6 @@ do_standby_switchover(void) PQfinish(remote_conn); - /* Determine the remote's configuration file location */ - /* -------------------------------------------------- */ - - /* Remote configuration file provided - check it exists */ - /* TODO have remote node verify config file "node status --config-file */ - if (runtime_options.remote_config_file[0]) - - { - log_verbose(LOG_INFO, _("looking for file \"%s\" on remote server \"%s\""), - runtime_options.remote_config_file, - remote_host); - - initPQExpBuffer(&remote_command_str); - appendPQExpBuffer(&remote_command_str, "ls "); - - appendShellString(&remote_command_str, runtime_options.remote_config_file); - appendPQExpBuffer(&remote_command_str, " >/dev/null 2>&1 && echo 1 || echo 0"); - - initPQExpBuffer(&command_output); - - (void)remote_command( - remote_host, - runtime_options.remote_user, - remote_command_str.data, - &command_output); - - termPQExpBuffer(&remote_command_str); - - if (*command_output.data == '0') - { - log_error(_("unable to find the specified repmgr configuration file on remote server")); - log_detail(_("remote configuration file is \"%s\""), - runtime_options.remote_config_file); - PQfinish(local_conn); - exit(ERR_BAD_CONFIG); - } - - log_verbose(LOG_INFO, _("remote configuration file \"%s\" found on remote server"), - runtime_options.remote_config_file); - - termPQExpBuffer(&command_output); - } - /* - * No remote configuration file provided - check some default locations: - * - path of configuration file for this repmgr - * - /etc/repmgr.conf - */ - else - { - int i; - bool remote_config_file_found = false; - - const char *config_paths[] = { - runtime_options.config_file, - "/etc/repmgr.conf", - NULL - }; - - log_verbose(LOG_INFO, _("no remote configuration file provided - checking default locations")); - - for (i = 0; config_paths[i] && remote_config_file_found == false; ++i) - { - /* - * Don't attempt to check for an empty filename - this might be the case - * if no local configuration file was found. - */ - if (!strlen(config_paths[i])) - continue; - - log_verbose(LOG_INFO, _("checking \"%s\"\n"), config_paths[i]); - - initPQExpBuffer(&remote_command_str); - appendPQExpBuffer(&remote_command_str, "ls "); - - appendShellString(&remote_command_str, config_paths[i]); - appendPQExpBuffer(&remote_command_str, " >/dev/null 2>&1 && echo 1 || echo 0"); - - initPQExpBuffer(&command_output); - - (void)remote_command( - remote_host, - runtime_options.remote_user, - remote_command_str.data, - &command_output); - - termPQExpBuffer(&remote_command_str); - - if (*command_output.data == '1') - { - strncpy(runtime_options.remote_config_file, config_paths[i], MAXLEN); - log_verbose(LOG_INFO, _("configuration file \"%s\" found on remote server"), - runtime_options.remote_config_file); - remote_config_file_found = true; - } - - termPQExpBuffer(&command_output); - } - - if (remote_config_file_found == false) - { - log_error(_("no remote configuration file supplied or found in a default location - terminating")); - log_hint(_("specify the remote configuration file with -C/--remote-config-file")); - PQfinish(local_conn); - exit(ERR_BAD_CONFIG); - } - } /* * If --siblings-follow specified, get list and check they're reachable @@ -2049,7 +1943,7 @@ do_standby_switchover(void) initPQExpBuffer(&remote_command_str); initPQExpBuffer(&command_output); - make_remote_repmgr_path(&remote_command_str); + make_remote_repmgr_path(&remote_command_str, &remote_node_record); if (runtime_options.dry_run == true) @@ -2117,7 +2011,7 @@ do_standby_switchover(void) */ initPQExpBuffer(&remote_command_str); - make_remote_repmgr_path(&remote_command_str); + make_remote_repmgr_path(&remote_command_str, &remote_node_record); appendPQExpBuffer(&remote_command_str, "node status --is-shutdown"); @@ -2232,7 +2126,7 @@ do_standby_switchover(void) } initPQExpBuffer(&remote_command_str); - make_remote_repmgr_path(&remote_command_str); + make_remote_repmgr_path(&remote_command_str, &remote_node_record); appendPQExpBuffer(&remote_command_str, "%s-d \\'%s\\' node rejoin", @@ -2260,7 +2154,6 @@ do_standby_switchover(void) true, NULL); - PQfinish(local_conn); /* clean up remote node */ @@ -2305,21 +2198,25 @@ do_standby_switchover(void) for (cell = sibling_nodes.head; cell; cell = cell->next) { int r = 0; - log_debug("XXX %s", cell->node_info->node_name); + t_node_info sibling_node_record = T_NODE_INFO_INITIALIZER; + /* skip nodes previously determined as unreachable */ if (cell->node_info->reachable == false) - { - log_debug(" XXX unreachable!"); continue; - } + + + record_status = get_node_record(local_conn, + cell->node_info->node_id, + &sibling_node_record); initPQExpBuffer(&remote_command_str); - make_remote_repmgr_path(&remote_command_str); + make_remote_repmgr_path(&remote_command_str, &sibling_node_record); appendPQExpBuffer(&remote_command_str, "standby follow"); get_conninfo_value(cell->node_info->conninfo, "host", host); log_debug("executing:\n \"%s\"", remote_command_str.data); + r = remote_command( host, runtime_options.remote_user, @@ -2339,6 +2236,9 @@ do_standby_switchover(void) log_info(_("STANDBY FOLLOW")); } } + + PQfinish(local_conn); + return; } diff --git a/repmgr-client-global.h b/repmgr-client-global.h index 71a9977e..48cfef85 100644 --- a/repmgr-client-global.h +++ b/repmgr-client-global.h @@ -83,7 +83,6 @@ typedef struct int wait_register_sync_seconds; /* "standby switchover" options */ - char remote_config_file[MAXPGPATH]; bool always_promote; bool force_rewind; bool siblings_follow; @@ -135,7 +134,7 @@ typedef struct /* "standby register" options */ \ false, 0, \ /* "standby switchover" options */ \ - "", false, false, false, \ + false, false, false, \ /* "node status" options */ \ false, \ /* "node check" options */ \ @@ -208,7 +207,7 @@ extern void get_superuser_connection(PGconn **conn, PGconn **superuser_conn, PGc extern bool remote_command(const char *host, const char *user, const char *command, PQExpBufferData *outputbuf); -extern void make_remote_repmgr_path(PQExpBufferData *outputbuf); +extern void make_remote_repmgr_path(PQExpBufferData *outputbuf, t_node_info *remote_node_record); /* server control functions */ extern void get_server_action(t_server_action action, char *script, char *data_dir); diff --git a/repmgr-client.c b/repmgr-client.c index 2b0d8416..affdb9dd 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -401,11 +401,6 @@ main(int argc, char **argv) /* "standby switchover" options * * ---------------------------- */ - /* -C/--remote-config-file */ - case 'C': - strncpy(runtime_options.remote_config_file, optarg, MAXPGPATH); - break; - case OPT_ALWAYS_PROMOTE: runtime_options.always_promote = true; break; @@ -548,6 +543,13 @@ main(int argc, char **argv) item_list_append(&cli_warnings, _("--no-conninfo-password is deprecated; pasuse --use-recovery-conninfo-password to explicitly set a password")); break; + /* -C/--remote-config-file */ + case 'C': + item_list_append(&cli_warnings, + _("--remote-config-file is no longer required")); + break; + + } } @@ -2684,16 +2686,13 @@ remote_command(const char *host, const char *user, const char *command, PQExpBuf void -make_remote_repmgr_path(PQExpBufferData *output_buf) +make_remote_repmgr_path(PQExpBufferData *output_buf, t_node_info *remote_node_record) { appendPQExpBuffer(output_buf, - "%s ", make_pg_path("repmgr")); + "%s -f %s ", + make_pg_path("repmgr"), + remote_node_record->config_file); - if (runtime_options.remote_config_file[0] != '\0') - { - appendPQExpBuffer(output_buf, - "-f %s ", runtime_options.remote_config_file); - } }