From 773159a9e854259ef9e6d1e4f9784530d287efa8 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 13 Oct 2020 14:27:46 +0900 Subject: [PATCH] standby clone: move check for --waldir pg_basebackup option When cloning from Barman, and --no-upstream-connection was supplied, the server version number will not be available at this point in the code. It will however later be extracted from the Barman metadata, so move the check for the --waldir pg_basebackup option to after this point. Also add an explicit check that a server version number has been obtained (and fall back to extracting it from the cloned data directory), as subsequent operations depend on knowing this to be performed correctly. --- repmgr-action-standby.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index c5f26827..73c79473 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -6944,16 +6944,6 @@ run_file_backup(t_node_info *local_node_record) { t_basebackup_options backup_options = T_BASEBACKUP_OPTIONS_INITIALIZER; - Assert(source_server_version_num != UNKNOWN_SERVER_VERSION_NUM); - - /* - * Parse the pg_basebackup_options provided in repmgr.conf - we need to - * check if --waldir/--xlogdir was provided. - */ - parse_pg_basebackup_options(config_file_options.pg_basebackup_options, - &backup_options, - source_server_version_num, - NULL); /* * Locate Barman's base backups directory */ @@ -7161,6 +7151,37 @@ run_file_backup(t_node_info *local_node_record) unlink(datadir_list_filename); + /* + * At this point we should have the source server version number. + * If not, try and extract it from the data directory. + */ + if (source_server_version_num == UNKNOWN_SERVER_VERSION_NUM) + { + log_warning(_("server version number is unknown")); + source_server_version_num = get_pg_version(local_data_directory, NULL); + + /* + * In the unlikely we are still unable to obtain the server + * version number, there's not a lot which can be done. + */ + if (source_server_version_num == UNKNOWN_SERVER_VERSION_NUM) + { + log_error(_("unable to extract server version number from the data directory, aborting")); + exit(ERR_BAD_CONFIG); + } + log_notice(_("server version number is: %i"), source_server_version_num); + } + + /* + * Parse the pg_basebackup_options provided in repmgr.conf - we need to + * check if --waldir/--xlogdir was provided. + */ + parse_pg_basebackup_options(config_file_options.pg_basebackup_options, + &backup_options, + source_server_version_num, + NULL); + + /* * We must create some PGDATA subdirectories because they are not * included in the Barman backup.