From 0d73d3c2b5c6d89c90f4c191cf3e7f06e95a480a Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 3 Apr 2018 14:06:13 +0900 Subject: [PATCH] Enable provision of "archive_cleanup_command" in recovery.conf If "archive_cleanup_command" is defined in "repmgr.conf", a corresponding entry will be made in the node's "recovery.conf" file after cloning a standby. Note that we recommend using PgBarman to manage WAL archives, but are providing this facility to help repmgr to be integrated in existing environments. Implements GitHub #416. --- configfile.c | 3 ++ configfile.h | 5 ++- doc/cloning-standbys.sgml | 2 +- doc/repmgr-standby-clone.sgml | 72 ++++++++++++++++++++++++++++++++++- repmgr-action-standby.c | 11 +++++- repmgr.conf.sample | 14 ++++--- 6 files changed, 97 insertions(+), 10 deletions(-) diff --git a/configfile.c b/configfile.c index 6e00205d..80c8f587 100644 --- a/configfile.c +++ b/configfile.c @@ -314,6 +314,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->tablespace_mapping.tail = NULL; memset(options->recovery_min_apply_delay, 0, sizeof(options->recovery_min_apply_delay)); options->recovery_min_apply_delay_provided = false; + memset(options->archive_cleanup_command, 0, sizeof(options->archive_cleanup_command)); options->use_primary_conninfo_password = false; memset(options->passfile, 0, sizeof(options->passfile)); @@ -508,6 +509,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * parse_time_unit_parameter(name, value, options->recovery_min_apply_delay, error_list); options->recovery_min_apply_delay_provided = true; } + else if (strcmp(name, "archive_cleanup_command") == 0) + strncpy(options->archive_cleanup_command, value, MAXLEN); else if (strcmp(name, "use_primary_conninfo_password") == 0) options->use_primary_conninfo_password = parse_bool(value, name, error_list); else if (strcmp(name, "passfile") == 0) diff --git a/configfile.h b/configfile.h index 873caa40..7bd9e094 100644 --- a/configfile.h +++ b/configfile.h @@ -89,6 +89,7 @@ typedef struct TablespaceList tablespace_mapping; char recovery_min_apply_delay[MAXLEN]; bool recovery_min_apply_delay_provided; + char archive_cleanup_command[MAXLEN]; bool use_primary_conninfo_password; char passfile[MAXPGPATH]; @@ -161,8 +162,8 @@ typedef struct UNKNOWN_NODE_ID, "", "", "", "", "", REPLICATION_TYPE_PHYSICAL, \ /* log settings */ \ "", "", "", DEFAULT_LOG_STATUS_INTERVAL, \ - /* standby action settings */ \ - false, "", "", { NULL, NULL }, "", false, false, "", \ + /* standby clone settings */ \ + false, "", "", { NULL, NULL }, "", false, "", false, "", \ /* standby promote settings */ \ DEFAULT_PROMOTE_CHECK_TIMEOUT, DEFAULT_PROMOTE_CHECK_INTERVAL, \ /* node check settings */ \ diff --git a/doc/cloning-standbys.sgml b/doc/cloning-standbys.sgml index 68bfcbac..fd7b0619 100644 --- a/doc/cloning-standbys.sgml +++ b/doc/cloning-standbys.sgml @@ -51,7 +51,7 @@ - + Prerequisites for cloning from Barman In order to enable Barman support for repmgr standby clone, following diff --git a/doc/repmgr-standby-clone.sgml b/doc/repmgr-standby-clone.sgml index 74cae20c..9ac9daab 100644 --- a/doc/repmgr-standby-clone.sgml +++ b/doc/repmgr-standby-clone.sgml @@ -65,7 +65,71 @@ - + + + recovery.conf + customising with "repmgr standby clone" + + + Customising recovery.conf + + By default, &repmgr; will create a minimal recovery.conf + containing following parameters: + + + + + + standby_mode (always 'on') + + + + recovery_target_timeline (always 'latest') + + + + primary_conninfo + + + + primary_slot_name (if replication slots in use) + + + + + + The following additional parameters can be specified in repmgr.conf + for inclusion in recovery.conf: + + + + + + restore_command + + + + archive_cleanup_command + + + + recovery_min_apply_delay + + + + + + + We recommend using Barman to manage + WAL file archiving. For more details on combining &repmgr; and Barman, + in particular using restore_command to configure Barman as a backu source of + WAL files, see . + + + + + + Managing WAL during the cloning process When initially cloning a standby, you will need to ensure @@ -102,6 +166,12 @@ + + + recovery.conf + generating for a standby cloned by another method + + Using a standby cloned by another method &repmgr; supports standbys cloned by another method (e.g. using barman's diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 951f1cdb..82a1a56e 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -5864,7 +5864,6 @@ create_recovery_file(t_node_info *node_record, t_conninfo_param_list *recovery_c appendPQExpBuffer(&recovery_file_buf, "recovery_min_apply_delay = %s\n", config_file_options.recovery_min_apply_delay); - } /* primary_slot_name = '...' (optional, for 9.4 and later) */ @@ -5889,6 +5888,16 @@ create_recovery_file(t_node_info *node_record, t_conninfo_param_list *recovery_c free(escaped); } + /* archive_cleanup_command (optional) */ + if (config_file_options.archive_cleanup_command[0] != '\0') + { + char *escaped = escape_recovery_conf_value(config_file_options.archive_cleanup_command); + appendPQExpBuffer(&recovery_file_buf, + "archive_cleanup_command = '%s'\n", + escaped); + free(escaped); + } + if (as_file == true) { maxpath_snprintf(recovery_file_path, "%s/%s", dest, RECOVERY_COMMAND_FILE); diff --git a/repmgr.conf.sample b/repmgr.conf.sample index 84274c59..5d9f8fd5 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -65,9 +65,6 @@ # at least the number of standbys which will connect # to the primary. -#recovery_min_apply_delay= # If provided, "recovery_min_apply_delay" in recovery.conf - # will be set to this value. - #------------------------------------------------------------------------------ # Witness server settings #------------------------------------------------------------------------------ @@ -175,8 +172,15 @@ ssh_options='-q -o ConnectTimeout=10' # Options to append to "ssh" # file system location to another. This # parameter can be provided multiple times. -#restore_command='' # This will be placed in the recovery.conf - # file generated by repmgr +#restore_command='' # This will be placed in the recovery.conf file generated + # by repmgr. + +#archive_cleanup_command='' # This will be placed in the recovery.conf file generated + # by repmgr. Note we recommend using Barman for managing + # WAL archives (see: https://www.pgbarman.org ) + +#recovery_min_apply_delay= # If provided, "recovery_min_apply_delay" in recovery.conf + # will be set to this value (PostgreSQL 9.4 and later). #------------------------------------------------------------------------------