Skip to content

Commit 77d2b15

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 <jian.universality@gmail.com> Co-authored-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com Backpatch-through: 13
1 parent e7a2bbd commit 77d2b15

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
@@ -3033,6 +3033,20 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
30333033
strcmp(te->desc, "ROW SECURITY") == 0))
30343034
return 0;
30353035

3036+
/*
3037+
* If it's a comment on a publication or a subscription, maybe ignore it.
3038+
*/
3039+
if (strcmp(te->desc, "COMMENT") == 0)
3040+
{
3041+
if (ropt->no_publications &&
3042+
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
3043+
return 0;
3044+
3045+
if (ropt->no_subscriptions &&
3046+
strncmp(te->tag, "SUBSCRIPTION", strlen("SUBSCRIPTION")) == 0)
3047+
return 0;
3048+
}
3049+
30363050
/*
30373051
* If it's a publication or a table part of a publication, maybe ignore
30383052
* 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,
@@ -1844,6 +1872,10 @@
18441872
regexp =>
18451873
qr/^COMMENT ON SUBSCRIPTION sub1 IS 'comment on subscription';/m,
18461874
like => { %full_runs, section_post_data => 1, },
1875+
unlike => {
1876+
no_subscriptions => 1,
1877+
no_subscriptions_restore => 1,
1878+
},
18471879
},
18481880
18491881
'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1' => {
@@ -3361,6 +3393,10 @@
33613393
\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub1', streaming = parallel);\E
33623394
/xm,
33633395
like => { %full_runs, section_post_data => 1, },
3396+
unlike => {
3397+
no_subscriptions => 1,
3398+
no_subscriptions_restore => 1,
3399+
},
33643400
},
33653401
33663402
'CREATE SUBSCRIPTION sub2' => {
@@ -3372,6 +3408,10 @@
33723408
\QCREATE SUBSCRIPTION sub2 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub2', streaming = off, origin = none);\E
33733409
/xm,
33743410
like => { %full_runs, section_post_data => 1, },
3411+
unlike => {
3412+
no_subscriptions => 1,
3413+
no_subscriptions_restore => 1,
3414+
},
33753415
},
33763416
33773417
'CREATE SUBSCRIPTION sub3' => {
@@ -3383,6 +3423,10 @@
33833423
\QCREATE SUBSCRIPTION sub3 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub3', streaming = on);\E
33843424
/xm,
33853425
like => { %full_runs, section_post_data => 1, },
3426+
unlike => {
3427+
no_subscriptions => 1,
3428+
no_subscriptions_restore => 1,
3429+
},
33863430
},
33873431
33883432

0 commit comments

Comments
 (0)