From 1d99a07b43d9c8e0140b1a2e701519242befc53e Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 10 Aug 2017 08:03:24 +0900 Subject: [PATCH] Store configuration file in repmgr.nodes table When executing repmgr on remote nodes, we otherwise end up jumping through hoops as we can't make assumptions about where the configuration file is located, but really need to be able to provide it. From a support point of view it will also make life easier as it will be easy to specify exactly which file to provide. --- configfile.c | 2 +- configfile.h | 1 + dbutils.c | 16 +++++++++------- dbutils.h | 4 +++- repmgr--4.0.sql | 3 ++- repmgr-client.c | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/configfile.c b/configfile.c index ded9f013..04eeca60 100644 --- a/configfile.c +++ b/configfile.c @@ -11,7 +11,7 @@ #include "log.h" const static char *_progname = NULL; -static char config_file_path[MAXPGPATH]; +char config_file_path[MAXPGPATH] = ""; static bool config_file_provided = false; bool config_file_found = false; diff --git a/configfile.h b/configfile.h index 22555dc8..d24d9bfd 100644 --- a/configfile.h +++ b/configfile.h @@ -13,6 +13,7 @@ #define CONFIG_FILE_NAME "repmgr.conf" #define MAXLINELENGTH 4096 extern bool config_file_found; +extern char config_file_path[MAXPGPATH]; typedef enum { FAILOVER_MANUAL, diff --git a/dbutils.c b/dbutils.c index 937f7b84..f068ff23 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1637,7 +1637,7 @@ get_node_record(PGconn *conn, int node_id, t_node_info *node_info) " WHERE node_id = %i", node_id); - log_verbose(LOG_DEBUG, "get_node_record():\n%s", query.data); + log_verbose(LOG_DEBUG, "get_node_record():\n %s", query.data); result = _get_node_record(conn, query.data, node_info); termPQExpBuffer(&query); @@ -1956,7 +1956,7 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) char *slot_name_ptr = NULL; - int param_count = 10; + int param_count = 11; const char *param_values[param_count]; PGresult *res; @@ -1995,7 +1995,8 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) param_values[6] = node_info->location; param_values[7] = priority; param_values[8] = node_info->active == true ? "TRUE" : "FALSE"; - param_values[9] = node_id; + param_values[9] = node_info->config_file; + param_values[10] = node_id; initPQExpBuffer(&query); @@ -2005,8 +2006,8 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) "INSERT INTO repmgr.nodes " " (node_id, type, upstream_node_id, " " node_name, conninfo, repluser, slot_name, " - " location, priority, active) " - "VALUES ($10, $1, $2, $3, $4, $5, $6, $7, $8, $9) "); + " location, priority, active, config_file) " + "VALUES ($11, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) "); } else { @@ -2020,8 +2021,9 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) " slot_name = $6, " " location = $7, " " priority = $8, " - " active = $9 " - " WHERE node_id = $10 "); + " active = $9, " + " config_file = $10 " + " WHERE node_id = $11 "); } diff --git a/dbutils.h b/dbutils.h index f84ca51c..875d9577 100644 --- a/dbutils.h +++ b/dbutils.h @@ -15,7 +15,7 @@ #include "strutil.h" #include "voting.h" -#define REPMGR_NODES_COLUMNS "node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active, '' AS upstream_node_name " +#define REPMGR_NODES_COLUMNS "node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active, config_file, '' AS upstream_node_name " typedef enum { UNKNOWN = 0, @@ -84,6 +84,7 @@ typedef struct s_node_info int priority; bool active; char slot_name[MAXLEN]; + char config_file[MAXPGPATH]; /* used during failover to track node status */ XLogRecPtr last_wal_receive_lsn; NodeStatus node_status; @@ -115,6 +116,7 @@ typedef struct s_node_info DEFAULT_PRIORITY, \ true, \ "", \ + "", \ /* used during failover to track node status */ \ InvalidXLogRecPtr, \ NODE_STATUS_UNKNOWN, \ diff --git a/repmgr--4.0.sql b/repmgr--4.0.sql index 050f94aa..cbb13e64 100644 --- a/repmgr--4.0.sql +++ b/repmgr--4.0.sql @@ -11,7 +11,8 @@ CREATE TABLE nodes ( priority INT NOT NULL DEFAULT 100, conninfo TEXT NOT NULL, repluser VARCHAR(63) NOT NULL, - slot_name TEXT NULL + slot_name TEXT NULL, + config_file TEXT NOT NULL ); CREATE TABLE events ( diff --git a/repmgr-client.c b/repmgr-client.c index d18e9228..2b0d8416 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -2971,6 +2971,7 @@ init_node_record(t_node_info *node_record) strncpy(node_record->node_name, config_file_options.node_name, MAXLEN); strncpy(node_record->conninfo, config_file_options.conninfo, MAXLEN); + strncpy(node_record->config_file, config_file_path, MAXLEN); if (config_file_options.replication_user[0] != '\0') {