This is an automated email from the ASF dual-hosted git repository. tuhaihe pushed a commit to branch REL_2_STABLE in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 1e2726b4ba1e84ad2d0e1ef04d13de69d7056651 Author: Brent Doil <[email protected]> AuthorDate: Wed Sep 21 06:26:00 2022 -0400 pg_dump: Define macros for GPDB{5-7} Postgres major version Two conditionals in getTableSchema were testing remote version <= 90400 for GPDB5/6 specific code, which is a bug because it omits GPDB6 (90424 or 90426) altogether. This commit fixes the issue by defining and using a macro for the major Postgres versions for GPDB5-7. These are then used in GPDB specific version checks. Also cleans up some now unused functions. Also check tbinfo->partclause before trying to dereference the pointer. Authored-by: Brent Doil <[email protected]> --- src/bin/pg_dump/pg_backup.h | 8 +++++ src/bin/pg_dump/pg_backup_db.c | 9 ++++- src/bin/pg_dump/pg_dump.c | 81 ++++++------------------------------------ src/bin/pg_dump/pg_dumpall.c | 2 +- 4 files changed, 28 insertions(+), 72 deletions(-) diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 73e0e7c7c0c..9c6a6cddef9 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -26,6 +26,14 @@ #include "fe_utils/simple_list.h" #include "libpq-fe.h" +#define GPDB5_MAJOR_PGVERSION 80300 +#define GPDB6_MAJOR_PGVERSION 90400 +#define GPDB7_MAJOR_PGVERSION 120000 +/* + * GPDB7_MERGE_FIXME: it seems like we don't need those cuz for cbdb we have + * fout->version.type and fout->version.version, which provide better checks + */ +#define CBDB2_MAJOR_PGVERSION 140000 typedef enum trivalue { diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 967e35ec7f2..4964b0fd943 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -191,10 +191,17 @@ ConnectDatabase(Archive *AHX, } keywords[i] = "fallback_application_name"; values[i++] = progname; + /* GPDB: If binary upgrade, we need to use the correct + * session GUC to connect in utility mode, which depends on + * the server version. We don't know the server version until + * we connect for the first time, so set the correct GUC and + * reconnect. + */ if (binary_upgrade) { keywords[i] = "options"; - values[i++] = "-c gp_role=utility"; + values[i++] = AH->public.remoteVersion < GPDB7_MAJOR_PGVERSION ? + "-c gp_session_role=utility" : "-c gp_role=utility"; keywords[i] = NULL; values[i++] = NULL; } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 512434f9496..5087fac372b 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -390,62 +390,9 @@ static char *nextToken(register char **stringp, register const char *delim); static void addDistributedBy(Archive *fout, PQExpBuffer q, const TableInfo *tbinfo, int actual_atts); static void addDistributedByOld(Archive *fout, PQExpBuffer q, const TableInfo *tbinfo, int actual_atts); static void addSchedule(Archive *fout, PQExpBuffer q, const TableInfo *tbinfo); -static bool isMPP(Archive *fout); -static bool isGPDB5000OrLater(Archive *fout); -static bool isGPDB6000OrLater(Archive *fout); /* END MPP ADDITION */ -/* - * Check if we are talking to Greenplum or Cloudberry - */ -static bool -isMPP(Archive *fout) -{ - static int value = -1; /* -1 = not known yet, 0 = no, 1 = yes */ - - /* Query the server on first call, and cache the result */ - if (value == -1) - { - const char *query = "select pg_catalog.version()"; - PGresult *res; - char *ver; - - res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK); - - ver = (PQgetvalue(res, 0, 0)); - if (strstr(ver, "Cloudberry") != NULL || strstr(ver, "Greenplum") != NULL) - value = 1; - else - value = 0; - - PQclear(res); - } - return (value == 1) ? true : false; -} - - -static bool -isGPDB5000OrLater(Archive *fout) -{ - if (!isMPP(fout)) - return false; /* Not GP-based at all. */ - - /* GPDB 5 is based on PostgreSQL 8.3 */ - return fout->remoteVersion >= 80300; -} - - -static bool -isGPDB6000OrLater(Archive *fout) -{ - if (!isMPP(fout)) - return false; /* Not GP-based at all. */ - - /* GPDB 6 is based on PostgreSQL 9.4 */ - return fout->remoteVersion >= 90400; -} - int main(int argc, char **argv) { @@ -958,7 +905,7 @@ main(int argc, char **argv) * We allow the server to be back to 8.3, and up to any minor release of * our own major version. (See also version check in pg_dumpall.c.) */ - fout->minRemoteVersion = 80300; /* we can handle back to 8.3 */ + fout->minRemoteVersion = GPDB5_MAJOR_PGVERSION; /* we can handle back to 8.3 */ fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99; fout->numWorkers = numWorkers; @@ -3818,9 +3765,9 @@ dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf, } /* - * If we're upgrading from GPDB 5 or below, use the legacy hash ops. + * If we're upgrading from GPDB 5, use the legacy hash ops. */ - if (AH->dopt->binary_upgrade && AH->remoteVersion < 90400) + if (AH->dopt->binary_upgrade && AH->remoteVersion < GPDB6_MAJOR_PGVERSION) { makeAlterConfigCommand(conn, "gp_use_legacy_hashops=on", "DATABASE", dbname, NULL, NULL, outbuf); @@ -7286,7 +7233,7 @@ getTables(Archive *fout, int *numTables) " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE) " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"); - if (fout->remoteVersion <= 90426) // GPDB 6 or below + if (fout->remoteVersion < GPDB7_MAJOR_PGVERSION) appendPQExpBufferStr(query, "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid\n" "LEFT JOIN pg_partition p ON pr.paroid = p.oid\n" @@ -13117,7 +13064,6 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) char **allargtypes = NULL; char **argmodes = NULL; char **argnames = NULL; - bool isGE50 = isGPDB5000OrLater(fout); char **configitems = NULL; int nconfigitems = 0; const char *keyword; @@ -13178,7 +13124,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "false AS proleakproof,\n"); /* GPDB6 added proexeclocation */ - if (fout->remoteVersion >= 90400) + if (fout->remoteVersion >= GPDB6_MAJOR_PGVERSION) appendPQExpBuffer(query, "proexeclocation,\n"); else @@ -13250,12 +13196,8 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) probin = NULL; prosqlbody = PQgetvalue(res, 0, PQfnumber(res, "prosqlbody")); } - /* - * GPDB_14_MERGE_FIXME: - * isGE50 is >= 80300 but upstream is (fout->remoteVersion >= 80400) - * Need to check. - */ - if (isGE50) + + if (fout->remoteVersion >= GPDB5_MAJOR_PGVERSION) { funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs")); funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs")); @@ -17061,7 +17003,6 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer bool isweb = false; bool iswritable = false; char *options; - bool gpdb6OrLater = isGPDB6000OrLater(fout); char *logerrors = NULL; char *on_clause; char *qualrelname; @@ -17077,7 +17018,7 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer qualrelname); /* Now get required information from pg_exttable */ - if (gpdb6OrLater) + if (fout->remoteVersion >= GPDB6_MAJOR_PGVERSION) { appendPQExpBuffer(query, "SELECT x.urilocation, x.execlocation, x.fmttype, x.fmtopts, x.command, " @@ -17928,7 +17869,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) * These do not exist on GPDB7, so first check if we are dumping * from <= GPDB6. */ - if (fout->remoteVersion <= 90400 && + if (fout->remoteVersion < GPDB7_MAJOR_PGVERSION && (*tbinfo->partclause && *tbinfo->partclause != '\0')) { /* partition by clause */ @@ -18109,7 +18050,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) appendStringLiteralAH(q, tbinfo->attnames[j], fout); /* GPDB partitioning */ - if (fout->remoteVersion <= 90400) + if (fout->remoteVersion < GPDB7_MAJOR_PGVERSION) { /* * Do for all descendants of a partition table. @@ -20775,7 +20716,7 @@ addSchedule(Archive *fout, PQExpBuffer q, const TableInfo *tbinfo) static void addDistributedBy(Archive *fout, PQExpBuffer q, const TableInfo *tbinfo, int actual_atts) { - if (isGPDB6000OrLater(fout)) + if (fout->remoteVersion >= GPDB6_MAJOR_PGVERSION) { PQExpBuffer query = createPQExpBuffer(); PGresult *res; diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 83473746578..43fc2e52a8e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -2638,7 +2638,7 @@ connectDatabase(const char *dbname, const char *connection_string, * our own major version. (See also version check in pg_dump.c.) */ if (my_version != server_version - && (server_version < 80300 || /* we can handle back to 8.3 */ + && (server_version < GPDB5_MAJOR_PGVERSION || /* we can handle back to 8.3 */ (server_version / 100) > (my_version / 100))) { pg_log_error("server version: %s; %s version: %s", --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
