@@ -169,9 +169,15 @@ static NamespaceInfo *findNamespace(Oid nsoid);
169
169
static void dumpTableData(Archive *fout, const TableDataInfo *tdinfo);
170
170
static void refreshMatViewData(Archive *fout, const TableDataInfo *tdinfo);
171
171
static void guessConstraintInheritance(TableInfo *tblinfo, int numTables);
172
- static void dumpComment(Archive *fout, const char *type, const char *name,
173
- const char *namespace, const char *owner,
174
- CatalogId catalogId, int subid, DumpId dumpId);
172
+ static void dumpCommentExtended(Archive *fout, const char *type,
173
+ const char *name, const char *namespace,
174
+ const char *owner, CatalogId catalogId,
175
+ int subid, DumpId dumpId,
176
+ const char *initdb_comment);
177
+ static inline void dumpComment(Archive *fout, const char *type,
178
+ const char *name, const char *namespace,
179
+ const char *owner, CatalogId catalogId,
180
+ int subid, DumpId dumpId);
175
181
static int findComments(Archive *fout, Oid classoid, Oid objoid,
176
182
CommentItem **items);
177
183
static int collectComments(Archive *fout, CommentItem **items);
@@ -1638,16 +1644,13 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
1638
1644
{
1639
1645
/*
1640
1646
* The public schema is a strange beast that sits in a sort of
1641
- * no-mans-land between being a system object and a user object. We
1642
- * don't want to dump creation or comment commands for it, because
1643
- * that complicates matters for non-superuser use of pg_dump. But we
1644
- * should dump any ownership changes, security labels, and ACL
1645
- * changes, and of course we should dump contained objects. pg_dump
1646
- * ties ownership to DUMP_COMPONENT_DEFINITION. Hence, unless the
1647
- * owner is the default, dump a "definition" bearing just a comment.
1647
+ * no-mans-land between being a system object and a user object.
1648
+ * CREATE SCHEMA would fail, so its DUMP_COMPONENT_DEFINITION is just
1649
+ * a comment and an indication of ownership. If the owner is the
1650
+ * default, that DUMP_COMPONENT_DEFINITION is superfluous.
1648
1651
*/
1649
1652
nsinfo->create = false;
1650
- nsinfo->dobj.dump = DUMP_COMPONENT_ALL & ~DUMP_COMPONENT_COMMENT ;
1653
+ nsinfo->dobj.dump = DUMP_COMPONENT_ALL;
1651
1654
if (nsinfo->nspowner == BOOTSTRAP_SUPERUSERID)
1652
1655
nsinfo->dobj.dump &= ~DUMP_COMPONENT_DEFINITION;
1653
1656
nsinfo->dobj.dump_contains = DUMP_COMPONENT_ALL;
@@ -9873,7 +9876,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
9873
9876
}
9874
9877
9875
9878
/*
9876
- * dumpComment --
9879
+ * dumpCommentExtended --
9877
9880
*
9878
9881
* This routine is used to dump any comments associated with the
9879
9882
* object handed to this routine. The routine takes the object type
@@ -9896,9 +9899,11 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
9896
9899
* calling ArchiveEntry() for the specified object.
9897
9900
*/
9898
9901
static void
9899
- dumpComment(Archive *fout, const char *type, const char *name,
9900
- const char *namespace, const char *owner,
9901
- CatalogId catalogId, int subid, DumpId dumpId)
9902
+ dumpCommentExtended(Archive *fout, const char *type,
9903
+ const char *name, const char *namespace,
9904
+ const char *owner, CatalogId catalogId,
9905
+ int subid, DumpId dumpId,
9906
+ const char *initdb_comment)
9902
9907
{
9903
9908
DumpOptions *dopt = fout->dopt;
9904
9909
CommentItem *comments;
@@ -9934,6 +9939,25 @@ dumpComment(Archive *fout, const char *type, const char *name,
9934
9939
ncomments--;
9935
9940
}
9936
9941
9942
+ if (initdb_comment != NULL)
9943
+ {
9944
+ static CommentItem empty_comment = {.descr = ""};
9945
+
9946
+ /*
9947
+ * initdb creates this object with a comment. Skip dumping the
9948
+ * initdb-provided comment, which would complicate matters for
9949
+ * non-superuser use of pg_dump. When the DBA has removed initdb's
9950
+ * comment, replicate that.
9951
+ */
9952
+ if (ncomments == 0)
9953
+ {
9954
+ comments = &empty_comment;
9955
+ ncomments = 1;
9956
+ }
9957
+ else if (strcmp(comments->descr, initdb_comment) == 0)
9958
+ ncomments = 0;
9959
+ }
9960
+
9937
9961
/* If a comment exists, build COMMENT ON statement */
9938
9962
if (ncomments > 0)
9939
9963
{
@@ -9969,6 +9993,21 @@ dumpComment(Archive *fout, const char *type, const char *name,
9969
9993
}
9970
9994
}
9971
9995
9996
+ /*
9997
+ * dumpComment --
9998
+ *
9999
+ * Typical simplification of the above function.
10000
+ */
10001
+ static inline void
10002
+ dumpComment(Archive *fout, const char *type,
10003
+ const char *name, const char *namespace,
10004
+ const char *owner, CatalogId catalogId,
10005
+ int subid, DumpId dumpId)
10006
+ {
10007
+ dumpCommentExtended(fout, type, name, namespace, owner,
10008
+ catalogId, subid, dumpId, NULL);
10009
+ }
10010
+
9972
10011
/*
9973
10012
* dumpTableComment --
9974
10013
*
@@ -10426,9 +10465,18 @@ dumpNamespace(Archive *fout, const NamespaceInfo *nspinfo)
10426
10465
10427
10466
/* Dump Schema Comments and Security Labels */
10428
10467
if (nspinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10429
- dumpComment(fout, "SCHEMA", qnspname,
10430
- NULL, nspinfo->rolname,
10431
- nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId);
10468
+ {
10469
+ const char *initdb_comment = NULL;
10470
+
10471
+ if (!nspinfo->create && strcmp(qnspname, "public") == 0)
10472
+ initdb_comment = (fout->remoteVersion >= 80300 ?
10473
+ "standard public schema" :
10474
+ "Standard public schema");
10475
+ dumpCommentExtended(fout, "SCHEMA", qnspname,
10476
+ NULL, nspinfo->rolname,
10477
+ nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId,
10478
+ initdb_comment);
10479
+ }
10432
10480
10433
10481
if (nspinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10434
10482
dumpSecLabel(fout, "SCHEMA", qnspname,
0 commit comments