mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
"standby clone": improve replication user selection
Use the upstream node's replication user when checking the replication connection.
This commit is contained in:
@@ -129,7 +129,7 @@ do_standby_clone(void)
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
/* dummy node record */
|
/* dummy node record */
|
||||||
t_node_info node_record = T_NODE_INFO_INITIALIZER;
|
t_node_info local_node_record = T_NODE_INFO_INITIALIZER;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* --recovery-conf-only provided - we'll handle that separately
|
* --recovery-conf-only provided - we'll handle that separately
|
||||||
@@ -186,8 +186,8 @@ do_standby_clone(void)
|
|||||||
check_barman_config();
|
check_barman_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
init_node_record(&node_record);
|
init_node_record(&local_node_record);
|
||||||
node_record.type = STANDBY;
|
local_node_record.type = STANDBY;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise list of conninfo parameters which will later be used to
|
* Initialise list of conninfo parameters which will later be used to
|
||||||
@@ -530,7 +530,7 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
if (mode != barman)
|
if (mode != barman)
|
||||||
{
|
{
|
||||||
initialise_direct_clone(&node_record);
|
initialise_direct_clone(&local_node_record);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
@@ -557,10 +557,10 @@ do_standby_clone(void)
|
|||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case pg_basebackup:
|
case pg_basebackup:
|
||||||
r = run_basebackup(&node_record);
|
r = run_basebackup(&local_node_record);
|
||||||
break;
|
break;
|
||||||
case barman:
|
case barman:
|
||||||
r = run_file_backup(&node_record);
|
r = run_file_backup(&local_node_record);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* should never reach here */
|
/* should never reach here */
|
||||||
@@ -574,7 +574,7 @@ do_standby_clone(void)
|
|||||||
/* If a replication slot was previously created, drop it */
|
/* If a replication slot was previously created, drop it */
|
||||||
if (config_file_options.use_replication_slots == true)
|
if (config_file_options.use_replication_slots == true)
|
||||||
{
|
{
|
||||||
drop_replication_slot(source_conn, node_record.slot_name);
|
drop_replication_slot(source_conn, local_node_record.slot_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_error(_("unable to take a base backup of the primary server"));
|
log_error(_("unable to take a base backup of the primary server"));
|
||||||
@@ -601,7 +601,7 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
/* Write the recovery.conf file */
|
/* Write the recovery.conf file */
|
||||||
|
|
||||||
if (create_recovery_file(&node_record, &recovery_conninfo, local_data_directory, true) == false)
|
if (create_recovery_file(&local_node_record, &recovery_conninfo, local_data_directory, true) == false)
|
||||||
{
|
{
|
||||||
/* create_recovery_file() will log an error */
|
/* create_recovery_file() will log an error */
|
||||||
log_notice(_("unable to create recovery.conf; see preceding error messages"));
|
log_notice(_("unable to create recovery.conf; see preceding error messages"));
|
||||||
@@ -4292,6 +4292,10 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *node_in
|
|||||||
{
|
{
|
||||||
param_set(&repl_conninfo, "user", runtime_options.replication_user);
|
param_set(&repl_conninfo, "user", runtime_options.replication_user);
|
||||||
}
|
}
|
||||||
|
else if (upstream_repluser[0] != '\0')
|
||||||
|
{
|
||||||
|
param_set(&repl_conninfo, "user", upstream_repluser);
|
||||||
|
}
|
||||||
else if (node_info->repluser[0] != '\0')
|
else if (node_info->repluser[0] != '\0')
|
||||||
{
|
{
|
||||||
param_set(&repl_conninfo, "user", node_info->repluser);
|
param_set(&repl_conninfo, "user", node_info->repluser);
|
||||||
@@ -4562,10 +4566,14 @@ run_basebackup(t_node_info *node_record)
|
|||||||
/* string will already have been parsed */
|
/* string will already have been parsed */
|
||||||
(void) parse_conninfo_string(runtime_options.dbname, &conninfo, NULL, false);
|
(void) parse_conninfo_string(runtime_options.dbname, &conninfo, NULL, false);
|
||||||
|
|
||||||
if (*runtime_options.replication_user)
|
if (runtime_options.replication_user[0] != '\0')
|
||||||
{
|
{
|
||||||
param_set(&conninfo, "user", runtime_options.replication_user);
|
param_set(&conninfo, "user", runtime_options.replication_user);
|
||||||
}
|
}
|
||||||
|
else if (upstream_repluser[0] != '\0')
|
||||||
|
{
|
||||||
|
param_set(&conninfo, "user", upstream_repluser);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
param_set(&conninfo, "user", node_record->repluser);
|
param_set(&conninfo, "user", node_record->repluser);
|
||||||
@@ -4598,6 +4606,10 @@ run_basebackup(t_node_info *node_record)
|
|||||||
{
|
{
|
||||||
appendPQExpBuffer(¶ms, " -U %s", runtime_options.replication_user);
|
appendPQExpBuffer(¶ms, " -U %s", runtime_options.replication_user);
|
||||||
}
|
}
|
||||||
|
else if (strlen(upstream_repluser))
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(¶ms, " -U %s", upstream_repluser);
|
||||||
|
}
|
||||||
else if (strlen(node_record->repluser))
|
else if (strlen(node_record->repluser))
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(¶ms, " -U %s", node_record->repluser);
|
appendPQExpBuffer(¶ms, " -U %s", node_record->repluser);
|
||||||
|
|||||||
@@ -2721,7 +2721,7 @@ init_node_record(t_node_info *node_record)
|
|||||||
|
|
||||||
if (config_file_options.replication_user[0] != '\0')
|
if (config_file_options.replication_user[0] != '\0')
|
||||||
{
|
{
|
||||||
/* replication user explicitly provided */
|
/* replication user explicitly provided in configuration file */
|
||||||
strncpy(node_record->repluser, config_file_options.replication_user, NAMEDATALEN);
|
strncpy(node_record->repluser, config_file_options.replication_user, NAMEDATALEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user