standby follow: don't restart server (PostgreSQL 13 and later)

As of PostgreSQL 13, changes to the fundamental replication
configuration can be applied with a simple SIGHUP, no restart
required.

In case the old behaviour is desired, i.e. a full restart to apply
the configuration changes, the new configuration parameter
"standby_follow_restart" can be set. This parameter has no effect
in PostgreSQL 12 and earlier.
This commit is contained in:
Ian Barwick
2020-09-29 16:37:09 +09:00
parent 48f95f9a39
commit 73d2088a85
7 changed files with 58 additions and 5 deletions

View File

@@ -316,6 +316,16 @@ struct ConfigFileSetting config_file_settings[] =
{},
{}
},
/* standby_follow_restart */
{
"standby_follow_restart",
CONFIG_BOOL,
{ .boolptr = &config_file_options.standby_follow_restart },
{ .booldefault = DEFAULT_STANDBY_FOLLOW_RESTART },
{},
{},
{}
},
/* ===========================
* standby switchover settings

View File

@@ -164,6 +164,7 @@ typedef struct
/* standby follow settings */
int primary_follow_timeout;
int standby_follow_timeout;
bool standby_follow_restart;
/* standby switchover settings */
int shutdown_check_timeout;

View File

@@ -79,11 +79,24 @@
</para>
</listitem>
<listitem>
<para>
<link linkend="repmgr-standby-follow">repmgr standby follow</link>:
In PostgreSQL 13 and later, a standby no longer requires a restart to
follow a new upstream node.
</para>
<para>
The old behaviour (always restarting the standby to follow a new node)
can be restored by setting the configuration file parameter
<varname>standby_follow_restart</varname> to <literal>true</literal>.
</para>
</listitem>
<listitem>
<para>
<link linkend="repmgr-node-check">repmgr node check</link>:
option <option>--db-connection</option> added to check if &repmgr; can connect to the database on the
local node.
option <option>--db-connection</option> added to check if &repmgr;
can connect to the database on the local node.
</para>
</listitem>
<listitem>

View File

@@ -47,7 +47,15 @@
</para>
<para>
This command will force a restart of PostgreSQL on the standby node.
In PostgreSQL 12 and earlier, this command will force a restart of PostgreSQL on the standby node.
</para>
<para>
In PostgreSQL 13 and later, by default this command will signal PostgreSQL to reload its
configuration, which will cause PostgreSQL to follow the new upstream without
a restart. If this behaviour is not desired for whatever reason, the configuration
file parameter <varname>standby_follow_restart</varname> can be set <literal>true</literal>
to always force a restart.
</para>
<para>

View File

@@ -3361,9 +3361,27 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n
if (server_up == true)
{
/* no "service_restart_command" defined - stop and start using pg_ctl*/
if (PQserverVersion(primary_conn) >= 130000 && config_file_options.standby_follow_restart == false)
{
/* PostgreSQL 13 and later: we'll send SIGHUP via pg_ctl */
get_server_action(ACTION_RELOAD, server_command, config_file_options.data_directory);
success = local_command(server_command, &output_buf);
if (success == true)
{
goto cleanup;
}
/* In the unlikley event that fails, we'll fall back to a restart */
log_warning(_("unable to reload server configuration"));
}
if (config_file_options.service_restart_command[0] == '\0')
{
/* no "service_restart_command" defined - stop and start using pg_ctl */
action = "stopp"; /* sic */
get_server_action(ACTION_STOP_WAIT, server_command, config_file_options.data_directory);
@@ -3445,6 +3463,7 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n
}
}
cleanup:
/*
* If replication slots are in use, and an inactive one for this node
* exists on the former upstream, drop it.

View File

@@ -238,7 +238,8 @@ ssh_options='-q -o ConnectTimeout=10' # Options to append to "ssh"
# for the new primary to become available
#standby_follow_timeout=15 # The max length of time (in seconds) to wait
# for the standby to connect to the primary
#standby_follow_restart=false # Restart the standby instead of sending a SIGHUP
# (only for PostgreSQL 13 and later)
#------------------------------------------------------------------------------
# "standby switchover" settings

View File

@@ -116,6 +116,7 @@
#define DEFAULT_PROMOTE_CHECK_INTERVAL 1 /* seconds */
#define DEFAULT_PRIMARY_FOLLOW_TIMEOUT 60 /* seconds */
#define DEFAULT_STANDBY_FOLLOW_TIMEOUT 30 /* seconds */
#define DEFAULT_STANDBY_FOLLOW_RESTART false
#define DEFAULT_SHUTDOWN_CHECK_TIMEOUT 60 /* seconds */
#define DEFAULT_STANDBY_RECONNECT_TIMEOUT 60 /* seconds */
#define DEFAULT_NODE_REJOIN_TIMEOUT 60 /* seconds */