Skip to content

Commit 1c6afc4

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 3f145f6 commit 1c6afc4

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
@@ -12440,7 +12440,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1244012440
* attislocal correctly, plus fix up any inherited CHECK constraints.
1244112441
* Analogously, we set up typed tables using ALTER TABLE / OF here.
1244212442
*/
12443-
if (binary_upgrade && tbinfo->relkind == RELKIND_RELATION)
12443+
if (binary_upgrade && (tbinfo->relkind == RELKIND_RELATION ||
12444+
tbinfo->relkind == RELKIND_FOREIGN_TABLE) )
1244412445
{
1244512446
for (j = 0; j < tbinfo->numatts; j++)
1244612447
{
@@ -12458,8 +12459,13 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1245812459
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
1245912460
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
1246012461

12461-
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
12462-
fmtId(tbinfo->dobj.name));
12462+
if (tbinfo->relkind == RELKIND_RELATION)
12463+
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
12464+
fmtId(tbinfo->dobj.name));
12465+
else
12466+
appendPQExpBuffer(q, "ALTER FOREIGN TABLE %s ",
12467+
fmtId(tbinfo->dobj.name));
12468+
1246312469
appendPQExpBuffer(q, "DROP COLUMN %s;\n",
1246412470
fmtId(tbinfo->attnames[j]));
1246512471
}

0 commit comments

Comments
 (0)