mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
standby follow: improve handling of --upstream-node-id
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
<para>
|
<para>
|
||||||
This command will force a restart of the standby server, which must be
|
This command will force a restart of the standby server, which must be
|
||||||
running. It can only be used to attach an active standby to the current primary node
|
running. It can only be used to attach an active standby to the current primary node
|
||||||
(and not to another standby).
|
(and not to another standby).
|
||||||
</para>
|
</para>
|
||||||
<tip>
|
<tip>
|
||||||
<para>
|
<para>
|
||||||
@@ -78,6 +78,20 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--upstream-node-id</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Node ID of the new primary.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
This option is intended for use by <application>repmgrd</application>, when
|
||||||
|
instructing standbys to follow the new primary. For more details
|
||||||
|
see <link linkend="repmgrd-automatic-failover-configuration">Automatic failover configuration</link>.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-w</option></term>
|
<term><option>-w</option></term>
|
||||||
<term><option>--wait</option></term>
|
<term><option>--wait</option></term>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<sect2 id="repmgrd-automatic-failover-configuration">
|
<sect2 id="repmgrd-automatic-failover-configuration">
|
||||||
<title>automatic failover configuration</title>
|
<title>Automatic failover configuration</title>
|
||||||
<para>
|
<para>
|
||||||
If using automatic failover, the following <application>repmgrd</application> options *must* be set in
|
If using automatic failover, the following <application>repmgrd</application> options *must* be set in
|
||||||
<filename>repmgr.conf</filename> :
|
<filename>repmgr.conf</filename> :
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<!ENTITY repmgrversion "4.2dev">
|
<!ENTITY repmgrversion "4.3dev">
|
||||||
|
|||||||
@@ -2226,6 +2226,32 @@ do_standby_follow(void)
|
|||||||
if (server_version_num < 90400)
|
if (server_version_num < 90400)
|
||||||
check_93_config();
|
check_93_config();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --upstream-node-id provided; assume that is the desired primary
|
||||||
|
* and retrieve its record. We'll check if it's actualy a primary later.
|
||||||
|
*/
|
||||||
|
if (runtime_options.upstream_node_id != UNKNOWN_NODE_ID)
|
||||||
|
{
|
||||||
|
if (runtime_options.upstream_node_id == config_file_options.node_id)
|
||||||
|
{
|
||||||
|
log_error(_("provided --upstream-node-id %i is the current node"),
|
||||||
|
runtime_options.upstream_node_id);
|
||||||
|
PQfinish(local_conn);
|
||||||
|
exit(ERR_FOLLOW_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
primary_node_id = runtime_options.upstream_node_id;
|
||||||
|
record_status = get_node_record(local_conn, primary_node_id, &primary_node_record);
|
||||||
|
|
||||||
|
if (record_status != RECORD_FOUND)
|
||||||
|
{
|
||||||
|
log_error(_("unable to find record for upstream node %i"),
|
||||||
|
runtime_options.upstream_node_id);
|
||||||
|
PQfinish(local_conn);
|
||||||
|
exit(ERR_FOLLOW_FAIL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to connect to primary.
|
* Attempt to connect to primary.
|
||||||
*
|
*
|
||||||
@@ -2233,11 +2259,21 @@ do_standby_follow(void)
|
|||||||
* before giving up
|
* before giving up
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
for (timer = 0; timer < config_file_options.primary_follow_timeout; timer++)
|
for (timer = 0; timer < config_file_options.primary_follow_timeout; timer++)
|
||||||
{
|
{
|
||||||
primary_conn = get_primary_connection_quiet(local_conn,
|
/* --upstream-node-id provided */
|
||||||
&primary_node_id,
|
if (primary_node_id != UNKNOWN_NODE_ID)
|
||||||
NULL);
|
{
|
||||||
|
primary_conn = establish_db_connection_quiet(primary_node_record.conninfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
primary_conn = get_primary_connection_quiet(local_conn,
|
||||||
|
&primary_node_id,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (PQstatus(primary_conn) == CONNECTION_OK || runtime_options.wait == false)
|
if (PQstatus(primary_conn) == CONNECTION_OK || runtime_options.wait == false)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -2249,7 +2285,14 @@ do_standby_follow(void)
|
|||||||
|
|
||||||
if (PQstatus(primary_conn) != CONNECTION_OK)
|
if (PQstatus(primary_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_error(_("unable to determine primary node"));
|
if (primary_node_id == UNKNOWN_NODE_ID)
|
||||||
|
{
|
||||||
|
log_error(_("unable to find a primary node"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_error(_("unable to connect to primary node %i"), primary_node_id);
|
||||||
|
}
|
||||||
|
|
||||||
if (runtime_options.wait == true)
|
if (runtime_options.wait == true)
|
||||||
{
|
{
|
||||||
@@ -2261,23 +2304,27 @@ do_standby_follow(void)
|
|||||||
exit(ERR_FOLLOW_FAIL);
|
exit(ERR_FOLLOW_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtime_options.dry_run == true)
|
/* --upstream-node-id not provided - retrieve record for node determined as primary */
|
||||||
|
if (runtime_options.upstream_node_id == UNKNOWN_NODE_ID)
|
||||||
{
|
{
|
||||||
log_info(_("connected to node %i, checking for current primary"), primary_node_id);
|
if (runtime_options.dry_run == true)
|
||||||
}
|
{
|
||||||
else
|
log_info(_("connected to node %i, checking for current primary"), primary_node_id);
|
||||||
{
|
}
|
||||||
log_verbose(LOG_INFO, _("connected to node %i, checking for current primary"), primary_node_id);
|
else
|
||||||
}
|
{
|
||||||
|
log_verbose(LOG_INFO, _("connected to node %i, checking for current primary"), primary_node_id);
|
||||||
|
}
|
||||||
|
|
||||||
record_status = get_node_record(primary_conn, primary_node_id, &primary_node_record);
|
record_status = get_node_record(primary_conn, primary_node_id, &primary_node_record);
|
||||||
|
|
||||||
if (record_status != RECORD_FOUND)
|
if (record_status != RECORD_FOUND)
|
||||||
{
|
{
|
||||||
log_error(_("unable to find record for new upstream node %i"),
|
log_error(_("unable to find record for new primarynode %i"),
|
||||||
runtime_options.upstream_node_id);
|
primary_node_id);
|
||||||
PQfinish(primary_conn);
|
PQfinish(primary_conn);
|
||||||
exit(ERR_FOLLOW_FAIL);
|
exit(ERR_FOLLOW_FAIL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2287,7 +2334,6 @@ do_standby_follow(void)
|
|||||||
event_info.node_name = primary_node_record.node_name;
|
event_info.node_name = primary_node_record.node_name;
|
||||||
event_info.conninfo_str = primary_node_record.conninfo;
|
event_info.conninfo_str = primary_node_record.conninfo;
|
||||||
|
|
||||||
|
|
||||||
if (runtime_options.dry_run == true)
|
if (runtime_options.dry_run == true)
|
||||||
{
|
{
|
||||||
log_info(_("primary node is \"%s\" (ID: %i)"),
|
log_info(_("primary node is \"%s\" (ID: %i)"),
|
||||||
@@ -6867,6 +6913,7 @@ do_standby_help(void)
|
|||||||
printf(_(" \"standby follow\" instructs a standby node to follow a new primary.\n"));
|
printf(_(" \"standby follow\" instructs a standby node to follow a new primary.\n"));
|
||||||
puts("");
|
puts("");
|
||||||
printf(_(" --dry-run perform checks but don't actually follow the new primary\n"));
|
printf(_(" --dry-run perform checks but don't actually follow the new primary\n"));
|
||||||
|
printf(_(" --upstream-node-id node ID of the new primary\n"));
|
||||||
printf(_(" -W, --wait wait for a primary to appear\n"));
|
printf(_(" -W, --wait wait for a primary to appear\n"));
|
||||||
puts("");
|
puts("");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user