Skip to content

Commit b54e8db

Browse files
committed
pg_restore: Fix comment handling with --no-publications / --no-subscriptions.
Previously, pg_restore did not skip comments on publications or subscriptions even when --no-publications or --no-subscriptions was specified. As a result, it could issue COMMENT commands for objects that were never created, causing those commands to fail. This commit fixes the issue by ensuring that comments on publications and subscriptions are also skipped when the corresponding options are used. Backpatch to all supported versions. Author: Jian He <[email protected]> Co-authored-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com Backpatch-through: 13
1 parent 7d9cd2d commit b54e8db

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,20 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
30483048
strcmp(te->desc, "ROW SECURITY") == 0))
30493049
return 0;
30503050

3051+
/*
3052+
* If it's a comment on a publication or a subscription, maybe ignore it.
3053+
*/
3054+
if (strcmp(te->desc, "COMMENT") == 0)
3055+
{
3056+
if (ropt->no_publications &&
3057+
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
3058+
return 0;
3059+
3060+
if (ropt->no_subscriptions &&
3061+
strncmp(te->tag, "SUBSCRIPTION", strlen("SUBSCRIPTION")) == 0)
3062+
return 0;
3063+
}
3064+
30513065
/*
30523066
* If it's a publication or a table part of a publication, maybe ignore
30533067
* it.

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,32 @@
650650
'postgres',
651651
],
652652
},
653+
no_subscriptions => {
654+
dump_cmd => [
655+
'pg_dump', '--no-sync',
656+
'--file' => "$tempdir/no_subscriptions.sql",
657+
'--no-subscriptions',
658+
'--statistics',
659+
'postgres',
660+
],
661+
},
662+
no_subscriptions_restore => {
663+
dump_cmd => [
664+
'pg_dump', '--no-sync',
665+
'--format' => 'custom',
666+
'--file' => "$tempdir/no_subscriptions_restore.dump",
667+
'--statistics',
668+
'postgres',
669+
],
670+
restore_cmd => [
671+
'pg_restore',
672+
'--format' => 'custom',
673+
'--file' => "$tempdir/no_subscriptions_restore.sql",
674+
'--no-subscriptions',
675+
'--statistics',
676+
"$tempdir/no_subscriptions_restore.dump",
677+
],
678+
},
653679
no_table_access_method => {
654680
dump_cmd => [
655681
'pg_dump', '--no-sync',
@@ -873,6 +899,8 @@
873899
no_policies => 1,
874900
no_privs => 1,
875901
no_statistics => 1,
902+
no_subscriptions => 1,
903+
no_subscriptions_restore => 1,
876904
no_table_access_method => 1,
877905
pg_dumpall_dbprivs => 1,
878906
pg_dumpall_exclude => 1,
@@ -1846,6 +1874,10 @@
18461874
regexp =>
18471875
qr/^COMMENT ON SUBSCRIPTION sub1 IS 'comment on subscription';/m,
18481876
like => { %full_runs, section_post_data => 1, },
1877+
unlike => {
1878+
no_subscriptions => 1,
1879+
no_subscriptions_restore => 1,
1880+
},
18491881
},
18501882
18511883
'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1' => {
@@ -3363,6 +3395,10 @@
33633395
\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub1', streaming = parallel);\E
33643396
/xm,
33653397
like => { %full_runs, section_post_data => 1, },
3398+
unlike => {
3399+
no_subscriptions => 1,
3400+
no_subscriptions_restore => 1,
3401+
},
33663402
},
33673403
33683404
'CREATE SUBSCRIPTION sub2' => {
@@ -3374,6 +3410,10 @@
33743410
\QCREATE SUBSCRIPTION sub2 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub2', streaming = off, origin = none);\E
33753411
/xm,
33763412
like => { %full_runs, section_post_data => 1, },
3413+
unlike => {
3414+
no_subscriptions => 1,
3415+
no_subscriptions_restore => 1,
3416+
},
33773417
},
33783418
33793419
'CREATE SUBSCRIPTION sub3' => {
@@ -3385,6 +3425,10 @@
33853425
\QCREATE SUBSCRIPTION sub3 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub3', streaming = on);\E
33863426
/xm,
33873427
like => { %full_runs, section_post_data => 1, },
3428+
unlike => {
3429+
no_subscriptions => 1,
3430+
no_subscriptions_restore => 1,
3431+
},
33883432
},
33893433
33903434

0 commit comments

Comments
 (0)