From 0074d6d6bb4915fb1d7f1454f201725abf2d3ec4 Mon Sep 17 00:00:00 2001
From: Vignesh <vignesh21@gmail.com>
Date: Wed, 18 Dec 2024 12:43:28 +0530
Subject: [PATCH v1] 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 | 17 -----------------
 2 files changed, 31 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index d34b8ed4bb..39b76815d7 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4534,13 +4534,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 =
@@ -4640,13 +4633,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 aa1564cd45..fd5d3daa03 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -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,
-		},
 	},
 
 	'ALTER PUBLICATION pub1 ADD TABLE test_second_table' => {
@@ -3051,7 +3047,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)' => {
@@ -3062,7 +3057,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)'
@@ -3074,7 +3068,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' => {
@@ -3085,7 +3078,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' => {
@@ -3105,10 +3097,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);' => {
@@ -3119,10 +3107,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\');'
@@ -3134,7 +3118,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

