Skip to content

Commit b6882e9

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 6be8647 commit b6882e9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/bin/pg_dump/pg_dump.c

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

1019010190
/* Dump Proc Lang Comments and Security Labels */
1019110191
dumpComment(fout, labelq->data,
10192-
NULL, "",
10192+
lanschema, plang->lanowner,
1019310193
plang->dobj.catId, 0, plang->dobj.dumpId);
1019410194
dumpSecLabel(fout, labelq->data,
10195-
NULL, "",
10195+
lanschema, plang->lanowner,
1019610196
plang->dobj.catId, 0, plang->dobj.dumpId);
1019710197

1019810198
if (plang->lanpltrusted)
@@ -10947,7 +10947,7 @@ dumpCast(Archive *fout, CastInfo *cast)
1094710947

1094810948
/* Dump Cast Comments */
1094910949
dumpComment(fout, labelq->data,
10950-
NULL, "",
10950+
"pg_catalog", "",
1095110951
cast->dobj.catId, 0, cast->dobj.dumpId);
1095210952

1095310953
destroyPQExpBuffer(defqry);
@@ -11067,7 +11067,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
1106711067

1106811068
/* Dump Transform Comments */
1106911069
dumpComment(fout, labelq->data,
11070-
NULL, "",
11070+
"pg_catalog", "",
1107111071
transform->dobj.catId, 0, transform->dobj.dumpId);
1107211072

1107311073
free(lanname);
@@ -11829,7 +11829,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1182911829

1183011830
/* Dump Operator Class Comments */
1183111831
dumpComment(fout, labelq->data,
11832-
NULL, opcinfo->rolname,
11832+
opcinfo->dobj.namespace->dobj.name, opcinfo->rolname,
1183311833
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
1183411834

1183511835
free(amname);
@@ -12100,7 +12100,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1210012100

1210112101
/* Dump Operator Family Comments */
1210212102
dumpComment(fout, labelq->data,
12103-
NULL, opfinfo->rolname,
12103+
opfinfo->dobj.namespace->dobj.name, opfinfo->rolname,
1210412104
opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
1210512105

1210612106
free(amname);
@@ -12788,7 +12788,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
1278812788

1278912789
/* Dump Parser Comments */
1279012790
dumpComment(fout, labelq->data,
12791-
NULL, "",
12791+
prsinfo->dobj.namespace->dobj.name, "",
1279212792
prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
1279312793

1279412794
destroyPQExpBuffer(q);
@@ -12876,7 +12876,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
1287612876

1287712877
/* Dump Dictionary Comments */
1287812878
dumpComment(fout, labelq->data,
12879-
NULL, dictinfo->rolname,
12879+
dictinfo->dobj.namespace->dobj.name, dictinfo->rolname,
1288012880
dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
1288112881

1288212882
destroyPQExpBuffer(q);
@@ -12943,7 +12943,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
1294312943

1294412944
/* Dump Template Comments */
1294512945
dumpComment(fout, labelq->data,
12946-
NULL, "",
12946+
tmplinfo->dobj.namespace->dobj.name, "",
1294712947
tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
1294812948

1294912949
destroyPQExpBuffer(q);
@@ -13072,7 +13072,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
1307213072

1307313073
/* Dump Configuration Comments */
1307413074
dumpComment(fout, labelq->data,
13075-
NULL, cfginfo->rolname,
13075+
cfginfo->dobj.namespace->dobj.name, cfginfo->rolname,
1307613076
cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
1307713077

1307813078
destroyPQExpBuffer(q);

0 commit comments

Comments
 (0)