From 892e3b93d17e6f1433b01666097688c45e38ad7c Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 15 Feb 2017 22:39:59 +0900 Subject: [PATCH] repmgr: support --wal-method (replacing --xlog-method) for pg_basebackup in PostgreSQL 10 --- HISTORY | 4 ++-- repmgr.c | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/HISTORY b/HISTORY index ead2da19..4eb22205 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,4 @@ -3.3.2 2017-05-18 +3.3.2 2017-05-22 repmgr: ensure --replication-user option is honoured when passing database connection parameters as a conninfo string (Ian) repmgr: improve detection of pg_rewind on remote server (Ian) @@ -8,7 +8,7 @@ repmgr: add missing `-P` option (Ian) repmgrd: monitoring statistic reporting fixes (Ian) -3.3.1 2017-03- +3.3.1 2017-03-13 repmgrd: prevent invalid apply lag value being written to the monitoring table (Ian) repmgrd: fix error in XLogRecPtr conversion when calculating diff --git a/repmgr.c b/repmgr.c index a184c726..40db336f 100644 --- a/repmgr.c +++ b/repmgr.c @@ -96,7 +96,7 @@ static int test_ssh_connection(char *host, char *remote_user); static int copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory, int server_version_num); -static int run_basebackup(const char *data_dir, int server_version); +static int run_basebackup(const char *data_dir, int server_version_num); static void check_parameters_for_action(const int action); static bool create_schema(PGconn *conn); static bool create_recovery_file(const char *data_dir, t_conninfo_param_list *recovery_conninfo); @@ -159,7 +159,7 @@ static char *param_get(t_conninfo_param_list *param_list, const char *param); static bool parse_conninfo_string(const char *conninfo_str, t_conninfo_param_list *param_list, char *errmsg, bool ignore_application_name); static void conn_to_param_list(PGconn *conn, t_conninfo_param_list *param_list); static char *param_list_to_string(t_conninfo_param_list *param_list); -static void parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_options *backup_options); +static void parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_options *backup_options, int server_version_num); static void config_file_list_init(t_configfile_list *list, int max_size); static void config_file_list_add(t_configfile_list *list, const char *file, const char *filename, bool in_data_dir); @@ -7006,7 +7006,7 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, static int -run_basebackup(const char *data_dir, int server_version) +run_basebackup(const char *data_dir, int server_version_num) { char script[MAXLEN]; int r = 0; @@ -7018,7 +7018,7 @@ run_basebackup(const char *data_dir, int server_version) * Parse the pg_basebackup_options provided in repmgr.conf - we'll want * to check later whether certain options were set by the user */ - parse_pg_basebackup_options(options.pg_basebackup_options, &backup_options); + parse_pg_basebackup_options(options.pg_basebackup_options, &backup_options, server_version_num); /* Create pg_basebackup command line options */ @@ -7097,6 +7097,7 @@ run_basebackup(const char *data_dir, int server_version) * From 9.6, if replication slots are in use, we'll have previously * created a slot with reserved LSN, and will stream from that slot to avoid * WAL buildup on the master using the -S/--slot, which requires -X/--xlog-method=stream + * (from 10, -X/--wal-method=stream) */ if (!strlen(backup_options.xlog_method)) { @@ -7114,17 +7115,17 @@ run_basebackup(const char *data_dir, int server_version) * * NOTE: * It's possible to set 'pg_basebackup_options' with an invalid combination - * of values for --xlog-method and --slot - we're not checking that, just that + * of values for --wal-method (--xlog-method) and --slot - we're not checking that, just that * we're not overriding any user-supplied values */ - if (server_version >= 90600 && options.use_replication_slots) + if (server_version_num >= 90600 && options.use_replication_slots) { bool slot_add = true; /* * Check whether 'pg_basebackup_options' in repmgr.conf has the --slot option set, - * or if --xlog-method is set to a value other than "stream" (in which case we can't - * use --slot). + * or if --wal-method (--xlog-method) is set to a value other than "stream" + * (in which case we can't use --slot). */ if (strlen(backup_options.slot) || (strlen(backup_options.xlog_method) && strcmp(backup_options.xlog_method, "stream") != 0)) { slot_add = false; @@ -7752,7 +7753,7 @@ create_schema(PGconn *conn) * to perform additional cleanup * * char *server_version_string - * passed to get_server_version(), which will place the human-readble + * passed to get_server_version(), which will place the human-readable * server version string there (e.g. "9.4.0") */ static int @@ -7865,7 +7866,7 @@ check_upstream_config(PGconn *conn, int server_version_num, bool exit_on_error) * this will influence some checks */ - parse_pg_basebackup_options(options.pg_basebackup_options, &backup_options); + parse_pg_basebackup_options(options.pg_basebackup_options, &backup_options, server_version_num); if (strlen(backup_options.xlog_method) && strcmp(backup_options.xlog_method, "stream") != 0) xlog_stream = false; @@ -8751,7 +8752,7 @@ param_list_to_string(t_conninfo_param_list *param_list) static void -parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_options *backup_options) +parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_options *backup_options, int server_version_num) { int options_len = strlen(pg_basebackup_options) + 1; char *options_string = pg_malloc(options_len); @@ -8771,18 +8772,33 @@ parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_opti int optindex = 0; + struct option *long_options; + /* We're only interested in these options */ - static struct option long_options[] = + static struct option long_options_9[] = { {"slot", required_argument, NULL, 'S'}, {"xlog-method", required_argument, NULL, 'X'}, {NULL, 0, NULL, 0} }; + /* From PostgreSQL 10, --xlog-method is renamed --wal-method */ + static struct option long_options_10[] = + { + {"slot", required_argument, NULL, 'S'}, + {"wal-method", required_argument, NULL, 'X'}, + {NULL, 0, NULL, 0} + }; + /* Don't attempt to tokenise an empty string */ if (!strlen(pg_basebackup_options)) return; + if (server_version_num >= 100000) + long_options = long_options_10; + else + long_options = long_options_9; + /* Copy the string before operating on it with strtok() */ strncpy(options_string, pg_basebackup_options, options_len);