@@ -306,6 +306,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
306
306
int i_relname = -1 ;
307
307
int i_oid = -1 ;
308
308
int i_relfilenode = -1 ;
309
+ int i_reltablespace = -1 ;
309
310
int i_reltoastrelid = -1 ;
310
311
char query [QUERY_ALLOC ];
311
312
@@ -320,7 +321,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
320
321
321
322
snprintf (query ,sizeof (query ),
322
323
"SELECT DISTINCT c.oid, n.nspname, c.relname, "
323
- "c.relfilenode, c.reltoastrelid, t.spclocation "
324
+ "c.relfilenode, c.reltoastrelid,c.reltablespace, t.spclocation "
324
325
"FROM pg_catalog.pg_class c JOIN "
325
326
"pg_catalog.pg_namespace n "
326
327
"ON c.relnamespace = n.oid "
@@ -339,7 +340,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
339
340
" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
340
341
"AND relkind IN ('r','t', 'i'%s)"
341
342
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
342
- "c.reltoastrelid, t.spclocation, "
343
+ "c.reltoastrelid,c.reltablespace, t.spclocation, "
343
344
"n.nspname "
344
345
"ORDER BY n.nspname, c.relname;" ,
345
346
FirstNormalObjectId ,
@@ -361,6 +362,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
361
362
i_relname = PQfnumber (res ,"relname" );
362
363
i_relfilenode = PQfnumber (res ,"relfilenode" );
363
364
i_reltoastrelid = PQfnumber (res ,"reltoastrelid" );
365
+ i_reltablespace = PQfnumber (res ,"reltablespace" );
364
366
i_spclocation = PQfnumber (res ,"spclocation" );
365
367
366
368
for (relnum = 0 ;relnum < ntups ;relnum ++ )
@@ -379,10 +381,13 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
379
381
curr -> relfilenode = atooid (PQgetvalue (res ,relnum ,i_relfilenode ));
380
382
curr -> toastrelid = atooid (PQgetvalue (res ,relnum ,i_reltoastrelid ));
381
383
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. */
385
389
tblspace = dbinfo -> db_tblspace ;
390
+
386
391
strlcpy (curr -> tablespace ,tblspace ,sizeof (curr -> tablespace ));
387
392
}
388
393
PQclear (res );