From cb7bbda02112deaa619a9657af8e250d2c6e2ae9 Mon Sep 17 00:00:00 2001 From: laixiong Date: Mon, 16 Dec 2019 22:03:04 +0800 Subject: [PATCH] standby switchover: check remote's registered repmgr.conf Check the demotion candidate's registered repmgr.conf file can be found. If the configuration file has been deleted or moved, previously the resulting error message would have been a confusing reference to an incorrectly configured data directory; by explicitly checking for the expected configuration file, we can make troubleshooting easier. Original patch by laixiong (GitHub #615), modified by Ian Barwick. --- repmgr-action-standby.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index dc358644..8cd7c84b 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -3760,6 +3760,44 @@ do_standby_switchover(void) } termPQExpBuffer(&command_output); + + /* + * Check if the expected remote repmgr.conf file exists + */ + initPQExpBuffer(&remote_command_str); + + appendPQExpBuffer(&remote_command_str, + "test -f %s && echo 1 || echo 0", + remote_node_record.config_file); + initPQExpBuffer(&command_output); + + command_success = remote_command(remote_host, + runtime_options.remote_user, + remote_command_str.data, + config_file_options.ssh_options, + &command_output); + + termPQExpBuffer(&remote_command_str); + + if (command_success == false || command_output.data[0] == '0') + { + log_error(_("expected configuration file not found on the demotion candiate \"%s\" (ID: %i)"), + remote_node_record.node_name, + remote_node_record.node_id); + log_detail(_("registered configuration file is \"%s\""), + remote_node_record.config_file); + log_hint(_("ensure the configuration file is in the expected location, or re-register \"%s\" to update the configuration file location"), + remote_node_record.node_name); + + PQfinish(remote_conn); + PQfinish(local_conn); + + termPQExpBuffer(&command_output); + + exit(ERR_BAD_CONFIG); + } + + /* * Sanity-check remote "data_directory" is correctly configured in repmgr.conf. *