Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c79dcb

Browse files
committed
Rethink recent fix for pg_dump's handling of extension config tables.
Commit3eb3d3e was a few bricks shy of a load: while it correctlyset the table's "interesting" flag when deciding to dump the data ofan extension config table, it was not correct to clear that flagif we concluded we shouldn't dump the data. This led to the crashreported in bug #16655, because in fact we'll traverse dumpTableSchemaanyway for all extension tables (to see if they have user-addedseclabels or RLS policies).The right thing to do is to force "interesting" true in makeTableDataInfo,and otherwise leave the flag alone. (Doing it there is more future-proofin case additional calls are added, and it also avoids setting the flagunnecessarily if that function decides the table is non-dumpable.)This investigation also showed that while only the --inserts code pathhad an obvious failure in the case considered by3eb3d3e, the COPYcode path also has a problem with not having loaded table subsidiarydata. That causes fmtCopyColumnList to silently return an empty stringinstead of the correct column list. That accidentally mostly works,which perhaps is why we didn't notice this before. It would only failif the restore column order is different from the dump column order,which only happens in weird inheritance cases, so it's not surprisingnobody had hit the case with an extension config table. Nonetheless,it's a bug, and it goes a long way back, not just to v12 where the--inserts code path started to have a problem with this.In hopes of catching such cases a bit sooner in future, add someAsserts that "interesting" has been set in both dumpTableData anddumpTableSchema. Adjust the test case added by3eb3d3e so that itchecks the COPY rather than INSERT form of that bug, allowing it todetect the longer-standing symptom.Per bug #16655 from Cameron Daniel. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/16655-5c92d6b3a9438137@postgresql.orgDiscussion:https://postgr.es/m/18048b44-3414-b983-8c7c-9165b177900d@2ndQuadrant.com
1 parent957a782 commit0c79dcb

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,9 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
20462046
DataDumperPtr dumpFn;
20472047
char *copyStmt;
20482048

2049+
/* We had better have loaded per-column details about this table */
2050+
Assert(tbinfo->interesting);
2051+
20492052
if (!dopt->dump_inserts)
20502053
{
20512054
/* Dump/restore using COPY */
@@ -2207,6 +2210,9 @@ makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids)
22072210
addObjectDependency(&tdinfo->dobj, tbinfo->dobj.dumpId);
22082211

22092212
tbinfo->dataObj = tdinfo;
2213+
2214+
/* Make sure that we'll collect per-column info for this table. */
2215+
tbinfo->interesting = true;
22102216
}
22112217

22122218
/*
@@ -14957,6 +14963,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1495714963
intj,
1495814964
k;
1495914965

14966+
/* We had better have loaded per-column details about this table */
14967+
Assert(tbinfo->interesting);
14968+
1496014969
qrelname = pg_strdup(fmtId(tbinfo->dobj.name));
1496114970
qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
1496214971

‎src/test/modules/test_pg_dump/t/001_base.pl

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@
118118
'pg_restore',
119119
"--file=$tempdir/defaults_tar_format.sql",
120120
"$tempdir/defaults_tar_format.tar", ], },
121+
exclude_table=> {
122+
dump_cmd=> [
123+
'pg_dump',
124+
'--exclude-table=regress_table_dumpable',
125+
"--file=$tempdir/exclude_table.sql",
126+
'postgres',
127+
],
128+
},
129+
extension_schema=> {
130+
dump_cmd=> [
131+
'pg_dump','--schema=public',
132+
"--file=$tempdir/extension_schema.sql",'postgres',
133+
],
134+
},
121135
pg_dumpall_globals=> {
122136
dump_cmd=> [
123137
'pg_dumpall','--no-sync',
@@ -339,7 +353,8 @@
339353
regexp => qr/^
340354
\QCREATE TABLE public.regress_pg_dump_table (\E
341355
\n\s+\Qcol1 integer NOT NULL,\E
342-
\n\s+\Qcol2 integer\E
356+
\n\s+\Qcol2 integer,\E
357+
\n\s+\QCONSTRAINT regress_pg_dump_table_col2_check CHECK ((col2 > 0))\E
343358
\n\);\n/xm,
344359
like => { binary_upgrade => 1, },
345360
unlike => {
@@ -354,6 +369,31 @@
354369
section_pre_data => 1,
355370
section_post_data => 1, }, },
356371
372+
'COPY public.regress_table_dumpable (col1)' => {
373+
regexp => qr/^
374+
\QCOPY public.regress_table_dumpable (col1) FROM stdin;\E
375+
\n/xm,
376+
like => {
377+
clean => 1,
378+
clean_if_exists => 1,
379+
createdb => 1,
380+
defaults => 1,
381+
no_privs => 1,
382+
no_owner => 1,
383+
data_only => 1,
384+
section_data => 1,
385+
extension_schema => 1,
386+
},
387+
unlike => {
388+
binary_upgrade => 1,
389+
exclude_table => 1,
390+
pg_dumpall_globals => 1,
391+
schema_only => 1,
392+
section_pre_data => 1,
393+
section_post_data => 1,
394+
},
395+
},
396+
357397
'CREATE ACCESS METHOD regress_test_am' => {
358398
regexp => qr/^
359399
\QCREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;\E
@@ -555,7 +595,8 @@
555595
regexp => qr/^
556596
\QCREATE TABLE regress_pg_dump_schema.test_table (\E
557597
\n\s+\Qcol1 integer,\E
558-
\n\s+\Qcol2 integer\E
598+
\n\s+\Qcol2 integer,\E
599+
\n\s+\QCONSTRAINT test_table_col2_check CHECK ((col2 > 0))\E
559600
\n\);\n/xm,
560601
like => { binary_upgrade => 1, },
561602
unlike => {
@@ -764,6 +805,7 @@
764805
unlike => {
765806
column_inserts => 1,
766807
data_only => 1,
808+
extension_schema => 1,
767809
pg_dumpall_globals => 1,
768810
section_data => 1,
769811
section_pre_data => 1, }, },
@@ -784,6 +826,7 @@
784826
unlike => {
785827
column_inserts => 1,
786828
data_only => 1,
829+
extension_schema => 1,
787830
pg_dumpall_globals => 1,
788831
section_data => 1,
789832
section_pre_data => 1, }, },

‎src/test/modules/test_pg_dump/test_pg_dump--1.0.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
CREATETABLEregress_pg_dump_table (
77
col1serial,
8-
col2int
8+
col2intcheck (col2>0)
99
);
1010

1111
CREATESEQUENCEregress_pg_dump_seq;
1212

1313
CREATESEQUENCEregress_seq_dumpable;
1414
SELECTpg_catalog.pg_extension_config_dump('regress_seq_dumpable','');
1515

16+
CREATETABLEregress_table_dumpable (
17+
col1intcheck (col1>0)
18+
);
19+
SELECTpg_catalog.pg_extension_config_dump('regress_table_dumpable','');
20+
1621
CREATESCHEMAregress_pg_dump_schema;
1722

1823
GRANT USAGEON regress_pg_dump_seq TO regress_dump_test_role;
@@ -29,7 +34,7 @@ CREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;
2934
-- this extension.
3035
CREATETABLEregress_pg_dump_schema.test_table (
3136
col1int,
32-
col2int
37+
col2intcheck (col2>0)
3338
);
3439
GRANTSELECTONregress_pg_dump_schema.test_table TO regress_dump_test_role;
3540

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp