pg_dump: Only dump publications when dumping everything
authorPeter Eisentraut
Wed, 22 Mar 2017 03:19:09 +0000 (23:19 -0400)
committerPeter Eisentraut
Wed, 22 Mar 2017 03:34:40 +0000 (23:34 -0400)
Don't dump publications with pg_dump -t or similar cases that select
specific groups of objects.

Author: Petr Jelinek 

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

index e67171dccbf050a4a356a58a8b904e90e24acdc6..52fa6f33e3d1fb570c192e2d584394bfdab9545a 100644 (file)
@@ -1621,6 +1621,23 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
            DUMP_COMPONENT_NONE;
 }
 
+/*
+ * selectDumpablePublicationTable: policy-setting subroutine
+ *     Mark a publication table as to be dumped or not
+ *
+ * Publication tables have schemas, but those are ignored in decision making,
+ * because publications are only dumped when we are dumping everything.
+ */
+static void
+selectDumpablePublicationTable(DumpableObject *dobj, Archive *fout)
+{
+   if (checkExtensionMembership(dobj, fout))
+       return;                 /* extension membership overrides all else */
+
+   dobj->dump = fout->dopt->include_everything ?
+       DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
+}
+
 /*
  * selectDumpableObject: policy-setting subroutine
  *     Mark a generic dumpable object as to be dumped or not
@@ -3414,6 +3431,9 @@ getPublications(Archive *fout)
        if (strlen(pubinfo[i].rolname) == 0)
            write_msg(NULL, "WARNING: owner of publication \"%s\" appears to be invalid\n",
                      pubinfo[i].dobj.name);
+
+       /* Decide whether we want to dump it */
+       selectDumpableObject(&(pubinfo[i].dobj), fout);
    }
    PQclear(res);
 
