Skip to content

Commit 66dabc0

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 <[email protected]> Co-authored-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com Backpatch-through: 18
1 parent b54e8db commit 66dabc0

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
@@ -3049,10 +3049,15 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
30493049
return 0;
30503050

30513051
/*
3052-
* If it's a comment on a publication or a subscription, maybe ignore it.
3052+
* If it's a comment on a policy, a publication, or a subscription, maybe
3053+
* ignore it.
30533054
*/
30543055
if (strcmp(te->desc, "COMMENT") == 0)
30553056
{
3057+
if (ropt->no_policies &&
3058+
strncmp(te->tag, "POLICY", strlen("POLICY")) == 0)
3059+
return 0;
3060+
30563061
if (ropt->no_publications &&
30573062
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
30583063
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,
@@ -1540,6 +1558,7 @@
15401558
exclude_dump_test_schema => 1,
15411559
exclude_test_table => 1,
15421560
no_policies => 1,
1561+
no_policies_restore => 1,
15431562
only_dump_measurement => 1,
15441563
},
15451564
},
@@ -1858,6 +1877,27 @@
18581877
},
18591878
},
18601879
1880+
'COMMENT ON POLICY p1' => {
1881+
create_order => 55,
1882+
create_sql => 'COMMENT ON POLICY p1 ON dump_test.test_table
1883+
IS \'comment on policy\';',
1884+
regexp =>
1885+
qr/^COMMENT ON POLICY p1 ON dump_test.test_table IS 'comment on policy';/m,
1886+
like => {
1887+
%full_runs,
1888+
%dump_test_schema_runs,
1889+
only_dump_test_table => 1,
1890+
section_post_data => 1,
1891+
},
1892+
unlike => {
1893+
exclude_dump_test_schema => 1,
1894+
exclude_test_table => 1,
1895+
no_policies => 1,
1896+
no_policies_restore => 1,
1897+
only_dump_measurement => 1,
1898+
},
1899+
},
1900+
18611901
'COMMENT ON PUBLICATION pub1' => {
18621902
create_order => 55,
18631903
create_sql => 'COMMENT ON PUBLICATION pub1
@@ -3224,6 +3264,7 @@
32243264
exclude_dump_test_schema => 1,
32253265
exclude_test_table => 1,
32263266
no_policies => 1,
3267+
no_policies_restore => 1,
32273268
only_dump_measurement => 1,
32283269
},
32293270
},
@@ -3246,6 +3287,7 @@
32463287
exclude_dump_test_schema => 1,
32473288
exclude_test_table => 1,
32483289
no_policies => 1,
3290+
no_policies_restore => 1,
32493291
only_dump_measurement => 1,
32503292
},
32513293
},
@@ -3268,6 +3310,7 @@
32683310
exclude_dump_test_schema => 1,
32693311
exclude_test_table => 1,
32703312
no_policies => 1,
3313+
no_policies_restore => 1,
32713314
only_dump_measurement => 1,
32723315
},
32733316
},
@@ -3290,6 +3333,7 @@
32903333
exclude_dump_test_schema => 1,
32913334
exclude_test_table => 1,
32923335
no_policies => 1,
3336+
no_policies_restore => 1,
32933337
only_dump_measurement => 1,
32943338
},
32953339
},
@@ -3312,6 +3356,7 @@
33123356
exclude_dump_test_schema => 1,
33133357
exclude_test_table => 1,
33143358
no_policies => 1,
3359+
no_policies_restore => 1,
33153360
only_dump_measurement => 1,
33163361
},
33173362
},
@@ -3334,6 +3379,7 @@
33343379
exclude_dump_test_schema => 1,
33353380
exclude_test_table => 1,
33363381
no_policies => 1,
3382+
no_policies_restore => 1,
33373383
only_dump_measurement => 1,
33383384
},
33393385
},

0 commit comments

Comments
 (0)