diff --git a/configdata.c b/configdata.c index 45e25a19..2c07f2f6 100644 --- a/configdata.c +++ b/configdata.c @@ -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 diff --git a/configfile.h b/configfile.h index 12440897..a1aa7395 100644 --- a/configfile.h +++ b/configfile.h @@ -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; diff --git a/doc/appendix-release-notes.xml b/doc/appendix-release-notes.xml index 91440806..6fbadb4e 100644 --- a/doc/appendix-release-notes.xml +++ b/doc/appendix-release-notes.xml @@ -79,11 +79,24 @@ + + + repmgr standby follow: + In PostgreSQL 13 and later, a standby no longer requires a restart to + follow a new upstream node. + + + The old behaviour (always restarting the standby to follow a new node) + can be restored by setting the configuration file parameter + standby_follow_restart to true. + + + repmgr node check: - option added to check if &repmgr; can connect to the database on the - local node. + option added to check if &repmgr; + can connect to the database on the local node. diff --git a/doc/repmgr-standby-follow.xml b/doc/repmgr-standby-follow.xml index cca1e2e1..60dd2c61 100644 --- a/doc/repmgr-standby-follow.xml +++ b/doc/repmgr-standby-follow.xml @@ -47,7 +47,15 @@ - 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. + + + + 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 standby_follow_restart can be set true + to always force a restart. diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 90399560..618e7c34 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -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. diff --git a/repmgr.conf.sample b/repmgr.conf.sample index b6c69302..07d0fae1 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -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 diff --git a/repmgr.h b/repmgr.h index 6e875cbe..5bc6020d 100644 --- a/repmgr.h +++ b/repmgr.h @@ -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 */