Repair incorrect pg_dump labeling for some comments and security labels.
authorTom Lane <[email protected]>
Tue, 7 Mar 2017 00:33:59 +0000 (19:33 -0500)
committerTom Lane <[email protected]>
Tue, 7 Mar 2017 00:33:59 +0000 (19:33 -0500)
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

src/bin/pg_dump/pg_dump.c

index 16f6c92d450fea641a374ec4d7b52f86ee0a5bf2..ac979a122bb5ab52b01d3ff60ddfc6751cff7dcb 100644 (file)
@@ -10189,10 +10189,10 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
 
        /* Dump Proc Lang Comments and Security Labels */
        dumpComment(fout, labelq->data,
-                               NULL, "",
+                               lanschema, plang->lanowner,
                                plang->dobj.catId, 0, plang->dobj.dumpId);
        dumpSecLabel(fout, labelq->data,
-                                NULL, "",
+                                lanschema, plang->lanowner,
                                 plang->dobj.catId, 0, plang->dobj.dumpId);
 
        if (plang->lanpltrusted)
@@ -10947,7 +10947,7 @@ dumpCast(Archive *fout, CastInfo *cast)
 
        /* Dump Cast Comments */
        dumpComment(fout, labelq->data,
-                               NULL, "",
+                               "pg_catalog", "",
                                cast->dobj.catId, 0, cast->dobj.dumpId);
 
        destroyPQExpBuffer(defqry);
@@ -11067,7 +11067,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
 
        /* Dump Transform Comments */
        dumpComment(fout, labelq->data,
-                               NULL, "",
+                               "pg_catalog", "",
                                transform->dobj.catId, 0, transform->dobj.dumpId);
 
        free(lanname);
@@ -11829,7 +11829,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
 
        /* Dump Operator Class Comments */
        dumpComment(fout, labelq->data,
-                               NULL, opcinfo->rolname,
+                               opcinfo->dobj.namespace->dobj.name, opcinfo->rolname,
                                opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
 
        free(amname);
@@ -12100,7 +12100,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
 
        /* Dump Operator Family Comments */
        dumpComment(fout, labelq->data,
-                               NULL, opfinfo->rolname,
+                               opfinfo->dobj.namespace->dobj.name, opfinfo->rolname,
                                opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
 
        free(amname);
@@ -12788,7 +12788,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
 
        /* Dump Parser Comments */
        dumpComment(fout, labelq->data,
-                               NULL, "",
+                               prsinfo->dobj.namespace->dobj.name, "",
                                prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
 
        destroyPQExpBuffer(q);
@@ -12876,7 +12876,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
 
        /* Dump Dictionary Comments */
        dumpComment(fout, labelq->data,
-                               NULL, dictinfo->rolname,
+                               dictinfo->dobj.namespace->dobj.name, dictinfo->rolname,
                                dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
 
        destroyPQExpBuffer(q);
@@ -12943,7 +12943,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
 
        /* Dump Template Comments */
        dumpComment(fout, labelq->data,
-                               NULL, "",
+                               tmplinfo->dobj.namespace->dobj.name, "",
                                tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
 
        destroyPQExpBuffer(q);
@@ -13072,7 +13072,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
 
        /* Dump Configuration Comments */
        dumpComment(fout, labelq->data,
-                               NULL, cfginfo->rolname,
+                               cfginfo->dobj.namespace->dobj.name, cfginfo->rolname,
                                cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
 
        destroyPQExpBuffer(q);