Skip to content

Commit 0bfe356

Browse files
committed
Rethink recent fix for pg_dump's handling of extension config tables.
Commit 3eb3d3e was a few bricks shy of a load: while it correctly set the table's "interesting" flag when deciding to dump the data of an extension config table, it was not correct to clear that flag if we concluded we shouldn't dump the data. This led to the crash reported in bug #16655, because in fact we'll traverse dumpTableSchema anyway for all extension tables (to see if they have user-added seclabels 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-proof in case additional calls are added, and it also avoids setting the flag unnecessarily if that function decides the table is non-dumpable.) This investigation also showed that while only the --inserts code path had an obvious failure in the case considered by 3eb3d3e, the COPY code path also has a problem with not having loaded table subsidiary data. That causes fmtCopyColumnList to silently return an empty string instead of the correct column list. That accidentally mostly works, which perhaps is why we didn't notice this before. It would only fail if the restore column order is different from the dump column order, which only happens in weird inheritance cases, so it's not surprising nobody 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 some Asserts that "interesting" has been set in both dumpTableData and dumpTableSchema. Adjust the test case added by 3eb3d3e so that it checks the COPY rather than INSERT form of that bug, allowing it to detect the longer-standing symptom. Per bug #16655 from Cameron Daniel. Back-patch to all supported branches. Discussion: https://postgr.es/m/16655-5c92d6b3a9438137@postgresql.org Discussion: https://postgr.es/m/18048b44-3414-b983-8c7c-9165b177900d@2ndQuadrant.com
1 parent c09164a commit 0bfe356

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,9 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
19111911
DataDumperPtr dumpFn;
19121912
char *copyStmt;
19131913

1914+
/* We had better have loaded per-column details about this table */
1915+
Assert(tbinfo->interesting);
1916+
19141917
if (!dopt->dump_inserts)
19151918
{
19161919
/* Dump/restore using COPY */
@@ -2064,6 +2067,9 @@ makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids)
20642067
addObjectDependency(&tdinfo->dobj, tbinfo->dobj.dumpId);
20652068

20662069
tbinfo->dataObj = tdinfo;
2070+
2071+
/* Make sure that we'll collect per-column info for this table. */
2072+
tbinfo->interesting = true;
20672073
}
20682074

20692075
/*
@@ -13843,6 +13849,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1384313849
int j,
1384413850
k;
1384513851

13852+
/* We had better have loaded per-column details about this table */
13853+
Assert(tbinfo->interesting);
13854+
1384613855
qrelname = pg_strdup(fmtId(tbinfo->dobj.name));
1384713856
qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
1384813857

0 commit comments

Comments
 (0)