From cf46834041fae439782cb19ce0fb4cf747775d3a Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 17 May 2016 15:19:20 -0300 Subject: [PATCH] Add new option pg_restore_command. This can be used so that repmgr standby clone adds the string specified in repmgr.conf as a restore_command in recovery.conf. We can use this option for integration with barman by setting the parameter to an appropriate get-wal call. --- config.c | 6 +++++- config.h | 3 ++- repmgr.c | 9 +++++++++ repmgr.conf.sample | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index c32166bb..dccac61c 100644 --- a/config.c +++ b/config.c @@ -224,6 +224,7 @@ parse_config(t_configuration_options *options) memset(options->pg_bindir, 0, sizeof(options->pg_bindir)); memset(options->pg_ctl_options, 0, sizeof(options->pg_ctl_options)); memset(options->pg_basebackup_options, 0, sizeof(options->pg_basebackup_options)); + memset(options->pg_restore_command, 0, sizeof(options->pg_restore_command)); /* default master_response_timeout is 60 seconds */ options->master_response_timeout = 60; @@ -340,7 +341,8 @@ parse_config(t_configuration_options *options) strncpy(options->follow_command, value, MAXLEN); else if (strcmp(name, "master_response_timeout") == 0) options->master_response_timeout = repmgr_atoi(value, "master_response_timeout", &config_errors, false); - /* 'primary_response_timeout' as synonym for 'master_response_timeout' - + /* + * 'primary_response_timeout' as synonym for 'master_response_timeout' - * we'll switch terminology in a future release (3.1?) */ else if (strcmp(name, "primary_response_timeout") == 0) @@ -372,6 +374,8 @@ parse_config(t_configuration_options *options) parse_event_notifications_list(options, value); else if (strcmp(name, "tablespace_mapping") == 0) tablespace_list_append(options, value); + else if (strcmp(name, "pg_restore_command") == 0) + strncpy(options->pg_restore_command, value, MAXLEN); else { known_parameter = false; diff --git a/config.h b/config.h index b5f3099b..37186444 100644 --- a/config.h +++ b/config.h @@ -72,6 +72,7 @@ typedef struct char pg_bindir[MAXLEN]; char pg_ctl_options[MAXLEN]; char pg_basebackup_options[MAXLEN]; + char pg_restore_command[MAXLEN]; char logfile[MAXLEN]; int monitor_interval_secs; int retry_promote_interval_secs; @@ -82,7 +83,7 @@ typedef struct TablespaceList tablespace_mapping; } t_configuration_options; -#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, NO_UPSTREAM_NODE, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "", "", 0, 0, 0, 0, "", { NULL, NULL }, {NULL, NULL} } +#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, NO_UPSTREAM_NODE, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "", "", "", 0, 0, 0, 0, "", { NULL, NULL }, {NULL, NULL} } typedef struct ErrorListCell { diff --git a/repmgr.c b/repmgr.c index b925e48d..507f8a25 100644 --- a/repmgr.c +++ b/repmgr.c @@ -4219,6 +4219,15 @@ create_recovery_file(const char *data_dir) log_debug(_("recovery.conf: %s"), line); } + /* If pg_restore_command is set, we use it as resore_cmmand in recovery.conf */ + if (strcmp(options.pg_restore_command, "") != 0) + { + maxlen_snprintf(line, "restore_command = '%s'\n", + options.pg_restore_command); + if (write_recovery_file_line(recovery_file, recovery_file_path, line) == false) + return false; + log_debug(_("recovery.conf: %s"), line); + } fclose(recovery_file); return true; diff --git a/repmgr.conf.sample b/repmgr.conf.sample index fc2bd5b4..5964f14d 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -113,6 +113,10 @@ # # tablespace_mapping=/path/to/original/tablespace=/path/to/new/tablespace +# You can specify a restore_command to be used in the recovery.conf that +# will be placed in the cloned standby +# +# pg_resore_command = cp /path/to/archived/wals/%f %p # Failover settings (repmgrd) # ---------------------------