diff --git a/config.c b/config.c index 08fd4d42..b88b8bc9 100644 --- a/config.c +++ b/config.c @@ -225,6 +225,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->use_replication_slots = false; memset(options->rsync_options, 0, sizeof(options->rsync_options)); memset(options->ssh_options, 0, sizeof(options->ssh_options)); + memset(options->replication_user, 0, sizeof(options->replication_user)); memset(options->pg_basebackup_options, 0, sizeof(options->pg_basebackup_options)); memset(options->restore_command, 0, sizeof(options->restore_command)); options->tablespace_mapping.head = NULL; @@ -332,6 +333,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->upstream_node_id = repmgr_atoi(value, name, error_list, 1); else if (strcmp(name, "conninfo") == 0) strncpy(options->conninfo, value, MAXLEN); + else if (strcmp(name, "replication_user") == 0) + strncpy(options->replication_user, value, MAXLEN); else if (strcmp(name, "pg_bindir") == 0) strncpy(options->pg_bindir, value, MAXLEN); else if (strcmp(name, "replication_type") == 0) diff --git a/config.h b/config.h index ebf490a8..cc926532 100644 --- a/config.h +++ b/config.h @@ -48,8 +48,9 @@ typedef struct /* node information */ int node_id; int upstream_node_id; - char node_name[MAXLEN]; + char node_name[MAXLEN]; char conninfo[MAXLEN]; + char replication_user[MAXLEN]; char pg_bindir[MAXLEN]; int replication_type; @@ -109,7 +110,7 @@ typedef struct #define T_CONFIGURATION_OPTIONS_INITIALIZER { \ /* node information */ \ - UNKNOWN_NODE_ID, NO_UPSTREAM_NODE, "", "", "", REPLICATION_TYPE_PHYSICAL, \ + UNKNOWN_NODE_ID, NO_UPSTREAM_NODE, "", "", "", "", REPLICATION_TYPE_PHYSICAL, \ /* log settings */ \ "", "", "", \ /* standby clone settings */ \ diff --git a/dbutils.c b/dbutils.c index 84beac37..f0188fc9 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1154,9 +1154,10 @@ _populate_node_record(PGresult *res, t_node_info *node_info, int row) strncpy(node_info->node_name, PQgetvalue(res, row, 3), MAXLEN); strncpy(node_info->conninfo, PQgetvalue(res, row, 4), MAXLEN); - strncpy(node_info->slot_name, PQgetvalue(res, row, 5), MAXLEN); - node_info->priority = atoi(PQgetvalue(res, row, 6)); - node_info->active = atobool(PQgetvalue(res, row, 7)); + strncpy(node_info->repluser, PQgetvalue(res, row, 5), MAXLEN); + strncpy(node_info->slot_name, PQgetvalue(res, row, 6), MAXLEN); + node_info->priority = atoi(PQgetvalue(res, row, 7)); + node_info->active = atobool(PQgetvalue(res, row, 8)); /* Set remaining struct fields with default values */ node_info->is_ready = false; @@ -1218,7 +1219,7 @@ get_node_record(PGconn *conn, int node_id, t_node_info *node_info) initPQExpBuffer(&query); appendPQExpBuffer(&query, - "SELECT node_id, type, upstream_node_id, node_name, conninfo, slot_name, priority, active" + "SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active" " FROM repmgr.nodes " " WHERE node_id = %i", node_id); @@ -1246,7 +1247,7 @@ get_node_record_by_name(PGconn *conn, const char *node_name, t_node_info *node_i initPQExpBuffer(&query); appendPQExpBuffer(&query, - "SELECT node_id, type, upstream_node_id, node_name, conninfo, slot_name, priority, active" + "SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active" " FROM repmgr.nodes " " WHERE node_name = '%s' ", node_name); @@ -1317,7 +1318,7 @@ get_downstream_node_records(PGconn *conn, int node_id, NodeInfoList *node_list) initPQExpBuffer(&query); appendPQExpBuffer(&query, - " SELECT node_id, type, upstream_node_id, node_name, conninfo, slot_name, priority, active" + " SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active" " FROM repmgr.nodes " " WHERE upstream_node_id = %i " "ORDER BY node_id ", @@ -1391,7 +1392,7 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) char slot_name[MAXLEN]; char *slot_name_ptr = NULL; - int param_count = 8; + int param_count = 9; const char *param_values[param_count]; PGresult *res; @@ -1423,10 +1424,11 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) param_values[1] = upstream_node_id_ptr; param_values[2] = node_info->node_name; param_values[3] = node_info->conninfo; - param_values[4] = slot_name_ptr; - param_values[5] = priority; - param_values[6] = node_info->active == true ? "TRUE" : "FALSE"; - param_values[7] = node_id; + param_values[4] = node_info->repluser; + param_values[5] = slot_name_ptr; + param_values[6] = priority; + param_values[7] = node_info->active == true ? "TRUE" : "FALSE"; + param_values[8] = node_id; initPQExpBuffer(&query); @@ -1435,9 +1437,9 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) appendPQExpBuffer(&query, "INSERT INTO repmgr.nodes " " (node_id, type, upstream_node_id, " - " node_name, conninfo, slot_name, " + " node_name, conninfo, repluser, slot_name, " " priority, active) " - "VALUES ($8, $1, $2, $3, $4, $5, $6, $7) "); + "VALUES ($9, $1, $2, $3, $4, $5, $6, $7, $8) "); } else { @@ -1447,10 +1449,11 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) " upstream_node_id = $2, " " node_name = $3, " " conninfo = $4, " - " slot_name = $5, " - " priority = $6, " - " active = $7 " - " WHERE node_id = $8 "); + " repluser = $5, " + " slot_name = $7, " + " priority = $7, " + " active = $8 " + " WHERE node_id = $9 "); } diff --git a/dbutils.h b/dbutils.h index 12700d79..123c6c66 100644 --- a/dbutils.h +++ b/dbutils.h @@ -49,6 +49,7 @@ typedef struct s_node_info t_server_type type; char node_name[MAXLEN]; char conninfo[MAXLEN]; + char repluser[MAXLEN]; char slot_name[MAXLEN]; int priority; bool active; @@ -65,6 +66,7 @@ typedef struct s_node_info "", \ "", \ "", \ + "", \ DEFAULT_PRIORITY, \ true, \ false, \ diff --git a/repmgr--4.0.sql b/repmgr--4.0.sql index 1dc60b8a..91a800b2 100644 --- a/repmgr--4.0.sql +++ b/repmgr--4.0.sql @@ -10,6 +10,7 @@ CREATE TABLE nodes ( priority INT NOT NULL DEFAULT 100, conninfo TEXT NOT NULL, + repluser TEXT NOT NULL, slot_name TEXT NULL ); diff --git a/repmgr-action-master.c b/repmgr-action-master.c index ac9541a4..a69f5c49 100644 --- a/repmgr-action-master.c +++ b/repmgr-action-master.c @@ -156,6 +156,15 @@ do_master_register(void) strncpy(node_info.node_name, config_file_options.node_name, MAXLEN); strncpy(node_info.conninfo, config_file_options.conninfo, MAXLEN); + if (config_file_options.replication_user[0] != '\0') + { + strncpy(node_info.repluser, config_file_options.replication_user, MAXLEN); + } + else + { + (void)get_conninfo_value(config_file_options.conninfo, "user", node_info.repluser); + } + if (repmgr_slot_name_ptr != NULL) strncpy(node_info.slot_name, repmgr_slot_name_ptr, MAXLEN); diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 3d06ecb4..dd9d05fd 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -48,6 +48,7 @@ static char upstream_data_directory[MAXPGPATH]; static t_conninfo_param_list recovery_conninfo; static char recovery_conninfo_str[MAXLEN]; +static char upstream_repluser[MAXLEN]; static t_configfile_list config_files = T_CONFIGFILE_LIST_INITIALIZER; @@ -257,6 +258,9 @@ do_standby_clone(void) PQfinish(source_conn); exit(ERR_BAD_CONFIG); } + + /* Write the replication user from the node's upstream record */ + param_set(&recovery_conninfo, "user", upstream_repluser); } else { @@ -277,12 +281,6 @@ do_standby_clone(void) } } - /* If --replication-user was set, use that value for the primary_conninfo user */ - if (*runtime_options.replication_user) - { - param_set(&recovery_conninfo, "user", runtime_options.replication_user); - } - if (mode != barman) { initialise_direct_clone(); @@ -801,6 +799,17 @@ do_standby_register(void) strncpy(node_record.node_name, config_file_options.node_name, MAXLEN); strncpy(node_record.conninfo, config_file_options.conninfo, MAXLEN); + if (config_file_options.replication_user[0] != '\0') + { + /* Replication user explicitly provided */ + strncpy(node_record.repluser, config_file_options.replication_user, MAXLEN); + } + else + { + (void)get_conninfo_value(config_file_options.conninfo, "user", node_record.repluser); + } + + if (repmgr_slot_name_ptr != NULL) strncpy(node_record.slot_name, repmgr_slot_name_ptr, MAXLEN); @@ -1433,6 +1442,7 @@ check_source_server() { upstream_record_found = true; strncpy(recovery_conninfo_str, node_record.conninfo, MAXLEN); + strncpy(upstream_repluser, node_record.repluser, MAXLEN); } /* diff --git a/repmgr-client.c b/repmgr-client.c index e5d4a4eb..109a6636 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -427,6 +427,10 @@ main(int argc, char **argv) runtime_options.verbose = true; break; + /* options deprecated since 3.3 * + * ---------------------------- */ + + } }