@@ -306,6 +306,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
306306int i_relname = -1 ;
307307int i_oid = -1 ;
308308int i_relfilenode = -1 ;
309+ int i_reltablespace = -1 ;
309310int i_reltoastrelid = -1 ;
310311char query [QUERY_ALLOC ];
311312
@@ -320,7 +321,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
320321
321322snprintf (query ,sizeof (query ),
322323"SELECT DISTINCT c.oid, n.nspname, c.relname, "
323- "c.relfilenode, c.reltoastrelid, t.spclocation "
324+ "c.relfilenode, c.reltoastrelid,c.reltablespace, t.spclocation "
324325"FROM pg_catalog.pg_class c JOIN "
325326"pg_catalog.pg_namespace n "
326327"ON c.relnamespace = n.oid "
@@ -339,7 +340,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
339340" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
340341"AND relkind IN ('r','t', 'i'%s)"
341342"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
342- "c.reltoastrelid, t.spclocation, "
343+ "c.reltoastrelid,c.reltablespace, t.spclocation, "
343344"n.nspname "
344345"ORDER BY n.nspname, c.relname;" ,
345346FirstNormalObjectId ,
@@ -361,6 +362,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
361362i_relname = PQfnumber (res ,"relname" );
362363i_relfilenode = PQfnumber (res ,"relfilenode" );
363364i_reltoastrelid = PQfnumber (res ,"reltoastrelid" );
365+ i_reltablespace = PQfnumber (res ,"reltablespace" );
364366i_spclocation = PQfnumber (res ,"spclocation" );
365367
366368for (relnum = 0 ;relnum < ntups ;relnum ++ )
@@ -379,10 +381,13 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
379381curr -> relfilenode = atooid (PQgetvalue (res ,relnum ,i_relfilenode ));
380382curr -> toastrelid = atooid (PQgetvalue (res ,relnum ,i_reltoastrelid ));
381383
382- tblspace = PQgetvalue (res ,relnum ,i_spclocation );
383- /* if no table tablespace, use the database tablespace */
384- if (strlen (tblspace )== 0 )
384+ if (atooid (PQgetvalue (res ,relnum ,i_reltablespace ))!= 0 )
385+ /* Might be "", meaning the cluster default location. */
386+ tblspace = PQgetvalue (res ,relnum ,i_spclocation );
387+ else
388+ /* A zero reltablespace indicates the database tablespace. */
385389tblspace = dbinfo -> db_tblspace ;
390+
386391strlcpy (curr -> tablespace ,tblspace ,sizeof (curr -> tablespace ));
387392}
388393PQclear (res );