From 05227e0c345247c9e9ff91445850f414e2b0bb70 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 21 Mar 2017 23:19:09 -0400 Subject: [PATCH] pg_dump: Only dump publications when dumping everything 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 | 29 ++++++++++++++++--- src/bin/pg_dump/t/002_pg_dump.pl | 48 +++++++++++++++----------------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index e67171dccb..52fa6f33e3 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -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); diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index a4e260a4e4..a46dcdbcd7 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -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,