This is an automated email from the ASF dual-hosted git repository. reshke pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit c462e38836ce6d7c68f7b0ad4386b11c8c7a32d8 Author: Vladimir Rachkin <[email protected]> AuthorDate: Tue Mar 25 13:01:16 2025 +0300 Remove unneccesary version checks from pg_dump Upstream has removed support for server versions older than 9.2.[1] The motivation for `error_unsupported_server_version` was to reduce diff footprint when upstream supported much older versions.[2] We still need to support GPDB5 (PostgreSQL 8.3), so remove version checks for PostgreSQL 8.2 and below. 1: https://github.com/postgres/postgres/commit/30e7c175b81d53c0f60f6ad12d1913a6d7d77008 2: https://github.com/bmdoil/gpdb/commit/b4c5a6186b1c0a1d9a3e2250a99546528de0c19e Authored-by: Brent Doil <[email protected]> --- src/bin/pg_dump/common.c | 7 +- src/bin/pg_dump/dumputils.c | 14 -- src/bin/pg_dump/pg_dump.c | 520 ++++++------------------------------------- src/bin/pg_dump/pg_dumpall.c | 118 +--------- 4 files changed, 83 insertions(+), 576 deletions(-) diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index d3ff5cc69d..822a7a1cf9 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -186,11 +186,8 @@ getSchemaData(Archive *fout, int *numTablesPtr) oprinfo = getOperators(fout, &numOperators); oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo)); - if (testExtProtocolSupport(fout)) - { - pg_log_info("reading user-defined external protocols"); - getExtProtocols(fout, &numExtProtocols); - } + pg_log_info("reading user-defined external protocols"); + getExtProtocols(fout, &numExtProtocols); pg_log_info("reading user-defined access methods"); getAccessMethods(fout, &numAccessMethods); diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 51ab650b46..a481687cd5 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -194,20 +194,6 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, } } - /* - * We still need some hacking though to cover the case where new default - * public privileges are added in new versions: the REVOKE ALL will revoke - * them, leading to behavior different from what the old version had, - * which is generally not what's wanted. So add back default privs if the - * source database is too old to have had that particular priv. - */ - if (remoteVersion < 80200 && strcmp(type, "DATABASE") == 0) - { - /* database CONNECT priv didn't exist before 8.2 */ - appendPQExpBuffer(firstsql, "%sGRANT CONNECT ON %s %s TO PUBLIC;\n", - prefix, type, name); - } - /* Scan individual ACL items */ for (i = 0; i < naclitems; i++) { diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index a81ca91b3c..36086d3b8d 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -157,9 +157,6 @@ const char *EXT_PARTITION_NAME_POSTFIX = "_external_partition__"; /* flag indicating whether or not this GP database supports partitioning */ static bool gp_partitioning_available = false; -/* flag indicating whether or not this GP database supports column encoding */ -static bool gp_attribute_encoding_available = false; - static DumpId binary_upgrade_dumpid; /* override for standard extra_float_digits setting */ @@ -383,77 +380,17 @@ static void expand_oid_patterns(SimpleStringList *patterns, static bool is_returns_table_function(int nallargs, char **argmodes); static bool testGPbackend(Archive *fout); static bool testPartitioningSupport(Archive *fout); -static bool testAttributeEncodingSupport(Archive *fout); 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 isGPDB4300OrLater(Archive *fout); static bool isGPDB(Archive *fout); static bool isGPDB5000OrLater(Archive *fout); static bool isGPDB6000OrLater(Archive *fout); -static void error_unsupported_server_version(Archive *fout) pg_attribute_noreturn(); /* END MPP ADDITION */ -/* - * PostgreSQL's pg_dump supports very old server versions, but in GPDB, we - * only need to go back to 8.2-derived GPDB versions (4.something?). A lot of - * that code to deal with old versions has been removed. But in order to not - * change the formatting of the surrounding code, and to make it more clear - * when reading a diff against the corresponding PostgreSQL version of - * pg_dump, calls to this function has been left in place of the removed - * code. - * - * This function should never actually be used, because check that the server - * version is new enough at the beginning of pg_dump. This is just for - * documentation purposes, to show were upstream code has been removed, and - * to avoid those diffs or merge conflicts with upstream. - */ -static void -error_unsupported_server_version(Archive *fout) -{ - pg_log_warning("unexpected server version %d", fout->remoteVersion); - exit_nicely(1); -} - -/* - * If GPDB version is 4.3, pg_proc has prodataaccess column. - */ -static bool -isGPDB4300OrLater(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) - { - if (isGPbackend) - { - const char *query; - PGresult *res; - - query = "select attnum from pg_catalog.pg_attribute " - "where attrelid = 'pg_catalog.pg_proc'::regclass and " - "attname = 'prodataaccess'"; - - res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK); - - if (PQntuples(res) == 1) - value = 1; - else - value = 0; - - PQclear(res); - } - else - value = 0; - } - - return (value == 1) ? true : false; -} - /* * Check if we are talking to GPDB */ @@ -1001,10 +938,10 @@ main(int argc, char **argv) /* - * We allow the server to be back to 8.0, and up to any minor release of + * 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 = 80200; /* we can handle back to 8.2 */ + fout->minRemoteVersion = 80300; /* we can handle back to 8.3 */ fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99; fout->numWorkers = numWorkers; @@ -1054,22 +991,13 @@ main(int argc, char **argv) if (fout->isStandby) dopt.no_unlogged_table_data = true; - /* Select the appropriate subquery to convert user IDs to names */ - if (fout->remoteVersion >= 80100) - username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid ="; - else - error_unsupported_server_version(fout); + username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid ="; /* * Remember whether or not this GP database supports partitioning. */ gp_partitioning_available = testPartitioningSupport(fout); - /* - * Remember whether or not this GP database supports column encoding. - */ - gp_attribute_encoding_available = testAttributeEncodingSupport(fout); - /* check the version for the synchronized snapshots feature */ if (numWorkers > 1 && fout->remoteVersion < 90200 && !dopt.no_synchronized_snapshots) @@ -2421,7 +2349,6 @@ dumpTableData_copy(Archive *fout, const void *dcontext) */ if (tdinfo->filtercond || tbinfo->relkind == RELKIND_FOREIGN_TABLE) { - /* Note: this syntax is only supported in 8.2 and up */ appendPQExpBufferStr(q, "COPY (SELECT "); /* klugery to get rid of parens in column list */ if (strlen(column_list) > 2) @@ -3447,7 +3374,7 @@ dumpDatabase(Archive *fout) "WHERE datname = current_database()", username_subquery); } - else if (fout->remoteVersion >= 80200) + else { appendPQExpBuffer(dbQry, "SELECT tableoid, oid, datname, " "(%s datdba) AS dba, " @@ -3461,20 +3388,6 @@ dumpDatabase(Archive *fout) "WHERE datname = current_database()", username_subquery); } - else - { - error_unsupported_server_version(fout); - appendPQExpBuffer(dbQry, "SELECT tableoid, oid, datname, " - "(%s datdba) AS dba, " - "pg_encoding_to_char(encoding) AS encoding, " - "NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, " - "datacl, '' as rdatacl, datistemplate, " - "-1 as datconnlimit, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace " - "FROM pg_database " - "WHERE datname = current_database()", - username_subquery); - } res = ExecuteSqlQueryForSingleRow(fout, dbQry->data); @@ -3574,42 +3487,28 @@ dumpDatabase(Archive *fout) /* Compute correct tag for archive entry */ appendPQExpBuffer(labelq, "DATABASE %s", qdatname); - /* Dump DB comment if any */ - if (fout->remoteVersion >= 80200) - { - /* - * 8.2 and up keep comments on shared objects in a shared table, so we - * cannot use the dumpComment() code used for other database objects. - * Be careful that the ArchiveEntry parameters match that function. - */ - char *comment = PQgetvalue(res, 0, PQfnumber(res, "description")); + char *comment = PQgetvalue(res, 0, PQfnumber(res, "description")); - if (comment && *comment && !dopt->no_comments) - { - resetPQExpBuffer(dbQry); + if (comment && *comment && !dopt->no_comments) + { + resetPQExpBuffer(dbQry); - /* - * Generates warning when loaded into a differently-named - * database. - */ - appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", qdatname); - appendStringLiteralAH(dbQry, comment, fout); - appendPQExpBufferStr(dbQry, ";\n"); + /* + * Generates warning when loaded into a differently-named + * database. + */ + appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", qdatname); + appendStringLiteralAH(dbQry, comment, fout); + appendPQExpBufferStr(dbQry, ";\n"); - ArchiveEntry(fout, nilCatalogId, createDumpId(), - ARCHIVE_OPTS(.tag = labelq->data, - .owner = dba, - .description = "COMMENT", - .section = SECTION_NONE, - .createStmt = dbQry->data, - .deps = &dbDumpId, - .nDeps = 1)); - } - } - else - { - dumpComment(fout, "DATABASE", qdatname, NULL, dba, - dbCatId, 0, dbDumpId); + ArchiveEntry(fout, nilCatalogId, createDumpId(), + ARCHIVE_OPTS(.tag = labelq->data, + .owner = dba, + .description = "COMMENT", + .section = SECTION_NONE, + .createStmt = dbQry->data, + .deps = &dbDumpId, + .nDeps = 1)); } /* Dump DB security label, if enabled */ @@ -6090,7 +5989,7 @@ getTypes(Archive *fout, int *numTypes) "FROM pg_type", username_subquery); } - else if (fout->remoteVersion >= 80300) + else { appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " "typnamespace, NULL AS typacl, NULL as rtypacl, " @@ -6105,21 +6004,6 @@ getTypes(Archive *fout, int *numTypes) "FROM pg_type", username_subquery); } - else - { - error_unsupported_server_version(fout); - appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " - "typnamespace, NULL AS typacl, NULL as rtypacl, " - "NULL AS inittypacl, NULL AS initrtypacl, " - "(%s typowner) AS rolname, " - "typelem, typrelid, " - "CASE WHEN typrelid = 0 THEN ' '::\"char\" " - "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " - "typtype, typisdefined, " - "typname[0] = '_' AND typelem != 0 AS isarray " - "FROM pg_type", - username_subquery); - } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6266,15 +6150,6 @@ getTypeStorageOptions(Archive *fout, int *numTypes) int i_typoptions; int i_rolname; - if (gp_attribute_encoding_available == false) - { - numTypes = 0; - tstorageoptions = (TypeStorageOptions *) pg_malloc(0); - destroyPQExpBuffer(query); - return tstorageoptions; - } - - /* * The following statement used format_type to resolve an internal name to its equivalent sql name. * The format_type seems to do two things, it translates an internal type name (e.g. bpchar) into its @@ -6882,7 +6757,7 @@ getAggregates(Archive *fout, int *numAggs) destroyPQExpBuffer(initacl_subquery); destroyPQExpBuffer(initracl_subquery); } - else if (fout->remoteVersion >= 80200) + else { appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " "pronamespace AS aggnamespace, " @@ -6906,23 +6781,6 @@ getAggregates(Archive *fout, int *numAggs) "deptype = 'e')"); appendPQExpBufferChar(query, ')'); } - else - { - error_unsupported_server_version(fout); - appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " - "pronamespace AS aggnamespace, " - "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, " - "proargtypes, " - "(%s proowner) AS rolname, " - "proacl AS aggacl, " - "NULL AS raggacl, " - "NULL AS initaggacl, NULL AS initraggacl " - "FROM pg_proc " - "WHERE proisagg " - "AND pronamespace != " - "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')", - username_subquery); - } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7972,7 +7830,7 @@ getTables(Archive *fout, int *numTables) RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } - else if (fout->remoteVersion >= 80200) + else { /* * Left join to pick up dependency info linking sequences to their @@ -8019,62 +7877,14 @@ getTables(Archive *fout, int *numTables) "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " "LEFT JOIN pg_partition p ON pr.paroid = p.oid " "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0) " - "WHERE c.relkind in ('%c', '%c', '%c', '%c') %s " + "WHERE c.relkind in ('%c', '%c', '%c', '%c') " + "AND c.oid NOT IN (select p.parchildrelid from pg_partition_rule p " + "LEFT JOIN pg_exttable e on p.parchildrelid=e.reloid where e.reloid is null) " "AND c.relnamespace <> 3012 " /* BM_BITMAPINDEX_NAMESPACE in GPDB 5 and below */ "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - fout->remoteVersion >= 80209 ? - "AND c.oid NOT IN (select p.parchildrelid from pg_partition_rule p left " - "join pg_exttable e on p.parchildrelid=e.reloid where e.reloid is null)" : ""); - } - else - { - error_unsupported_server_version(fout); - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, relname, " - "relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "relkind, relnamespace, " - "(%s relowner) AS rolname, " - "relchecks, (reltriggers <> 0) AS relhastriggers, " - "relhasindex, relhasrules, relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "0 AS relfrozenxid, 0 AS relminmxid," - "0 AS toid, " - "0 AS tfrozenxid, 0 AS tminmxid," - "'p' AS relpersistence, 't' as relispopulated, " - "'d' AS relreplident, relpages, " - "NULL AS amname, " - "NULL AS foreignserver, " - "NULL AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "NULL AS reloptions, " - "NULL AS toast_reloptions, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'i') " - "WHERE relkind in ('%c', '%c', '%c', '%c') " - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } @@ -8618,7 +8428,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "ORDER BY indexname", tbinfo->dobj.catId.oid); } - else if (fout->remoteVersion >= 80200) + else { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " @@ -8652,40 +8462,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "ORDER BY indexname", tbinfo->dobj.catId.oid); } - else - { - error_unsupported_server_version(fout); - appendPQExpBuffer(query, - "SELECT t.tableoid, t.oid, " - "t.relname AS indexname, " - "0 AS parentidx, " - "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " - "t.relnatts AS indnkeyatts, " - "t.relnatts AS indnatts, " - "i.indkey, i.indisclustered, " - "false AS indisreplident, " - "c.contype, c.conname, " - "c.condeferrable, c.condeferred, " - "c.tableoid AS contableoid, " - "c.oid AS conoid, " - "null AS condef, " - "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, " - "null AS indreloptions, " - "'' AS indstatcols, " - "'' AS indstatvals " - "FROM pg_catalog.pg_index i " - "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " - "LEFT JOIN pg_catalog.pg_depend d " - "ON (d.classid = t.tableoid " - "AND d.objid = t.oid " - "AND d.deptype = 'i') " - "LEFT JOIN pg_catalog.pg_constraint c " - "ON (d.refclassid = c.tableoid " - "AND d.refobjid = c.oid) " - "WHERE i.indrelid = '%u'::pg_catalog.oid " - "ORDER BY indexname", - tbinfo->dobj.catId.oid); - } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -9664,7 +9440,7 @@ getProcLangs(Archive *fout, int *numProcLangs) "ORDER BY oid", username_subquery); } - else if (fout->remoteVersion >= 80100) + else { /* Languages are owned by the bootstrap superuser, OID 10 */ appendPQExpBuffer(query, "SELECT tableoid, oid, " @@ -9678,21 +9454,6 @@ getProcLangs(Archive *fout, int *numProcLangs) "ORDER BY oid", username_subquery); } - else - { - error_unsupported_server_version(fout); - /* Languages are owned by the bootstrap superuser, sysid 1 */ - appendPQExpBuffer(query, "SELECT tableoid, oid, " - "lanname, lanpltrusted, lanplcallfoid, " - "0 AS laninline, lanvalidator, lanacl, " - "NULL AS rlanacl, " - "NULL AS initlanacl, NULL AS initrlanacl, " - "(%s '1') AS lanowner " - "FROM pg_language " - "WHERE lanispl " - "ORDER BY oid", - username_subquery); - } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -10115,15 +9876,6 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ntups = PQntuples(res); i_attencoding = PQfnumber(res, "attencoding"); - /* - * attencoding is a Cloudberry specific column in the query, make sure - * it wasn't missed in a merge with PostgreSQL. - */ - if (gp_attribute_encoding_available && i_attencoding < 0) - { - pg_log_warning("attencoding column required in table attributes query"); - exit_nicely(1); - } tbinfo->numatts = ntups; tbinfo->attnames = (char **) pg_malloc(ntups * sizeof(char *)); @@ -10180,7 +9932,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) tbinfo->inhNotNull[j] = false; /* column storage attributes */ - if (gp_attribute_encoding_available && !PQgetisnull(res, j, i_attencoding)) + if (!PQgetisnull(res, j, i_attencoding)) tbinfo->attencoding[j] = pg_strdup(PQgetvalue(res, j, i_attencoding)); else tbinfo->attencoding[j] = NULL; @@ -13584,7 +13336,6 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) char **allargtypes = NULL; char **argmodes = NULL; char **argnames = NULL; - bool isGE43 = isGPDB4300OrLater(fout); bool isGE50 = isGPDB5000OrLater(fout); char **configitems = NULL; int nconfigitems = 0; @@ -13652,7 +13403,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "%s\n" "'a' as proexeclocation,\n" "(SELECT procallback FROM pg_catalog.pg_proc_callback WHERE profnoid::pg_catalog.oid = p.oid) as callbackfunc,\n", - (isGE43 ? "prodataaccess," : "")); + "prodataaccess,"); } if (fout->remoteVersion >= 80400) @@ -14448,38 +14199,19 @@ dumpOpr(Archive *fout, const OprInfo *oprinfo) oprid = createPQExpBuffer(); details = createPQExpBuffer(); - if (fout->remoteVersion >= 80300) - { - appendPQExpBuffer(query, "SELECT oprkind, " - "oprcode::pg_catalog.regprocedure, " - "oprleft::pg_catalog.regtype, " - "oprright::pg_catalog.regtype, " - "oprcom, " - "oprnegate, " - "oprrest::pg_catalog.regprocedure, " - "oprjoin::pg_catalog.regprocedure, " - "oprcanmerge, oprcanhash " - "FROM pg_catalog.pg_operator " - "WHERE oid = '%u'::pg_catalog.oid", - oprinfo->dobj.catId.oid); - } - else - { - error_unsupported_server_version(fout); - appendPQExpBuffer(query, "SELECT oprkind, " - "oprcode::pg_catalog.regprocedure, " - "oprleft::pg_catalog.regtype, " - "oprright::pg_catalog.regtype, " - "oprcom, " - "oprnegate, " - "oprrest::pg_catalog.regprocedure, " - "oprjoin::pg_catalog.regprocedure, " - "(oprlsortop != 0) AS oprcanmerge, " - "oprcanhash " - "FROM pg_catalog.pg_operator " - "WHERE oid = '%u'::pg_catalog.oid", - oprinfo->dobj.catId.oid); - } + + appendPQExpBuffer(query, "SELECT oprkind, " + "oprcode::pg_catalog.regprocedure, " + "oprleft::pg_catalog.regtype, " + "oprright::pg_catalog.regtype, " + "oprcom, " + "oprnegate, " + "oprrest::pg_catalog.regprocedure, " + "oprjoin::pg_catalog.regprocedure, " + "oprcanmerge, oprcanhash " + "FROM pg_catalog.pg_operator " + "WHERE oid = '%u'::pg_catalog.oid", + oprinfo->dobj.catId.oid); res = ExecuteSqlQueryForSingleRow(fout, query->data); @@ -15774,13 +15506,6 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) if (fout->remoteVersion >= 80100) appendPQExpBufferStr(query, "aggsortop,\n"); - else - { - /* GPDB can't be here */ - error_unsupported_server_version(fout); - appendPQExpBufferStr(query, - "0 AS aggsortop,\n"); - } if (fout->remoteVersion >= 80400) appendPQExpBufferStr(query, @@ -17564,7 +17289,6 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer bool isweb = false; bool iswritable = false; char *options; - bool gpdb5OrLater = isGPDB5000OrLater(fout); bool gpdb6OrLater = isGPDB6000OrLater(fout); char *logerrors = NULL; char *on_clause; @@ -17598,7 +17322,7 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer "FROM pg_catalog.pg_exttable x, pg_catalog.pg_class c " "WHERE x.reloid = c.oid AND c.oid = '%u'::oid ", tbinfo->dobj.catId.oid); } - else if (gpdb5OrLater) + else { appendPQExpBuffer(query, "SELECT x.urilocation, x.execlocation, x.fmttype, x.fmtopts, x.command, " @@ -17615,62 +17339,6 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer "FROM pg_catalog.pg_exttable x, pg_catalog.pg_class c " "WHERE x.reloid = c.oid AND c.oid = '%u'::oid ", tbinfo->dobj.catId.oid); } - else if (fout->remoteVersion >= 80214) - { - appendPQExpBuffer(query, - "SELECT x.location, " - "CASE WHEN x.command <> '' THEN x.location " - "ELSE '{ALL_SEGMENTS}' " - "END AS execlocation, " - "x.fmttype, x.fmtopts, x.command, " - "x.rejectlimit, x.rejectlimittype, " - "d.relname AS logerrors, " - "pg_catalog.pg_encoding_to_char(x.encoding), " - "x.writable, null AS options " - "FROM pg_catalog.pg_class c " - "JOIN pg_catalog.pg_exttable x ON ( c.oid = x.reloid ) " - "LEFT JOIN pg_catalog.pg_class d ON ( d.oid = x.fmterrtbl ) " - "LEFT JOIN pg_catalog.pg_namespace n ON ( n.oid = d.relnamespace ) " - "WHERE c.oid = '%u'::oid ", - tbinfo->dobj.catId.oid); - } - else if (fout->remoteVersion >= 80205) - { - - appendPQExpBuffer(query, - "SELECT x.location, " - "CASE WHEN x.command <> '' THEN x.location " - "ELSE '{ALL_SEGMENTS}' " - "END AS execlocation, " - "x.fmttype, x.fmtopts, x.command, " - "x.rejectlimit, x.rejectlimittype, " - "d.relname AS logerrors, " - "pg_catalog.pg_encoding_to_char(x.encoding), " - "null as writable, null as options " - "FROM pg_catalog.pg_class c " - "JOIN pg_catalog.pg_exttable x ON ( c.oid = x.reloid ) " - "LEFT JOIN pg_catalog.pg_class d ON ( d.oid = x.fmterrtbl ) " - "LEFT JOIN pg_catalog.pg_namespace n ON ( n.oid = d.relnamespace ) " - "WHERE c.oid = '%u'::oid ", - tbinfo->dobj.catId.oid); - } - else - { - /* not SREH and encoding columns yet */ - appendPQExpBuffer(query, - "SELECT x.location, " - "CASE WHEN x.command <> '' THEN x.location " - "ELSE '{ALL_SEGMENTS}' " - "END AS execlocation, " - "x.fmttype, x.fmtopts, x.command, " - "-1 as rejectlimit, null as rejectlimittype," - "null as logerrors, " - "null as encoding, null as writable, " - "null as options " - "FROM pg_catalog.pg_exttable x, pg_catalog.pg_class c " - "WHERE x.reloid = c.oid AND c.oid = '%u'::oid", - tbinfo->dobj.catId.oid); - } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -17867,36 +17535,33 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer appendPQExpBuffer(q, "OPTIONS (\n %s\n )\n", options); } - if (fout->remoteVersion >= 80205) + /* add ENCODING clause */ + appendPQExpBuffer(q, "ENCODING '%s'", extencoding); + + /* add Single Row Error Handling clause (if any) */ + if (rejlim && strlen(rejlim) > 0) { - /* add ENCODING clause */ - appendPQExpBuffer(q, "ENCODING '%s'", extencoding); + appendPQExpBufferChar(q, '\n'); - /* add Single Row Error Handling clause (if any) */ - if (rejlim && strlen(rejlim) > 0) + /* + * Error tables were removed and replaced with file error + * logging. + */ + if (logerrors && strlen(logerrors) > 0) { - appendPQExpBufferChar(q, '\n'); - - /* - * Error tables were removed and replaced with file error - * logging. - */ - if (logerrors && strlen(logerrors) > 0) - { - appendPQExpBufferStr(q, "LOG ERRORS "); - if (logerrors[0] == 'p' && strlen(logerrors) == 1) - appendPQExpBufferStr(q, "PERSISTENTLY "); - } + appendPQExpBufferStr(q, "LOG ERRORS "); + if (logerrors[0] == 'p' && strlen(logerrors) == 1) + appendPQExpBufferStr(q, "PERSISTENTLY "); + } - /* reject limit */ - appendPQExpBuffer(q, "SEGMENT REJECT LIMIT %s", rejlim); + /* reject limit */ + appendPQExpBuffer(q, "SEGMENT REJECT LIMIT %s", rejlim); - /* reject limit type */ - if (rejlimtype[0] == 'r') - appendPQExpBufferStr(q, " ROWS"); - else - appendPQExpBufferStr(q, " PERCENT"); - } + /* reject limit type */ + if (rejlimtype[0] == 'r') + appendPQExpBufferStr(q, " ROWS"); + else + appendPQExpBufferStr(q, " PERCENT"); } /* DISTRIBUTED BY clause (if WRITABLE table) */ @@ -21442,53 +21107,6 @@ testPartitioningSupport(Archive *fout) return isSupported; } - - -/* - * testAttributeEncodingSupport - tests whether or not the current GP - * database includes support for column encoding. - */ -static bool -testAttributeEncodingSupport(Archive *fout) -{ - PQExpBuffer query; - PGresult *res; - bool isSupported; - - query = createPQExpBuffer(); - - appendPQExpBuffer(query, "SELECT 1 from pg_catalog.pg_class where relnamespace = 11 and relname = 'pg_attribute_encoding';"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - - isSupported = (PQntuples(res) == 1); - - PQclear(res); - destroyPQExpBuffer(query); - - return isSupported; -} - - -bool -testExtProtocolSupport(Archive *fout) -{ - PQExpBuffer query; - PGresult *res; - bool isSupported; - - query = createPQExpBuffer(); - - appendPQExpBuffer(query, "SELECT 1 FROM pg_class WHERE relname = 'pg_extprotocol' and relnamespace = 11;"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - - isSupported = (PQntuples(res) == 1); - - PQclear(res); - destroyPQExpBuffer(query); - - return isSupported; -} - /* * addSchedule * diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 54b857e267..73310951b5 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -64,8 +64,6 @@ static void executeCommand(PGconn *conn, const char *query); static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names); -static void error_unsupported_server_version(PGconn *conn) pg_attribute_noreturn(); - static char pg_dump_bin[MAXPGPATH]; static const char *progname; static PQExpBuffer pgdumpopts; @@ -925,22 +923,15 @@ dumpResQueues(PGconn *conn) "3 as ord FROM pg_resqueue " "UNION " "SELECT oid, rsqname, 'ignorecostlimit' as resname, " - "%s as ressetting, " + "rsqignorecostlimit::text as ressetting, " "4 as ord FROM pg_resqueue " - "%s" - "order by rsqname, ord", - (server_version >= 80205 ? - "rsqignorecostlimit::text" - : "0 AS"), - (server_version >= 80214 ? - "UNION " - "SELECT rq.oid, rq.rsqname, rt.resname, rc.ressetting, " - "rt.restypid as ord FROM " - "pg_resqueue rq, pg_resourcetype rt, " - "pg_resqueuecapability rc WHERE " - "rq.oid=rc.resqueueid and rc.restypid = rt.restypid " - : "") - ); + "UNION " + "SELECT rq.oid, rq.rsqname, rt.resname, rc.ressetting, " + "rt.restypid as ord FROM " + "pg_resqueue rq, pg_resourcetype rt, " + "pg_resqueuecapability rc WHERE " + "rq.oid=rc.resqueueid and rc.restypid = rt.restypid " + "order by rsqname, ord"); res = executeQuery(conn, buf->data); @@ -1237,7 +1228,7 @@ dumpRoles(PGconn *conn) " %s %s %s %s" "FROM %s " "ORDER BY 2", role_catalog, resq_col, resgroup_col, extauth_col, hdfs_col, role_catalog); - else if (server_version >= 80200) + else printfPQExpBuffer(buf, "SELECT oid, rolname, rolsuper, rolinherit, " "rolcreaterole, rolcreatedb, rolcatupdate, " @@ -1249,51 +1240,6 @@ dumpRoles(PGconn *conn) " %s %s %s %s" "FROM %s " "ORDER BY 2", role_catalog, resq_col, resgroup_col, extauth_col, hdfs_col, role_catalog); - else if (server_version >= 80100) - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, false as rolreplication, " - "false as rolbypassrls, " - "null as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "ORDER BY 2", role_catalog); - else - printfPQExpBuffer(buf, - "SELECT 0 as oid, usename as rolname, " - "usesuper as rolsuper, " - "true as rolinherit, " - "usesuper as rolcreaterole, " - "usecreatedb as rolcreatedb, " - "true as rolcanlogin, " - "-1 as rolconnlimit, " - "passwd as rolpassword, " - "valuntil as rolvaliduntil, " - "false as rolreplication, " - "false as rolbypassrls, " - "null as rolcomment, " - "usename = current_user AS is_current_user " - "FROM pg_shadow " - "UNION ALL " - "SELECT 0 as oid, groname as rolname, " - "false as rolsuper, " - "true as rolinherit, " - "false as rolcreaterole, " - "false as rolcreatedb, " - "false as rolcanlogin, " - "-1 as rolconnlimit, " - "null::text as rolpassword, " - "null::timestamptz as rolvaliduntil, " - "false as rolreplication, " - "false as rolbypassrls, " - "null as rolcomment, " - "false AS is_current_user " - "FROM pg_group " - "WHERE NOT EXISTS (SELECT 1 FROM pg_shadow " - " WHERE usename = groname) " - "ORDER BY 2"); res = executeQuery(conn, buf->data); @@ -1701,11 +1647,6 @@ dumpTablespaces(PGconn *conn) * Note that we do not support initial privileges (pg_init_privs) on * tablespaces, so this logic cannot make use of buildACLQueries(). */ - if (server_version < 80214) - { - /* Filespaces were introduced in GP 4.0 (server_version 8.2.14) */ - return; - } if (server_version >= 140000) { @@ -1788,7 +1729,7 @@ dumpTablespaces(PGconn *conn) "FROM pg_catalog.pg_tablespace " "WHERE spcname !~ '^pg_' " "ORDER BY 1"); - else if (server_version >= 80200) + else res = executeQuery(conn, "SELECT oid, spcname, " "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " "spclocation, spcacl, '' as rspcacl, null, " @@ -1796,17 +1737,6 @@ dumpTablespaces(PGconn *conn) "FROM pg_catalog.pg_tablespace " "WHERE spcname !~ '^pg_' " "ORDER BY 1"); - else - { - error_unsupported_server_version(conn); - res = executeQuery(conn, "SELECT oid, spcname, " - "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " - "spclocation, spcacl, '' as rspcacl, " - "null, null, null " - "FROM pg_catalog.pg_tablespace " - "WHERE spcname !~ '^pg_' " - "ORDER BY 1"); - } if (PQntuples(res) > 0) fprintf(OPF, "--\n-- Tablespaces\n--\n\n"); @@ -2722,11 +2652,11 @@ connectDatabase(const char *dbname, const char *connection_string, my_version = PG_VERSION_NUM; /* - * We allow the server to be back to 8.0, and up to any minor release of + * 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_dump.c.) */ if (my_version != server_version - && (server_version < 80200 || /* we can handle back to 8.2 */ + && (server_version < 80300 || /* we can handle back to 8.3 */ (server_version / 100) > (my_version / 100))) { pg_log_error("server version: %s; %s version: %s", @@ -2837,27 +2767,3 @@ dumpTimestamp(const char *msg) if (strftime(buf, sizeof(buf), PGDUMP_STRFTIME_FMT, localtime(&now)) != 0) fprintf(OPF, "-- %s %s\n\n", msg, buf); } - -/* - * This GPDB-specific function is copied (in spirit) from pg_dump.c. - * - * PostgreSQL's pg_dumpall supports very old server versions, but in GPDB, we - * only need to go back to 8.2-derived GPDB versions (4.something?). A lot of - * that code to deal with old versions has been removed. But in order to not - * change the formatting of the surrounding code, and to make it more clear - * when reading a diff against the corresponding PostgreSQL version of - * pg_dumpall, calls to this function has been left in place of the removed - * code. - * - * This function should never actually be used, because check that the server - * version is new enough at the beginning of pg_dumpall. This is just for - * documentation purposes, to show were upstream code has been removed, and - * to avoid those diffs or merge conflicts with upstream. - */ -static void -error_unsupported_server_version(PGconn *conn) -{ - fprintf(stderr, _("unexpected server version %d\n"), server_version); - PQfinish(conn); - exit(1); -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
