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

Commit2ea624b

Browse files
committed
Rethink recent fix for pg_dump's handling of extension config tables.
Commit 3eb3d3e78 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 by 3eb3d3e78, 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 by 3eb3d3e78 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 parentbe304cf commit2ea624b

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,8 +2099,6 @@ dumpTableData_insert(Archive *fout, void *dcontext)
20992099
if (nfields == 0)
21002100
continue;
21012101

2102-
Assert(tbinfo->attgenerated);
2103-
21042102
/* Emit a row heading */
21052103
if (rows_per_statement == 1)
21062104
archputs(" (", fout);
@@ -2261,6 +2259,9 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
22612259
char *copyStmt;
22622260
const char *copyFrom;
22632261

2262+
/* We had better have loaded per-column details about this table */
2263+
Assert(tbinfo->interesting);
2264+
22642265
if (!dopt->dump_inserts)
22652266
{
22662267
/* Dump/restore using COPY */
@@ -2452,6 +2453,9 @@ makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
24522453
addObjectDependency(&tdinfo->dobj, tbinfo->dobj.dumpId);
24532454

24542455
tbinfo->dataObj = tdinfo;
2456+
2457+
/* Make sure that we'll collect per-column info for this table. */
2458+
tbinfo->interesting = true;
24552459
}
24562460

24572461
/*
@@ -15772,10 +15776,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1577215776
intj,
1577315777
k;
1577415778

15779+
/* We had better have loaded per-column details about this table */
15780+
Assert(tbinfo->interesting);
15781+
1577515782
qrelname = pg_strdup(fmtId(tbinfo->dobj.name));
1577615783
qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
1577715784

15778-
1577915785
if (tbinfo->hasoids)
1578015786
pg_log_warning("WITH OIDS is not supported anymore (table \"%s\")",
1578115787
qrelname);
@@ -18143,8 +18149,6 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
1814318149
configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
1814418150
}
1814518151
}
18146-
18147-
configtbl->interesting = dumpobj;
1814818152
}
1814918153
}
1815018154
if (extconfigarray)

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,17 @@
135135
"$tempdir/defaults_tar_format.tar",
136136
],
137137
},
138+
exclude_table=> {
139+
dump_cmd=> [
140+
'pg_dump',
141+
'--exclude-table=regress_table_dumpable',
142+
"--file=$tempdir/exclude_table.sql",
143+
'postgres',
144+
],
145+
},
138146
extension_schema=> {
139147
dump_cmd=> [
140-
'pg_dump','--schema=public','--inserts',
148+
'pg_dump','--schema=public',
141149
"--file=$tempdir/extension_schema.sql",'postgres',
142150
],
143151
},
@@ -225,6 +233,7 @@
225233
clean_if_exists=> 1,
226234
createdb=> 1,
227235
defaults=> 1,
236+
exclude_table=> 1,
228237
no_privs=> 1,
229238
no_owner=> 1,);
230239

@@ -317,11 +326,28 @@
317326
regexp => qr/^
318327
\QCREATE TABLE public.regress_pg_dump_table (\E
319328
\n\s+\Qcol1 integer NOT NULL,\E
320-
\n\s+\Qcol2 integer\E
329+
\n\s+\Qcol2 integer,\E
330+
\n\s+\QCONSTRAINT regress_pg_dump_table_col2_check CHECK ((col2 > 0))\E
321331
\n\);\n/xm,
322332
like => { binary_upgrade => 1, },
323333
},
324334
335+
'COPY public.regress_table_dumpable (col1)' => {
336+
regexp => qr/^
337+
\QCOPY public.regress_table_dumpable (col1) FROM stdin;\E
338+
\n/xm,
339+
like => {
340+
%full_runs,
341+
data_only => 1,
342+
section_data => 1,
343+
extension_schema => 1,
344+
},
345+
unlike => {
346+
binary_upgrade => 1,
347+
exclude_table => 1,
348+
},
349+
},
350+
325351
'CREATE ACCESS METHOD regress_test_am' => {
326352
regexp => qr/^
327353
\QCREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;\E
@@ -443,7 +469,8 @@
443469
regexp => qr/^
444470
\QCREATE TABLE regress_pg_dump_schema.test_table (\E
445471
\n\s+\Qcol1 integer,\E
446-
\n\s+\Qcol2 integer\E
472+
\n\s+\Qcol2 integer,\E
473+
\n\s+\QCONSTRAINT test_table_col2_check CHECK ((col2 > 0))\E
447474
\n\);\n/xm,
448475
like => { binary_upgrade => 1, },
449476
},
@@ -578,17 +605,6 @@
578605
schema_only => 1,
579606
section_pre_data => 1,
580607
},
581-
},
582-
583-
# Dumpable object inside specific schema
584-
'INSERT INTO public.regress_table_dumpable VALUES (1);' => {
585-
create_sql => 'INSERT INTO public.regress_table_dumpable VALUES (1);',
586-
regexp => qr/^
587-
\QINSERT INTO public.regress_table_dumpable VALUES (1);\E
588-
\n/xm,
589-
like => {
590-
extension_schema => 1,
591-
},
592608
},);
593609
594610
#########################################

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

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

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

1111
CREATESEQUENCEregress_pg_dump_seq;
@@ -14,7 +14,7 @@ CREATE SEQUENCE regress_seq_dumpable;
1414
SELECTpg_catalog.pg_extension_config_dump('regress_seq_dumpable','');
1515

1616
CREATETABLEregress_table_dumpable (
17-
col1int
17+
col1intcheck (col1>0)
1818
);
1919
SELECTpg_catalog.pg_extension_config_dump('regress_table_dumpable','');
2020

@@ -34,7 +34,7 @@ CREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;
3434
-- this extension.
3535
CREATETABLEregress_pg_dump_schema.test_table (
3636
col1int,
37-
col2int
37+
col2intcheck (col2>0)
3838
);
3939
GRANTSELECTONregress_pg_dump_schema.test_table TO regress_dump_test_role;
4040

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp