On Wed, 19 Feb 2025 at 15:57, Amit Kapila <amit.kapil...@gmail.com> wrote:
>
> On Wed, Dec 18, 2024 at 12:51 PM vignesh C <vignes...@gmail.com> wrote:
> >
> > The attached patch has the changes for the same.
> >
>
> @@ -3037,10 +3037,6 @@ 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,
> - },
>
> Shall we change the above 'unlike' to 'like' instead of removing it
> with an additional comment as to why we expect a different behavior
> here?

The updated v2 version patch has the changes for the same.

Regards,
Vignesh
From 72e22deb7ae273825206403feed670e931ddddf3 Mon Sep 17 00:00:00 2001
From: Vignesh <vignes...@gmail.com>
Date: Wed, 18 Dec 2024 12:43:28 +0530
Subject: [PATCH v2] Include information_schema publications and excluded
 tables/schemas in dump

Previously, information_schema schema and table publications were excluded
from the dump, which led to their contents not being replicated after restoring
the dump. This issue occurred because the information_schema schema was set with
the DUMP_COMPONENT_NONE bitmask. The problem has been addressed by removing the
dump bitmask check for schemas and tables, ensuring that the corresponding
publications are now correctly included in the dump.
Additionally, this fix improves consistency by ensuring that table and schema
publications are included even when table and schema are excluded, similar to
the handling of dependent objects in other cases: a) Subscriptions that include
publications even when the --no-publication flag is used. b) The inclusion of
user-defined functions in views, even if those functions are excluded from the
dump.
---
 src/bin/pg_dump/pg_dump.c        | 14 --------------
 src/bin/pg_dump/t/002_pg_dump.pl | 21 ++++++---------------
 2 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 30dfda8c3f..6370bb711c 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -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 =
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index bc5d9222a2..92461acf6f 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -3094,6 +3094,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.
 	'ALTER PUBLICATION pub1 ADD TABLE test_table' => {
 		create_order => 51,
 		create_sql =>
@@ -3101,10 +3104,11 @@ my %tests = (
 		regexp => qr/^
 			\QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_table;\E
 			/xm,
-		like => { %full_runs, section_post_data => 1, },
-		unlike => {
+		like => {
+			%full_runs,
 			exclude_dump_test_schema => 1,
 			exclude_test_table => 1,
+			section_post_data => 1,
 		},
 	},
 
@@ -3116,7 +3120,6 @@ 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, },
 	},
 
 	'ALTER PUBLICATION pub1 ADD TABLE test_sixth_table (col3, col2)' => {
@@ -3127,7 +3130,6 @@ 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, },
 	},
 
 	'ALTER PUBLICATION pub1 ADD TABLE test_seventh_table (col3, col2) WHERE (col1 = 1)'
@@ -3139,7 +3141,6 @@ 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, },
 	  },
 
 	'ALTER PUBLICATION pub3 ADD TABLES IN SCHEMA dump_test' => {
@@ -3150,7 +3151,6 @@ 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, },
 	},
 
 	'ALTER PUBLICATION pub3 ADD TABLES IN SCHEMA public' => {
@@ -3170,10 +3170,6 @@ 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,
-		},
 	},
 
 	'ALTER PUBLICATION pub4 ADD TABLE test_table WHERE (col1 > 0);' => {
@@ -3184,10 +3180,6 @@ 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,
-		},
 	},
 
 	'ALTER PUBLICATION pub4 ADD TABLE test_second_table WHERE (col2 = \'test\');'
@@ -3199,7 +3191,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' => {
-- 
2.43.0

Reply via email to