diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c new file mode 100644 index 1f5b7ae..02d3e0f *** a/contrib/pg_upgrade/info.c --- b/contrib/pg_upgrade/info.c *************** get_rel_infos(migratorContext *ctx, cons *** 306,311 **** --- 306,312 ---- int i_relname = -1; int i_oid = -1; int i_relfilenode = -1; + int i_reltablespace = -1; int i_reltoastrelid = -1; char query[QUERY_ALLOC]; *************** get_rel_infos(migratorContext *ctx, cons *** 320,326 **** snprintf(query, sizeof(query), "SELECT DISTINCT c.oid, n.nspname, c.relname, " ! " c.relfilenode, c.reltoastrelid, t.spclocation " "FROM pg_catalog.pg_class c JOIN " " pg_catalog.pg_namespace n " " ON c.relnamespace = n.oid " --- 321,327 ---- snprintf(query, sizeof(query), "SELECT DISTINCT c.oid, n.nspname, c.relname, " ! " c.relfilenode, c.reltoastrelid, c.reltablespace, t.spclocation " "FROM pg_catalog.pg_class c JOIN " " pg_catalog.pg_namespace n " " ON c.relnamespace = n.oid " *************** get_rel_infos(migratorContext *ctx, cons *** 339,345 **** " ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) " " AND relkind IN ('r','t', 'i'%s)" "GROUP BY c.oid, n.nspname, c.relname, c.relfilenode," ! " c.reltoastrelid, t.spclocation, " " n.nspname " "ORDER BY n.nspname, c.relname;", FirstNormalObjectId, --- 340,346 ---- " ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) " " AND relkind IN ('r','t', 'i'%s)" "GROUP BY c.oid, n.nspname, c.relname, c.relfilenode," ! " c.reltoastrelid, c.reltablespace, t.spclocation, " " n.nspname " "ORDER BY n.nspname, c.relname;", FirstNormalObjectId, *************** get_rel_infos(migratorContext *ctx, cons *** 361,366 **** --- 362,368 ---- i_relname = PQfnumber(res, "relname"); i_relfilenode = PQfnumber(res, "relfilenode"); i_reltoastrelid = PQfnumber(res, "reltoastrelid"); + i_reltablespace = PQfnumber(res, "reltablespace"); i_spclocation = PQfnumber(res, "spclocation"); for (relnum = 0; relnum < ntups; relnum++) *************** get_rel_infos(migratorContext *ctx, cons *** 379,388 **** curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode)); curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid)); ! tblspace = PQgetvalue(res, relnum, i_spclocation); ! /* if no table tablespace, use the database tablespace */ ! if (strlen(tblspace) == 0) tblspace = dbinfo->db_tblspace; strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace)); } PQclear(res); --- 381,393 ---- curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode)); curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid)); ! if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0) ! /* Might be "", meaning the cluster default location. */ ! tblspace = PQgetvalue(res, relnum, i_spclocation); ! else ! /* A zero reltablespace indicates the database tablespace. */ tblspace = dbinfo->db_tblspace; + strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace)); } PQclear(res); diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h new file mode 100644 index 7a02fa1..bfcabb3 *** a/contrib/pg_upgrade/pg_upgrade.h --- b/contrib/pg_upgrade/pg_upgrade.h *************** typedef struct *** 69,75 **** Oid reloid; /* relation oid */ Oid relfilenode; /* relation relfile node */ Oid toastrelid; /* oid of the toast relation */ ! char tablespace[MAXPGPATH]; /* relations tablespace path */ } RelInfo; typedef struct --- 69,76 ---- Oid reloid; /* relation oid */ Oid relfilenode; /* relation relfile node */ Oid toastrelid; /* oid of the toast relation */ ! /* relation tablespace path, or "" for the cluster default */ ! char tablespace[MAXPGPATH]; } RelInfo; typedef struct