Skip to content

Commit 2ddbfed

Browse files
committed
pg_restore: Fix comment handling with --no-policies.
Previously, pg_restore did not skip comments on policies even when --no-policies was specified. As a result, it could issue COMMENT commands for policies that were never created, causing those commands to fail. This commit fixes the issue by ensuring that comments on policies are also skipped when --no-policies is used. Backpatch to v18, where --no-policies was added in pg_restore. 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: 18
1 parent 77d2b15 commit 2ddbfed

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3034,10 +3034,15 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
30343034
return 0;
30353035

30363036
/*
3037-
* If it's a comment on a publication or a subscription, maybe ignore it.
3037+
* If it's a comment on a policy, a publication, or a subscription, maybe
3038+
* ignore it.
30383039
*/
30393040
if (strcmp(te->desc, "COMMENT") == 0)
30403041
{
3042+
if (ropt->no_policies &&
3043+
strncmp(te->tag, "POLICY", strlen("POLICY")) == 0)
3044+
return 0;
3045+
30413046
if (ropt->no_publications &&
30423047
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
30433048
return 0;

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,23 @@
632632
'postgres',
633633
],
634634
},
635+
no_policies_restore => {
636+
dump_cmd => [
637+
'pg_dump', '--no-sync',
638+
'--format' => 'custom',
639+
'--file' => "$tempdir/no_policies_restore.dump",
640+
'--statistics',
641+
'postgres',
642+
],
643+
restore_cmd => [
644+
'pg_restore',
645+
'--format' => 'custom',
646+
'--file' => "$tempdir/no_policies_restore.sql",
647+
'--no-policies',
648+
'--statistics',
649+
"$tempdir/no_policies_restore.dump",
650+
],
651+
},
635652
no_privs => {
636653
dump_cmd => [
637654
'pg_dump', '--no-sync',
@@ -897,6 +914,7 @@
897914
no_large_objects => 1,
898915
no_owner => 1,
899916
no_policies => 1,
917+
no_policies_restore => 1,
900918
no_privs => 1,
901919
no_statistics => 1,
902920
no_subscriptions => 1,
@@ -1539,6 +1557,7 @@
15391557
exclude_dump_test_schema => 1,
15401558
exclude_test_table => 1,
15411559
no_policies => 1,
1560+
no_policies_restore => 1,
15421561
only_dump_measurement => 1,
15431562
},
15441563
},
@@ -1856,6 +1875,27 @@
18561875
},
18571876
},
18581877
1878+
'COMMENT ON POLICY p1' => {
1879+
create_order => 55,
1880+
create_sql => 'COMMENT ON POLICY p1 ON dump_test.test_table
1881+
IS \'comment on policy\';',
1882+
regexp =>
1883+
qr/^COMMENT ON POLICY p1 ON dump_test.test_table IS 'comment on policy';/m,
1884+
like => {
1885+
%full_runs,
1886+
%dump_test_schema_runs,
1887+
only_dump_test_table => 1,
1888+
section_post_data => 1,
1889+
},
1890+
unlike => {
1891+
exclude_dump_test_schema => 1,
1892+
exclude_test_table => 1,
1893+
no_policies => 1,
1894+
no_policies_restore => 1,
1895+
only_dump_measurement => 1,
1896+
},
1897+
},
1898+
18591899
'COMMENT ON PUBLICATION pub1' => {
18601900
create_order => 55,
18611901
create_sql => 'COMMENT ON PUBLICATION pub1
@@ -3222,6 +3262,7 @@
32223262
exclude_dump_test_schema => 1,
32233263
exclude_test_table => 1,
32243264
no_policies => 1,
3265+
no_policies_restore => 1,
32253266
only_dump_measurement => 1,
32263267
},
32273268
},
@@ -3244,6 +3285,7 @@
32443285
exclude_dump_test_schema => 1,
32453286
exclude_test_table => 1,
32463287
no_policies => 1,
3288+
no_policies_restore => 1,
32473289
only_dump_measurement => 1,
32483290
},
32493291
},
@@ -3266,6 +3308,7 @@
32663308
exclude_dump_test_schema => 1,
32673309
exclude_test_table => 1,
32683310
no_policies => 1,
3311+
no_policies_restore => 1,
32693312
only_dump_measurement => 1,
32703313
},
32713314
},
@@ -3288,6 +3331,7 @@
32883331
exclude_dump_test_schema => 1,
32893332
exclude_test_table => 1,
32903333
no_policies => 1,
3334+
no_policies_restore => 1,
32913335
only_dump_measurement => 1,
32923336
},
32933337
},
@@ -3310,6 +3354,7 @@
33103354
exclude_dump_test_schema => 1,
33113355
exclude_test_table => 1,
33123356
no_policies => 1,
3357+
no_policies_restore => 1,
33133358
only_dump_measurement => 1,
33143359
},
33153360
},
@@ -3332,6 +3377,7 @@
33323377
exclude_dump_test_schema => 1,
33333378
exclude_test_table => 1,
33343379
no_policies => 1,
3380+
no_policies_restore => 1,
33353381
only_dump_measurement => 1,
33363382
},
33373383
},

0 commit comments

Comments
 (0)