diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
new file mode 100644
index 3ef3429..10188ca
*** a/contrib/pg_upgrade/info.c
--- b/contrib/pg_upgrade/info.c
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 266,274 ****
  			 "  LEFT OUTER JOIN pg_catalog.pg_tablespace t "
  			 "	   ON c.reltablespace = t.oid "
  			 "WHERE relkind IN ('r','t', 'i'%s) AND "
! 			 /* exclude pg_catalog and pg_temp_ (could be orphaned tables) */
! 			 "  ((n.nspname !~ '^pg_' AND "
! 			"     n.nspname NOT IN ('information_schema', 'binary_upgrade') AND "
  			 "	  c.oid >= %u) "
  			 "  OR (n.nspname = 'pg_catalog' AND "
  	"    relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
--- 266,275 ----
  			 "  LEFT OUTER JOIN pg_catalog.pg_tablespace t "
  			 "	   ON c.reltablespace = t.oid "
  			 "WHERE relkind IN ('r','t', 'i'%s) AND "
! 			 /* exclude possible orphaned temp tables */
! 			 "  ((n.nspname !~ '^pg_temp_' AND "
! 			 "    n.nspname !~ '^pg_toast_temp_' AND "
! 			 "    n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') AND "
  			 "	  c.oid >= %u) "
  			 "  OR (n.nspname = 'pg_catalog' AND "
  	"    relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
diff --git a/contrib/pg_upgrade/version_old_8_3.c b/contrib/pg_upgrade/version_old_8_3.c
new file mode 100644
index 1c736d2..d63050c
*** a/contrib/pg_upgrade/version_old_8_3.c
--- b/contrib/pg_upgrade/version_old_8_3.c
*************** old_8_3_check_for_name_data_type_usage(C
*** 59,67 ****
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.name'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 							 /* exclude pg_catalog and pg_temp_ (could be orphaned tables) */
! 								"   n.nspname !~ '^pg_' AND "
! 						 "		n.nspname != 'information_schema'");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
--- 59,68 ----
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.name'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 								 /* exclude possible orphaned temp tables */
! 								"  		n.nspname !~ '^pg_temp_' AND "
! 								"		n.nspname !~ '^pg_toast_temp_' AND "
! 						 		"		n.nspname NOT IN ('pg_catalog', 'information_schema')");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
*************** old_8_3_check_for_tsquery_usage(ClusterI
*** 149,157 ****
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.tsquery'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 							 /* exclude pg_catalog and pg_temp_ (could be orphaned tables) */
! 								"   n.nspname !~ '^pg_' AND "
! 						 "		n.nspname != 'information_schema'");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
--- 150,159 ----
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.tsquery'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 								 /* exclude possible orphaned temp tables */
! 								"  		n.nspname !~ '^pg_temp_' AND "
! 								"		n.nspname !~ '^pg_toast_temp_' AND "
! 						 		"		n.nspname NOT IN ('pg_catalog', 'information_schema')");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
*************** old_8_3_rebuild_tsvector_tables(ClusterI
*** 247,255 ****
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.tsvector'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 							 /* exclude pg_catalog and pg_temp_ (could be orphaned tables) */
! 								"   n.nspname !~ '^pg_' AND "
! 						 "		n.nspname != 'information_schema'");
  
  /*
   *	This macro is used below to avoid reindexing indexes already rebuilt
--- 249,258 ----
  								"		NOT a.attisdropped AND "
  								"		a.atttypid = 'pg_catalog.tsvector'::pg_catalog.regtype AND "
  								"		c.relnamespace = n.oid AND "
! 								 /* exclude possible orphaned temp tables */
! 								"  		n.nspname !~ '^pg_temp_' AND "
! 								"		n.nspname !~ '^pg_toast_temp_' AND "
! 						 		"		n.nspname NOT IN ('pg_catalog', 'information_schema')");
  
  /*
   *	This macro is used below to avoid reindexing indexes already rebuilt
*************** old_8_3_create_sequence_script(ClusterIn
*** 619,627 ****
  								"		pg_catalog.pg_namespace n "
  								"WHERE	c.relkind = 'S' AND "
  								"		c.relnamespace = n.oid AND "
! 							 /* exclude pg_catalog and pg_temp_ (could be orphaned tables) */
! 								"   n.nspname !~ '^pg_' AND "
! 						 "		n.nspname != 'information_schema'");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
--- 622,631 ----
  								"		pg_catalog.pg_namespace n "
  								"WHERE	c.relkind = 'S' AND "
  								"		c.relnamespace = n.oid AND "
! 								 /* exclude possible orphaned temp tables */
! 								"  		n.nspname !~ '^pg_temp_' AND "
! 								"		n.nspname !~ '^pg_toast_temp_' AND "
! 						 		"		n.nspname NOT IN ('pg_catalog', 'information_schema')");
  
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
