Include schema/table publications even with exclude options in dump.

The current implementation inconsistently includes public schema but not
information_schema when those are specified in FOR TABLES IN SCHMEA ...
Apart from that, the current behavior for publications w.r.t exclude table
and schema (--exclude-table, --exclude-schema) option differs from what we
do at other places. We try to avoid including publications for
corresponding tables or schemas when an exclude-table or exclude-schema
option is given, unlike what we do for views using functions defined in a
particular schema or a subscription pointing to publications with their
corresponding exclude options.

I decided not to backpatch this as it leads to a behavior change and we don't
see any field report for current behavior.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/1270733.1734134272@sss.pgh.pa.us
pull/200/head
Amit Kapila 4 months ago
parent f11674f8df
commit 4aa6fa3cd0
  1. 14
      src/bin/pg_dump/pg_dump.c
  2. 45
      src/bin/pg_dump/t/002_pg_dump.pl

@ -4536,13 +4536,6 @@ getPublicationNamespaces(Archive *fout)
if (nspinfo == NULL)
continue;
/*
* We always dump publication namespaces unless the corresponding
* namespace is excluded from the dump.
*/
if (nspinfo->dobj.dump == DUMP_COMPONENT_NONE)
continue;
/* OK, make a DumpableObject for this relationship */
pubsinfo[j].dobj.objType = DO_PUBLICATION_TABLE_IN_SCHEMA;
pubsinfo[j].dobj.catId.tableoid =
@ -4642,13 +4635,6 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
if (tbinfo == NULL)
continue;
/*
* Ignore publication membership of tables whose definitions are not
* to be dumped.
*/
if (!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
continue;
/* OK, make a DumpableObject for this relationship */
pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
pubrinfo[j].dobj.catId.tableoid =

@ -3094,6 +3094,10 @@ my %tests = (
like => { %full_runs, section_post_data => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub1 ADD TABLE test_table' => {
create_order => 51,
create_sql =>
@ -3102,12 +3106,11 @@ my %tests = (
\QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_table;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
exclude_test_table => 1,
},
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub1 ADD TABLE test_second_table' => {
create_order => 52,
create_sql =>
@ -3116,9 +3119,11 @@ my %tests = (
\QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_second_table;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub1 ADD TABLE test_sixth_table (col3, col2)' => {
create_order => 52,
create_sql =>
@ -3127,9 +3132,11 @@ my %tests = (
\QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_sixth_table (col2, col3);\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub1 ADD TABLE test_seventh_table (col3, col2) WHERE (col1 = 1)'
=> {
create_order => 52,
@ -3139,9 +3146,11 @@ my %tests = (
\QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_seventh_table (col2, col3) WHERE ((col1 = 1));\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub3 ADD TABLES IN SCHEMA dump_test' => {
create_order => 51,
create_sql =>
@ -3150,9 +3159,11 @@ my %tests = (
\QALTER PUBLICATION pub3 ADD TABLES IN SCHEMA dump_test;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub3 ADD TABLES IN SCHEMA public' => {
create_order => 52,
create_sql => 'ALTER PUBLICATION pub3 ADD TABLES IN SCHEMA public;',
@ -3162,6 +3173,9 @@ my %tests = (
like => { %full_runs, section_post_data => 1, },
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub3 ADD TABLE test_table' => {
create_order => 51,
create_sql =>
@ -3170,12 +3184,11 @@ my %tests = (
\QALTER PUBLICATION pub3 ADD TABLE ONLY dump_test.test_table;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
exclude_test_table => 1,
},
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub4 ADD TABLE test_table WHERE (col1 > 0);' => {
create_order => 51,
create_sql =>
@ -3184,12 +3197,11 @@ my %tests = (
\QALTER PUBLICATION pub4 ADD TABLE ONLY dump_test.test_table WHERE ((col1 > 0));\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
exclude_test_table => 1,
},
},
# Regardless of whether the table or schema is excluded, publications must
# still be dumped, as excluded objects do not apply to publications. We
# perform table and schema exclusion via full_runs.
'ALTER PUBLICATION pub4 ADD TABLE test_second_table WHERE (col2 = \'test\');'
=> {
create_order => 52,
@ -3199,7 +3211,6 @@ my %tests = (
\QALTER PUBLICATION pub4 ADD TABLE ONLY dump_test.test_second_table WHERE ((col2 = 'test'::text));\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
},
'CREATE SCHEMA public' => {

Loading…
Cancel
Save