diff --git a/src/bin/pg_basebackup/pg_basebackup.cpp b/src/bin/pg_basebackup/pg_basebackup.cpp index 0aac2bb30..865185d9b 100644 --- a/src/bin/pg_basebackup/pg_basebackup.cpp +++ b/src/bin/pg_basebackup/pg_basebackup.cpp @@ -1349,6 +1349,32 @@ static void BaseBackup(void) disconnect_and_exit(1); } + /* + * End of copy data. Final result is already checked inside the loop. + */ + PQclear(res); + + res = PQgetResult(conn); + if (res != NULL) { + /* + * We expect the result to be NULL, otherwise we received some unexpected result. + * We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE, + * otherwise we have problem! Report error and disconnect. + */ + fprintf(stderr, + _("%s: unexpected result received after final result, status: %u\n"), + progname, + PQresultStatus(res)); + free(sysidentifier); + disconnect_and_exit(1); + } + + if (verbose) { + fprintf(stderr, "%s: fetching MOT checkpoint\n", progname); + } + + FetchMotCheckpoint(basedir, conn, progname, (bool)verbose, format, compresslevel); + if (bgchild > 0) { #ifndef WIN32 int status; @@ -1428,32 +1454,6 @@ static void BaseBackup(void) #endif } - /* - * End of copy data. Final result is already checked inside the loop. - */ - PQclear(res); - - res = PQgetResult(conn); - if (res != NULL) { - /* - * We expect the result to be NULL, otherwise we received some unexpected result. - * We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE, - * otherwise we have problem! Report error and disconnect. - */ - fprintf(stderr, - _("%s: unexpected result received after final result, status: %u\n"), - progname, - PQresultStatus(res)); - free(sysidentifier); - disconnect_and_exit(1); - } - - if (verbose) { - fprintf(stderr, "%s: fetching MOT checkpoint\n", progname); - } - - FetchMotCheckpoint(basedir, conn, progname, (bool)verbose, format, compresslevel); - PQfinish(conn); conn = NULL; diff --git a/src/bin/pg_ctl/backup.cpp b/src/bin/pg_ctl/backup.cpp index 5ad00bbb2..822334699 100755 --- a/src/bin/pg_ctl/backup.cpp +++ b/src/bin/pg_ctl/backup.cpp @@ -1316,6 +1316,43 @@ static void BaseBackup(const char* dirname, uint32 term) disconnect_and_exit(1); } + /* + * End of copy data. Final result is already checked inside the loop. + */ + PQclear(res); + + res = PQgetResult(streamConn); + if (res != NULL) { + /* + * We expect the result to be NULL, otherwise we received some unexpected result. + * We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE, + * otherwise we have problem! Report error and disconnect. + */ + pg_log(PG_WARNING, _("unexpected result received after final result, status: %u\n"), PQresultStatus(res)); + disconnect_and_exit(1); + } + + show_full_build_process("fetching MOT checkpoint"); + + /* see if we have an mot conf file configured */ + nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "postgresql.conf"); + securec_check_ss_c(nRet, "\0", "\0"); + motConfPath = GetOptionValueFromFile(confPath, "mot_config_file"); + if (motConfPath != NULL) { + motChkptDir = GetOptionValueFromFile(motConfPath, "checkpoint_dir"); + } else { + nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "mot.conf"); + securec_check_ss_c(nRet, "\0", "\0"); + motChkptDir = GetOptionValueFromFile(confPath, "checkpoint_dir"); + } + FetchMotCheckpoint(motChkptDir ? (const char*)motChkptDir : dirname, streamConn, progname, (bool)verbose); + if (motChkptDir) { + free(motChkptDir); + } + if (motConfPath) { + free(motConfPath); + } + if (bgchild > 0) { #ifndef WIN32 int status; @@ -1389,45 +1426,6 @@ static void BaseBackup(const char* dirname, uint32 term) TABLESPACE_LIST_RELEASE(); - /* - * End of copy data. Final result is already checked inside the loop. - */ - PQclear(res); - - res = PQgetResult(streamConn); - if (res != NULL) { - /* - * We expect the result to be NULL, otherwise we received some unexpected result. - * We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE, - * otherwise we have problem! Report error and disconnect. - */ - pg_log(PG_WARNING, _("unexpected result received after final result, status: %u\n"), PQresultStatus(res)); - disconnect_and_exit(1); - } - - show_full_build_process("fetching MOT checkpoint"); - - /* see if we have an mot conf file configured */ - nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "postgresql.conf"); - securec_check_ss_c(nRet, "\0", "\0"); - motConfPath = GetOptionValueFromFile(confPath, "mot_config_file"); - if (motConfPath != NULL) { - motChkptDir = GetOptionValueFromFile(motConfPath, "checkpoint_dir"); - } else { - nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "mot.conf"); - securec_check_ss_c(nRet, "\0", "\0"); - motChkptDir = GetOptionValueFromFile(confPath, "checkpoint_dir"); - } - - FetchMotCheckpoint(motChkptDir ? (const char*)motChkptDir : dirname, streamConn, progname, (bool)verbose); - - if (motChkptDir) { - free(motChkptDir); - } - if (motConfPath) { - free(motConfPath); - } - PQfinish(streamConn); streamConn = NULL;