]> granicus.if.org Git - postgresql/commitdiff
Fix pg_dump's handling of event triggers.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Jul 2017 00:20:09 +0000 (20:20 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Jul 2017 00:20:09 +0000 (20:20 -0400)
pg_dump with the --clean option failed to emit DROP EVENT TRIGGER
commands for event triggers.  In a closely related oversight,
it also did not emit ALTER OWNER commands for event triggers.
Since only superusers can create event triggers, the latter oversight
is of little practical consequence ... but if we're going to record
an owner for event triggers, then surely pg_dump should preserve it.

Per complaint from Greg Atkins.  Back-patch to 9.3 where event triggers
were introduced.

Discussion: https://postgr.es/m/20170722191142.yi4e7tzcg3iacclg@gmail.com

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/t/002_pg_dump.pl

index 6483563f3d7a3eb87a0e6e301d9441e6ee7c9d77..f2b544871ebc3d650bb39ed404fddc4048f93c8a 100644 (file)
@@ -3267,6 +3267,7 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
                strcmp(type, "DATABASE") == 0 ||
                strcmp(type, "PROCEDURAL LANGUAGE") == 0 ||
                strcmp(type, "SCHEMA") == 0 ||
+               strcmp(type, "EVENT TRIGGER") == 0 ||
                strcmp(type, "FOREIGN DATA WRAPPER") == 0 ||
                strcmp(type, "SERVER") == 0 ||
                strcmp(type, "USER MAPPING") == 0)
@@ -3311,7 +3312,7 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
                return;
        }
 
-       write_msg(modulename, "WARNING: don't know how to set owner for object type %s\n",
+       write_msg(modulename, "WARNING: don't know how to set owner for object type \"%s\"\n",
                          type);
 }
 
@@ -3470,6 +3471,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData, bool acl_pass)
                        strcmp(te->desc, "OPERATOR FAMILY") == 0 ||
                        strcmp(te->desc, "PROCEDURAL LANGUAGE") == 0 ||
                        strcmp(te->desc, "SCHEMA") == 0 ||
+                       strcmp(te->desc, "EVENT TRIGGER") == 0 ||
                        strcmp(te->desc, "TABLE") == 0 ||
                        strcmp(te->desc, "TYPE") == 0 ||
                        strcmp(te->desc, "VIEW") == 0 ||
@@ -3505,7 +3507,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData, bool acl_pass)
                }
                else
                {
-                       write_msg(modulename, "WARNING: don't know how to set owner for object type %s\n",
+                       write_msg(modulename, "WARNING: don't know how to set owner for object type \"%s\"\n",
                                          te->desc);
                }
        }
index d1db3702beaff1b93e86af590f7019b924de5e6c..479fd89e17b7a58d0050bb88f9fed09852c6802f 100644 (file)
@@ -16978,6 +16978,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
 {
        DumpOptions *dopt = fout->dopt;
        PQExpBuffer query;
+       PQExpBuffer delqry;
        PQExpBuffer labelq;
 
        /* Skip if not to be dumped */
@@ -16985,6 +16986,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
                return;
 
        query = createPQExpBuffer();
+       delqry = createPQExpBuffer();
        labelq = createPQExpBuffer();
 
        appendPQExpBufferStr(query, "CREATE EVENT TRIGGER ");
@@ -17024,14 +17026,21 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
                }
                appendPQExpBufferStr(query, ";\n");
        }
+
+       appendPQExpBuffer(delqry, "DROP EVENT TRIGGER %s;\n",
+                                         fmtId(evtinfo->dobj.name));
+
        appendPQExpBuffer(labelq, "EVENT TRIGGER %s",
                                          fmtId(evtinfo->dobj.name));
 
        if (evtinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
                ArchiveEntry(fout, evtinfo->dobj.catId, evtinfo->dobj.dumpId,
-                                        evtinfo->dobj.name, NULL, NULL, evtinfo->evtowner, false,
+                                        evtinfo->dobj.name, NULL, NULL,
+                                        evtinfo->evtowner, false,
                                         "EVENT TRIGGER", SECTION_POST_DATA,
-                                        query->data, "", NULL, NULL, 0, NULL, NULL);
+                                        query->data, delqry->data, NULL,
+                                        NULL, 0,
+                                        NULL, NULL);
 
        if (evtinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
                dumpComment(fout, labelq->data,
@@ -17039,6 +17048,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
                                        evtinfo->dobj.catId, 0, evtinfo->dobj.dumpId);
 
        destroyPQExpBuffer(query);
+       destroyPQExpBuffer(delqry);
        destroyPQExpBuffer(labelq);
 }
 
index 1f8db16cf166aedf62b5baaec4a49a1cb47b3760..d5bfbc797c5fd5d36bd2a8ca62d17778ea4127f5 100644 (file)
@@ -516,18 +516,19 @@ my %tests = (
                        only_dump_test_table   => 1,
                        test_schema_plus_blobs => 1, }, },
 
-       # catch-all for ALTER ... OWNER (except LARGE OBJECTs)
-       'ALTER ... OWNER commands (except LARGE OBJECTs)' => {
-               regexp => qr/^ALTER (?!LARGE OBJECT)(.*) OWNER TO .*;/m,
+       # catch-all for ALTER ... OWNER (except post-data objects)
+       'ALTER ... OWNER commands (except post-data objects)' => {
+               regexp => qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT)(.*) OWNER TO .*;/m,
                like   => {},    # use more-specific options above
                unlike => {
                        column_inserts => 1,
                        data_only      => 1,
-                       section_data   => 1, }, },
+                       section_data   => 1,
+                       section_post_data => 1, }, },
 
-       # catch-all for ALTER TABLE ...
+       # catch-all for ALTER TABLE ... (except OWNER TO)
        'ALTER TABLE ... commands' => {
-               regexp => qr/^ALTER TABLE .*;/m,
+               regexp => qr/^ALTER TABLE .* (?!OWNER TO)(.*);/m,
                like   => {},                      # use more-specific options above
                unlike => {
                        column_inserts           => 1,
@@ -543,8 +544,7 @@ my %tests = (
                unlike => {
                        no_owner                 => 1,
                        pg_dumpall_globals       => 1,
-                       pg_dumpall_globals_clean => 1,
-                       section_post_data        => 1, }, },
+                       pg_dumpall_globals_clean => 1, }, },
 
        #       'BLOB load (contents are of test_table)' => {
        #               create_order => 14,