diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index b0ef1980360..93026a8ddc5 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2855,6 +2855,20 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) if (ropt->no_comments && strcmp(te->desc, "COMMENT") == 0) return 0; + /* + * If it's a comment on a publication or a subscription, maybe ignore it. + */ + if (strcmp(te->desc, "COMMENT") == 0) + { + if (ropt->no_publications && + strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0) + return 0; + + if (ropt->no_subscriptions && + strncmp(te->tag, "SUBSCRIPTION", strlen("SUBSCRIPTION")) == 0) + return 0; + } + /* * If it's a publication or a table part of a publication, maybe ignore * it. diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index b491e461158..5a69e58f217 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -548,6 +548,29 @@ my %pgdump_runs = ( 'postgres', ], }, + no_subscriptions => { + dump_cmd => [ + 'pg_dump', '--no-sync', + '--file' => "$tempdir/no_subscriptions.sql", + '--no-subscriptions', + 'postgres', + ], + }, + no_subscriptions_restore => { + dump_cmd => [ + 'pg_dump', '--no-sync', + '--format' => 'custom', + '--file' => "$tempdir/no_subscriptions_restore.dump", + 'postgres', + ], + restore_cmd => [ + 'pg_restore', + '--format' => 'custom', + '--file' => "$tempdir/no_subscriptions_restore.sql", + '--no-subscriptions', + "$tempdir/no_subscriptions_restore.dump", + ], + }, no_table_access_method => { dump_cmd => [ 'pg_dump', '--no-sync', @@ -722,6 +745,8 @@ my %full_runs = ( no_large_objects => 1, no_owner => 1, no_privs => 1, + no_subscriptions => 1, + no_subscriptions_restore => 1, no_table_access_method => 1, pg_dumpall_dbprivs => 1, pg_dumpall_exclude => 1, @@ -1546,6 +1571,10 @@ my %tests = ( regexp => qr/^COMMENT ON SUBSCRIPTION sub1 IS 'comment on subscription';/m, like => { %full_runs, section_post_data => 1, }, + unlike => { + no_subscriptions => 1, + no_subscriptions_restore => 1, + }, }, 'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1' => { @@ -2988,6 +3017,10 @@ my %tests = ( \QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub1');\E /xm, like => { %full_runs, section_post_data => 1, }, + unlike => { + no_subscriptions => 1, + no_subscriptions_restore => 1, + }, }, 'CREATE SUBSCRIPTION sub2' => { @@ -2999,6 +3032,10 @@ my %tests = ( \QCREATE SUBSCRIPTION sub2 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub2', origin = none);\E /xm, like => { %full_runs, section_post_data => 1, }, + unlike => { + no_subscriptions => 1, + no_subscriptions_restore => 1, + }, }, 'CREATE SUBSCRIPTION sub3' => { @@ -3010,6 +3047,10 @@ my %tests = ( \QCREATE SUBSCRIPTION sub3 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub3');\E /xm, like => { %full_runs, section_post_data => 1, }, + unlike => { + no_subscriptions => 1, + no_subscriptions_restore => 1, + }, }, 'ALTER PUBLICATION pub1 ADD TABLE test_table' => { @@ -3862,6 +3903,8 @@ my %tests = ( no_large_objects => 1, no_privs => 1, no_owner => 1, + no_subscriptions => 1, + no_subscriptions_restore => 1, no_table_access_method => 1, only_dump_test_schema => 1, pg_dumpall_dbprivs => 1, @@ -3954,6 +3997,8 @@ my %tests = ( no_large_objects => 1, no_privs => 1, no_owner => 1, + no_subscriptions => 1, + no_subscriptions_restore => 1, no_table_access_method => 1, pg_dumpall_dbprivs => 1, pg_dumpall_exclude => 1,