@@ -269,34 +269,59 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
269269 */
270270
271271snprintf (query ,sizeof (query ),
272- "SELECT c.oid, n.nspname, c.relname, "
273- "c.relfilenode, c.reltablespace, %s "
272+ "CREATE TEMPORARY TABLE info_rels (reloid) AS SELECT c.oid "
274273"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
275274" ON c.relnamespace = n.oid "
276- " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
277- " ON c.reltablespace = t.oid "
278- "WHERE relkind IN ('r','t', 'i'%s) AND "
275+ "WHERE relkind IN ('r', 'i'%s) AND "
279276/* exclude possible orphaned temp tables */
280277" ((n.nspname !~ '^pg_temp_' AND "
281278" n.nspname !~ '^pg_toast_temp_' AND "
282- " n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') AND "
279+ /* skip pg_toast because toast index have relkind == 'i', not 't' */
280+ " n.nspname NOT IN ('pg_catalog', 'information_schema', "
281+ "'binary_upgrade', 'pg_toast') AND "
283282" c.oid >= %u) "
284283" OR (n.nspname = 'pg_catalog' AND "
285- " relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
286- /* we preserve pg_class.oid so we sort by it to match old/new */
287- "ORDER BY 1;" ,
288- /* 9.2 removed the spclocation column */
289- (GET_MAJOR_VERSION (cluster -> major_version ) <=901 ) ?
290- "t.spclocation" :"pg_catalog.pg_tablespace_location(t.oid) AS spclocation" ,
284+ " relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) ));" ,
291285/* see the comment at the top of old_8_3_create_sequence_script() */
292286 (GET_MAJOR_VERSION (old_cluster .major_version ) <=803 ) ?
293287"" :", 'S'" ,
294- /* this oid allows us to skip system toast tables */
295288FirstNormalObjectId ,
296289/* does pg_largeobject_metadata need to be migrated? */
297290 (GET_MAJOR_VERSION (old_cluster .major_version ) <=804 ) ?
298291"" :", 'pg_largeobject_metadata', 'pg_largeobject_metadata_oid_index'" );
299292
293+ PQclear (executeQueryOrDie (conn ,"%s" ,query ));
294+
295+ /*
296+ *Get TOAST tables and indexes; we have to gather the TOAST tables in
297+ *later steps because we can't schema-qualify TOAST tables.
298+ */
299+ PQclear (executeQueryOrDie (conn ,
300+ "INSERT INTO info_rels "
301+ "SELECT reltoastrelid "
302+ "FROM info_rels i JOIN pg_catalog.pg_class c "
303+ "ON i.reloid = c.oid" ));
304+ PQclear (executeQueryOrDie (conn ,
305+ "INSERT INTO info_rels "
306+ "SELECT reltoastidxid "
307+ "FROM info_rels i JOIN pg_catalog.pg_class c "
308+ "ON i.reloid = c.oid" ));
309+
310+ snprintf (query ,sizeof (query ),
311+ "SELECT c.oid, n.nspname, c.relname, "
312+ "c.relfilenode, c.reltablespace, %s "
313+ "FROM info_rels i JOIN pg_catalog.pg_class c "
314+ "ON i.reloid = c.oid "
315+ " JOIN pg_catalog.pg_namespace n "
316+ " ON c.relnamespace = n.oid "
317+ " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
318+ " ON c.reltablespace = t.oid "
319+ /* we preserve pg_class.oid so we sort by it to match old/new */
320+ "ORDER BY 1;" ,
321+ /* 9.2 removed the spclocation column */
322+ (GET_MAJOR_VERSION (cluster -> major_version ) <=901 ) ?
323+ "t.spclocation" :"pg_catalog.pg_tablespace_location(t.oid) AS spclocation" );
324+
300325res = executeQueryOrDie (conn ,"%s" ,query );
301326
302327ntups = PQntuples (res );