@@ -96,6 +96,12 @@ bool g_verbose; /* User wants verbose narration of our
96
96
/* subquery used to convert user ID (eg, datdba) to user name */
97
97
static const char *username_subquery;
98
98
99
+ /*
100
+ * For 8.0 and earlier servers, pulled from pg_database, for 8.1+ we use
101
+ * FirstNormalObjectId - 1.
102
+ */
103
+ static Oid g_last_builtin_oid; /* value of the last builtin oid */
104
+
99
105
/* The specified names/patterns should to match at least one entity */
100
106
static int strict_names = 0;
101
107
@@ -233,6 +239,7 @@ static char *convertRegProcReference(Archive *fout,
233
239
const char *proc);
234
240
static char *convertOperatorReference(Archive *fout, const char *opr);
235
241
static char *convertTSFunction(Archive *fout, Oid funcOid);
242
+ static Oid findLastBuiltinOid_V71(Archive *fout, const char *);
236
243
static void selectSourceSchema(Archive *fout, const char *schemaName);
237
244
static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
238
245
static void getBlobs(Archive *fout);
@@ -684,6 +691,20 @@ main(int argc, char **argv)
684
691
exit_horribly(NULL,
685
692
"Exported snapshots are not supported by this server version.\n");
686
693
694
+ /*
695
+ * Find the last built-in OID, if needed (prior to 8.1)
696
+ *
697
+ * With 8.1 and above, we can just use FirstNormalObjectId - 1.
698
+ */
699
+ if (fout->remoteVersion < 80100)
700
+ g_last_builtin_oid = findLastBuiltinOid_V71(fout,
701
+ PQdb(GetConnection(fout)));
702
+ else
703
+ g_last_builtin_oid = FirstNormalObjectId - 1;
704
+
705
+ if (g_verbose)
706
+ write_msg(NULL, "last built-in OID is %u\n", g_last_builtin_oid);
707
+
687
708
/* Expand schema selection patterns into OID lists */
688
709
if (schema_include_patterns.head != NULL)
689
710
{
@@ -1494,7 +1515,7 @@ selectDumpableCast(CastInfo *cast, Archive *fout)
1494
1515
* This would be DUMP_COMPONENT_ACL for from-initdb casts, but they do not
1495
1516
* support ACLs currently.
1496
1517
*/
1497
- if (cast->dobj.catId.oid < (Oid) FirstNormalObjectId )
1518
+ if (cast->dobj.catId.oid <= (Oid) g_last_builtin_oid )
1498
1519
cast->dobj.dump = DUMP_COMPONENT_NONE;
1499
1520
else
1500
1521
cast->dobj.dump = fout->dopt->include_everything ?
@@ -1526,7 +1547,7 @@ selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
1526
1547
plang->dobj.dump = DUMP_COMPONENT_NONE;
1527
1548
else
1528
1549
{
1529
- if (plang->dobj.catId.oid < (Oid) FirstNormalObjectId )
1550
+ if (plang->dobj.catId.oid <= (Oid) g_last_builtin_oid )
1530
1551
plang->dobj.dump = fout->remoteVersion < 90600 ?
1531
1552
DUMP_COMPONENT_NONE : DUMP_COMPONENT_ACL;
1532
1553
else
@@ -1552,7 +1573,7 @@ selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
1552
1573
* This would be DUMP_COMPONENT_ACL for from-initdb access methods, but
1553
1574
* they do not support ACLs currently.
1554
1575
*/
1555
- if (method->dobj.catId.oid < (Oid) FirstNormalObjectId )
1576
+ if (method->dobj.catId.oid <= (Oid) g_last_builtin_oid )
1556
1577
method->dobj.dump = DUMP_COMPONENT_NONE;
1557
1578
else
1558
1579
method->dobj.dump = fout->dopt->include_everything ?
@@ -1577,7 +1598,7 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
1577
1598
* change permissions on those objects, if they wish to, and have those
1578
1599
* changes preserved.
1579
1600
*/
1580
- if (dopt->binary_upgrade && extinfo->dobj.catId.oid < (Oid) FirstNormalObjectId )
1601
+ if (dopt->binary_upgrade && extinfo->dobj.catId.oid <= (Oid) g_last_builtin_oid )
1581
1602
extinfo->dobj.dump = extinfo->dobj.dump_contains = DUMP_COMPONENT_ACL;
1582
1603
else
1583
1604
extinfo->dobj.dump = extinfo->dobj.dump_contains =
@@ -8820,8 +8841,8 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
8820
8841
/*
8821
8842
* We unconditionally create the extension, so we must drop it if it
8822
8843
* exists. This could happen if the user deleted 'plpgsql' and then
8823
- * readded it, causing its oid to be greater than FirstNormalObjectId .
8824
- * The FirstNormalObjectId test was kept to avoid repeatedly dropping
8844
+ * readded it, causing its oid to be greater than g_last_builtin_oid .
8845
+ * The g_last_builtin_oid test was kept to avoid repeatedly dropping
8825
8846
* and recreating extensions like 'plpgsql'.
8826
8847
*/
8827
8848
appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname);
@@ -15324,6 +15345,33 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
15324
15345
destroyPQExpBuffer(labelq);
15325
15346
}
15326
15347
15348
+ /*
15349
+ * findLastBuiltinOid_V71 -
15350
+ *
15351
+ * find the last built in oid
15352
+ *
15353
+ * For 7.1 through 8.0, we do this by retrieving datlastsysoid from the
15354
+ * pg_database entry for the current database.
15355
+ */
15356
+ static Oid
15357
+ findLastBuiltinOid_V71(Archive *fout, const char *dbname)
15358
+ {
15359
+ PGresult *res;
15360
+ Oid last_oid;
15361
+ PQExpBuffer query = createPQExpBuffer();
15362
+
15363
+ resetPQExpBuffer(query);
15364
+ appendPQExpBufferStr(query, "SELECT datlastsysoid from pg_database where datname = ");
15365
+ appendStringLiteralAH(query, dbname, fout);
15366
+
15367
+ res = ExecuteSqlQueryForSingleRow(fout, query->data);
15368
+ last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid")));
15369
+ PQclear(res);
15370
+ destroyPQExpBuffer(query);
15371
+
15372
+ return last_oid;
15373
+ }
15374
+
15327
15375
/*
15328
15376
* dumpSequence
15329
15377
* write the declaration (not data) of one user-defined sequence
0 commit comments