pg_dump only selected components of ACCESS METHODs
authorStephen Frost <sfrost@snowman.net>
Tue, 7 Jun 2016 13:56:02 +0000 (09:56 -0400)
committerStephen Frost <sfrost@snowman.net>
Tue, 7 Jun 2016 13:56:02 +0000 (09:56 -0400)
dumpAccessMethod() didn't get the memo that we now have a bitfield for
the components which should be dumped instead of a simple boolean.

Correct that by checking if the relevant bit is set for each component
being dumped out (and not dumping it out if it isn't set).

This corrects an issue where CREATE ACCESS METHOD commands were being
included in non-binary-upgrades when an extension included an access
method (as the bloom extensions does).

Also add a regression test to make sure that we only dump out the
ACCESS METHOD commands, when they are part of an extension, when doing
a binary upgrade.

Pointed out by Thom Brown.

src/bin/pg_dump/pg_dump.c
src/test/modules/test_pg_dump/t/001_base.pl
src/test/modules/test_pg_dump/test_pg_dump--1.0.sql

index 296273ba4abfcc0110caf10b604a4da9df911dee..89cf0274ed26a77f2ca7609b28fac1d8371b0e16 100644 (file)
@@ -12472,20 +12472,22 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo)
        appendPQExpBuffer(labelq, "ACCESS METHOD %s",
                                          qamname);
 
-       ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
-                                aminfo->dobj.name,
-                                NULL,
-                                NULL,
-                                "",
-                                false, "ACCESS METHOD", SECTION_PRE_DATA,
-                                q->data, delq->data, NULL,
-                                NULL, 0,
-                                NULL, NULL);
+       if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
+               ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
+                                        aminfo->dobj.name,
+                                        NULL,
+                                        NULL,
+                                        "",
+                                        false, "ACCESS METHOD", SECTION_PRE_DATA,
+                                        q->data, delq->data, NULL,
+                                        NULL, 0,
+                                        NULL, NULL);
 
        /* Dump Access Method Comments */
-       dumpComment(fout, labelq->data,
-                               NULL, "",
-                               aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
+       if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
+               dumpComment(fout, labelq->data,
+                                       NULL, "",
+                                       aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
 
        pg_free(qamname);
 
index 2177df8bba443c1355dfde2546cf9f8a367e63f9..626eb4b758f5d2ab68375ec75ef6e06da0e2a1ba 100644 (file)
@@ -317,6 +317,26 @@ my %tests = (
                        section_post_data => 1,
                },
        },
+       'CREATE ACCESS METHOD regress_test_am' => {
+               regexp => qr/^
+                       \QCREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;\E
+                       $/xm,
+               like => {
+                       binary_upgrade => 1,
+               },
+               unlike => {
+                       clean => 1,
+                       clean_if_exists => 1,
+                       createdb => 1,
+                       defaults => 1,
+                       no_privs => 1,
+                       no_owner => 1,
+                       pg_dumpall_globals => 1,
+                       schema_only => 1,
+                       section_pre_data => 1,
+                       section_post_data => 1,
+               },
+       },
        'COMMENT ON EXTENSION test_pg_dump' => {
                regexp => qr/^
                        \QCOMMENT ON EXTENSION test_pg_dump \E
index d1ec58d023f06065b15752c6a24e78518ea4b96a..e2bcd480e0850cf1089c6922a1775182b3fddf8e 100644 (file)
@@ -13,3 +13,5 @@ GRANT SELECT(col1) ON regress_pg_dump_table TO public;
 
 GRANT SELECT(col2) ON regress_pg_dump_table TO dump_test;
 REVOKE SELECT(col2) ON regress_pg_dump_table FROM dump_test;
+
+CREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;