Skip to content

Commit 5734eb2

Browse files
committed
Properly dump dropped foreign table cols in binary-upgrade mode.
In binary upgrade mode, we need to recreate and then drop dropped columns so that all the columns get the right attribute number. This is true for foreign tables as well as for native tables. For foreign tables we have been getting the first part right but not the second, leading to bogus columns in the upgraded database. Fix this all the way back to 9.1, where foreign tables were introduced.
1 parent bee4a4d commit 5734eb2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12595,7 +12595,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1259512595
* attislocal correctly, plus fix up any inherited CHECK constraints.
1259612596
* Analogously, we set up typed tables using ALTER TABLE / OF here.
1259712597
*/
12598-
if (binary_upgrade && tbinfo->relkind == RELKIND_RELATION)
12598+
if (binary_upgrade && (tbinfo->relkind == RELKIND_RELATION ||
12599+
tbinfo->relkind == RELKIND_FOREIGN_TABLE) )
1259912600
{
1260012601
for (j = 0; j < tbinfo->numatts; j++)
1260112602
{
@@ -12613,8 +12614,13 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1261312614
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
1261412615
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
1261512616

12616-
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
12617-
fmtId(tbinfo->dobj.name));
12617+
if (tbinfo->relkind == RELKIND_RELATION)
12618+
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
12619+
fmtId(tbinfo->dobj.name));
12620+
else
12621+
appendPQExpBuffer(q, "ALTER FOREIGN TABLE %s ",
12622+
fmtId(tbinfo->dobj.name));
12623+
1261812624
appendPQExpBuffer(q, "DROP COLUMN %s;\n",
1261912625
fmtId(tbinfo->attnames[j]));
1262012626
}

0 commit comments

Comments
 (0)