Skip to content

Commit db9b4b7

Browse files
committed
Repair incorrect pg_dump labeling for some comments and security labels.
We attached no schema label to comments for procedural languages, casts, transforms, operator classes, operator families, or text search objects. The first three categories of objects don't really have schemas, but pg_dump treats them as if they do, and it seems like the TocEntry fields for their comments had better match the TocEntry fields for the parent objects. (As an example of a possible hazard, the type names in a CAST will be formatted with the assumption of a particular search_path, so failing to ensure that this same path is active for the COMMENT ON command could lead to an error or to attaching the comment to the wrong cast.) In the last six cases, this was a flat-out error --- possibly mine to begin with, but it was a long time ago. The security label for a procedural language was likewise not correctly labeled as to schema, and both the comment and security label for a procedural language were not correctly labeled as to owner. In simple cases the restore would accidentally work correctly anyway, since these comments and security labels would normally get emitted right after the owning object, and so the search path and active user would be correct anyhow. But it could fail in corner cases; for example a schema-selective restore would omit comments it should include. Giuseppe Broccolo noted the oversight, and proposed the correct fix, for text search dictionary objects; I found the rest by cross-checking other dumpComment() calls. These oversights are ancient, so back-patch all the way. Discussion: https://postgr.es/m/CAFzmHiWwwzLjzwM4x5ki5s_PDMR6NrkipZkjNnO3B0xEpBgJaA@mail.gmail.com
1 parent 9359889 commit db9b4b7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9682,10 +9682,10 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
96829682

96839683
/* Dump Proc Lang Comments and Security Labels */
96849684
dumpComment(fout, labelq->data,
9685-
NULL, "",
9685+
lanschema, plang->lanowner,
96869686
plang->dobj.catId, 0, plang->dobj.dumpId);
96879687
dumpSecLabel(fout, labelq->data,
9688-
NULL, "",
9688+
lanschema, plang->lanowner,
96899689
plang->dobj.catId, 0, plang->dobj.dumpId);
96909690

96919691
if (plang->lanpltrusted)
@@ -10399,7 +10399,7 @@ dumpCast(Archive *fout, CastInfo *cast)
1039910399

1040010400
/* Dump Cast Comments */
1040110401
dumpComment(fout, labelq->data,
10402-
NULL, "",
10402+
"pg_catalog", "",
1040310403
cast->dobj.catId, 0, cast->dobj.dumpId);
1040410404

1040510405
destroyPQExpBuffer(defqry);
@@ -11157,7 +11157,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1115711157

1115811158
/* Dump Operator Class Comments */
1115911159
dumpComment(fout, labelq->data,
11160-
NULL, opcinfo->rolname,
11160+
opcinfo->dobj.namespace->dobj.name, opcinfo->rolname,
1116111161
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
1116211162

1116311163
free(amname);
@@ -11427,7 +11427,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1142711427

1142811428
/* Dump Operator Family Comments */
1142911429
dumpComment(fout, labelq->data,
11430-
NULL, opfinfo->rolname,
11430+
opfinfo->dobj.namespace->dobj.name, opfinfo->rolname,
1143111431
opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
1143211432

1143311433
free(amname);
@@ -12111,7 +12111,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
1211112111

1211212112
/* Dump Parser Comments */
1211312113
dumpComment(fout, labelq->data,
12114-
NULL, "",
12114+
prsinfo->dobj.namespace->dobj.name, "",
1211512115
prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
1211612116

1211712117
destroyPQExpBuffer(q);
@@ -12198,7 +12198,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
1219812198

1219912199
/* Dump Dictionary Comments */
1220012200
dumpComment(fout, labelq->data,
12201-
NULL, dictinfo->rolname,
12201+
dictinfo->dobj.namespace->dobj.name, dictinfo->rolname,
1220212202
dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
1220312203

1220412204
destroyPQExpBuffer(q);
@@ -12264,7 +12264,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
1226412264

1226512265
/* Dump Template Comments */
1226612266
dumpComment(fout, labelq->data,
12267-
NULL, "",
12267+
tmplinfo->dobj.namespace->dobj.name, "",
1226812268
tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
1226912269

1227012270
destroyPQExpBuffer(q);
@@ -12392,7 +12392,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
1239212392

1239312393
/* Dump Configuration Comments */
1239412394
dumpComment(fout, labelq->data,
12395-
NULL, cfginfo->rolname,
12395+
cfginfo->dobj.namespace->dobj.name, cfginfo->rolname,
1239612396
cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
1239712397

1239812398
destroyPQExpBuffer(q);

0 commit comments

Comments
 (0)