@@ -4354,14 +4354,20 @@ binary_upgrade_set_type_oids_by_rel_oid(Archive *fout,
43544354 Oid pg_type_oid;
43554355 bool toast_set = false;
43564356
4357- /* we only support old >= 8.3 for binary upgrades */
4357+ /*
4358+ * We only support old >= 8.3 for binary upgrades.
4359+ *
4360+ * We purposefully ignore toast OIDs for partitioned tables; the reason is
4361+ * that versions 10 and 11 have them, but 12 does not, so emitting them
4362+ * causes the upgrade to fail.
4363+ */
43584364 appendPQExpBuffer(upgrade_query,
43594365 "SELECT c.reltype AS crel, t.reltype AS trel "
43604366 "FROM pg_catalog.pg_class c "
43614367 "LEFT JOIN pg_catalog.pg_class t ON "
4362- " (c.reltoastrelid = t.oid) "
4368+ " (c.reltoastrelid = t.oid AND c.relkind <> '%c' ) "
43634369 "WHERE c.oid = '%u'::pg_catalog.oid;",
4364- pg_rel_oid);
4370+ RELKIND_PARTITIONED_TABLE, pg_rel_oid);
43654371
43664372 upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
43674373
@@ -5953,6 +5959,10 @@ getTables(Archive *fout, int *numTables)
59535959 * information about each table, basically just enough to decide if it is
59545960 * interesting. We must fetch all tables in this phase because otherwise
59555961 * we cannot correctly identify inherited columns, owned sequences, etc.
5962+ *
5963+ * We purposefully ignore toast OIDs for partitioned tables; the reason is
5964+ * that versions 10 and 11 have them, but 12 does not, so emitting them
5965+ * causes the upgrade to fail.
59565966 */
59575967
59585968 if (fout->remoteVersion >= 90600)
@@ -6049,7 +6059,7 @@ getTables(Archive *fout, int *numTables)
60496059 "d.classid = c.tableoid AND d.objid = c.oid AND "
60506060 "d.objsubid = 0 AND "
60516061 "d.refclassid = c.tableoid AND d.deptype IN ('a', 'i')) "
6052- "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) "
6062+ "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid AND c.relkind <> '%c' ) "
60536063 "LEFT JOIN pg_am am ON (c.relam = am.oid) "
60546064 "LEFT JOIN pg_init_privs pip ON "
60556065 "(c.oid = pip.objoid "
@@ -6072,6 +6082,7 @@ getTables(Archive *fout, int *numTables)
60726082 ispartition,
60736083 partbound,
60746084 RELKIND_SEQUENCE,
6085+ RELKIND_PARTITIONED_TABLE,
60756086 RELKIND_RELATION, RELKIND_SEQUENCE,
60766087 RELKIND_VIEW, RELKIND_COMPOSITE_TYPE,
60776088 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
0 commit comments