mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
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
This commit is contained in:
@@ -3049,10 +3049,15 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it's a comment on a publication or a subscription, maybe ignore it.
|
* If it's a comment on a policy, a publication, or a subscription, maybe
|
||||||
|
* ignore it.
|
||||||
*/
|
*/
|
||||||
if (strcmp(te->desc, "COMMENT") == 0)
|
if (strcmp(te->desc, "COMMENT") == 0)
|
||||||
{
|
{
|
||||||
|
if (ropt->no_policies &&
|
||||||
|
strncmp(te->tag, "POLICY", strlen("POLICY")) == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (ropt->no_publications &&
|
if (ropt->no_publications &&
|
||||||
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
|
strncmp(te->tag, "PUBLICATION", strlen("PUBLICATION")) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -632,6 +632,23 @@ my %pgdump_runs = (
|
|||||||
'postgres',
|
'postgres',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
no_policies_restore => {
|
||||||
|
dump_cmd => [
|
||||||
|
'pg_dump', '--no-sync',
|
||||||
|
'--format' => 'custom',
|
||||||
|
'--file' => "$tempdir/no_policies_restore.dump",
|
||||||
|
'--statistics',
|
||||||
|
'postgres',
|
||||||
|
],
|
||||||
|
restore_cmd => [
|
||||||
|
'pg_restore',
|
||||||
|
'--format' => 'custom',
|
||||||
|
'--file' => "$tempdir/no_policies_restore.sql",
|
||||||
|
'--no-policies',
|
||||||
|
'--statistics',
|
||||||
|
"$tempdir/no_policies_restore.dump",
|
||||||
|
],
|
||||||
|
},
|
||||||
no_privs => {
|
no_privs => {
|
||||||
dump_cmd => [
|
dump_cmd => [
|
||||||
'pg_dump', '--no-sync',
|
'pg_dump', '--no-sync',
|
||||||
@@ -897,6 +914,7 @@ my %full_runs = (
|
|||||||
no_large_objects => 1,
|
no_large_objects => 1,
|
||||||
no_owner => 1,
|
no_owner => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
no_privs => 1,
|
no_privs => 1,
|
||||||
no_statistics => 1,
|
no_statistics => 1,
|
||||||
no_subscriptions => 1,
|
no_subscriptions => 1,
|
||||||
@@ -1540,6 +1558,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1858,6 +1877,27 @@ my %tests = (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'COMMENT ON POLICY p1' => {
|
||||||
|
create_order => 55,
|
||||||
|
create_sql => 'COMMENT ON POLICY p1 ON dump_test.test_table
|
||||||
|
IS \'comment on policy\';',
|
||||||
|
regexp =>
|
||||||
|
qr/^COMMENT ON POLICY p1 ON dump_test.test_table IS 'comment on policy';/m,
|
||||||
|
like => {
|
||||||
|
%full_runs,
|
||||||
|
%dump_test_schema_runs,
|
||||||
|
only_dump_test_table => 1,
|
||||||
|
section_post_data => 1,
|
||||||
|
},
|
||||||
|
unlike => {
|
||||||
|
exclude_dump_test_schema => 1,
|
||||||
|
exclude_test_table => 1,
|
||||||
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
|
only_dump_measurement => 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
'COMMENT ON PUBLICATION pub1' => {
|
'COMMENT ON PUBLICATION pub1' => {
|
||||||
create_order => 55,
|
create_order => 55,
|
||||||
create_sql => 'COMMENT ON PUBLICATION pub1
|
create_sql => 'COMMENT ON PUBLICATION pub1
|
||||||
@@ -3224,6 +3264,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -3246,6 +3287,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -3268,6 +3310,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -3290,6 +3333,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -3312,6 +3356,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -3334,6 +3379,7 @@ my %tests = (
|
|||||||
exclude_dump_test_schema => 1,
|
exclude_dump_test_schema => 1,
|
||||||
exclude_test_table => 1,
|
exclude_test_table => 1,
|
||||||
no_policies => 1,
|
no_policies => 1,
|
||||||
|
no_policies_restore => 1,
|
||||||
only_dump_measurement => 1,
|
only_dump_measurement => 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user