@@ -3427,11 +3447,10 @@ getPublications(Archive *fout)
 static void
 dumpPublication(Archive *fout, PublicationInfo *pubinfo)
 {
-   DumpOptions *dopt = fout->dopt;
    PQExpBuffer delq;
    PQExpBuffer query;
 
-   if (dopt->dataOnly)
+   if (!(pubinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
        return;
 
    delq = createPQExpBuffer();
@@ -3560,6 +3579,9 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
            pubrinfo[j].dobj.name = tbinfo->dobj.name;
            pubrinfo[j].pubname = pg_strdup(PQgetvalue(res, j, i_pubname));
            pubrinfo[j].pubtable = tbinfo;
+
+           /* Decide whether we want to dump it */
+           selectDumpablePublicationTable(&(pubrinfo[j].dobj), fout);
        }
        PQclear(res);
    }
@@ -3573,12 +3595,11 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
 static void
 dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
 {
-   DumpOptions *dopt = fout->dopt;
    TableInfo  *tbinfo = pubrinfo->pubtable;
    PQExpBuffer query;
    char       *tag;
 
-   if (dopt->dataOnly)
+   if (!(pubrinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
        return;
 
    tag = psprintf("%s %s", pubrinfo->pubname, tbinfo->dobj.name);
index a4e260a4e48d509f342650d943ac68086a9cc7dc..a46dcdbcd7d94566f0cfe2bb124404df365f7989 100644 (file)
@@ -653,22 +653,22 @@ my %tests = (
            exclude_test_table_data  => 1,
            no_privs                 => 1,
            no_blobs                 => 1,
-           only_dump_test_schema    => 1, # XXX Should be unlike
-           only_dump_test_table     => 1, # XXX Should be unlike
            pg_dumpall_dbprivs       => 1,
-           role                     => 1, # XXX Should be unlike
            schema_only              => 1,
            section_post_data        => 1,
-           test_schema_plus_blobs   => 1, # XXX Should be unlike
            with_oids                => 1, },
        unlike => {
            column_inserts           => 1,
            data_only                => 1,
            no_owner                 => 1,
+           only_dump_test_schema    => 1,
+           only_dump_test_table     => 1,
            pg_dumpall_globals       => 1,
            pg_dumpall_globals_clean => 1,
+           role                     => 1,
            section_pre_data         => 1,
-           section_data             => 1, }, },
+           section_data             => 1,
+           test_schema_plus_blobs   => 1, }, },
 
    'ALTER LARGE OBJECT ... OWNER TO' => {
        all_runs => 1,
@@ -4168,19 +4168,18 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog
            no_blobs                 => 1,
            no_privs                 => 1,
            no_owner                 => 1,
-           only_dump_test_schema    => 1, # XXX Should be unlike
-           only_dump_test_table     => 1, # XXX Should be unlike
            pg_dumpall_dbprivs       => 1,
-           role                     => 1, # XXX Should be unlike
            schema_only              => 1,
            section_post_data        => 1,
-           test_schema_plus_blobs   => 1, # XXX Should be unlike
            with_oids                => 1, },
        unlike => {
-           section_pre_data         => 1,
+           only_dump_test_schema    => 1,
+           only_dump_test_table     => 1,
            pg_dumpall_globals       => 1,
            pg_dumpall_globals_clean => 1,
-           section_pre_data         => 1, }, },
+           role                     => 1,
+           section_pre_data         => 1,
+           test_schema_plus_blobs   => 1, }, },
 
    'CREATE PUBLICATION pub2' => {
        all_runs     => 1,
@@ -4206,19 +4205,18 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog
            no_blobs                 => 1,
            no_privs                 => 1,
            no_owner                 => 1,
-           only_dump_test_schema    => 1, # XXX Should be unlike
-           only_dump_test_table     => 1, # XXX Should be unlike
            pg_dumpall_dbprivs       => 1,
-           role                     => 1, # XXX Should be unlike
            schema_only              => 1,
            section_post_data        => 1,
-           test_schema_plus_blobs   => 1, # XXX Should be unlike
            with_oids                => 1, },
        unlike => {
-           section_pre_data         => 1,
+           only_dump_test_schema    => 1,
+           only_dump_test_table     => 1,
            pg_dumpall_globals       => 1,
            pg_dumpall_globals_clean => 1,
-           section_pre_data         => 1, }, },
+           role                     => 1,
+           section_pre_data         => 1,
+           test_schema_plus_blobs   => 1, }, },
 
    'CREATE SUBSCRIPTION sub1' => {
        all_runs     => 1,
@@ -4274,12 +4272,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog
            no_blobs                => 1,
            no_privs                => 1,
            no_owner                => 1,
-           only_dump_test_schema   => 1,
-           only_dump_test_table    => 1,
            pg_dumpall_dbprivs      => 1,
            schema_only             => 1,
            section_post_data       => 1,
-           test_schema_plus_blobs  => 1,
            with_oids               => 1, },
        unlike => {
            column_inserts           => 1,
@@ -4289,8 +4284,11 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog
            section_pre_data         => 1,
            exclude_dump_test_schema => 1,
            exclude_test_table       => 1,
+           only_dump_test_schema    => 1,
+           only_dump_test_table     => 1,
            pg_dumpall_globals       => 1,
-           pg_dumpall_globals_clean => 1, }, },
+           pg_dumpall_globals_clean => 1,
+           test_schema_plus_blobs   => 1, }, },
    'ALTER PUBLICATION pub1 ADD TABLE test_second_table' => {
        create_order => 52,
        create_sql =>
@@ -4308,17 +4306,17 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog
            exclude_test_table_data => 1,
            no_privs                => 1,
            no_owner                => 1,
-           only_dump_test_schema   => 1,
            pg_dumpall_dbprivs      => 1,
            schema_only             => 1,
-           section_post_data       => 1,
-           test_schema_plus_blobs  => 1, },
+           section_post_data       => 1, },
        unlike => {
            section_pre_data         => 1,
            exclude_dump_test_schema => 1,
+           only_dump_test_schema    => 1,
            only_dump_test_table     => 1,
            pg_dumpall_globals       => 1,
-           pg_dumpall_globals_clean => 1, }, },
+           pg_dumpall_globals_clean => 1,
+           test_schema_plus_blobs   => 1, }, },
 
    'CREATE SCHEMA dump_test' => {
        all_runs     => 1,