diff --git a/contrib/pg_upgrade/tablespace.c b/contrib/pg_upgrade/tablespace.c
new file mode 100644
index 783ee93..5a3dc60
*** a/contrib/pg_upgrade/tablespace.c
--- b/contrib/pg_upgrade/tablespace.c
***************
*** 11,16 ****
--- 11,18 ----
  
  #include "pg_upgrade.h"
  
+ #include <sys/types.h>
+ 
  static void get_tablespace_paths(void);
  static void set_tablespace_directory_suffix(ClusterInfo *cluster);
  
*************** get_tablespace_paths(void)
*** 65,73 ****
--- 67,101 ----
  	i_spclocation = PQfnumber(res, "spclocation");
  
  	for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ 	{
+ 		struct stat statBuf;
+ 
  		os_info.old_tablespaces[tblnum] = pg_strdup(
  									 PQgetvalue(res, tblnum, i_spclocation));
  
+ 		/*
+ 		 * Check that the tablespace path exists and is a directory.
+ 		 * Effectively, this is checking only for tables/indexes in
+ 		 * non-existant tablespace directories.  Databases located in
+ 		 * non-existant tablespaces already throw a backend error.
+ 		 */
+ 		if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ 		{
+ 			if (errno == ENOENT)
+ 				report_status(PG_FATAL,
+ 							  "tablespace directory \"%s\" does not exist\n",
+ 							  os_info.old_tablespaces[tblnum]);
+ 			else
+ 				report_status(PG_FATAL,
+ 							  "cannot stat() tablespace directory \"%s\": %s\n",
+ 							  os_info.old_tablespaces[tblnum], getErrorText(errno));
+ 		}
+ 		if (!S_ISDIR(statBuf.st_mode))
+ 				report_status(PG_FATAL,
+ 							  "tablespace path \"%s\" is not a directory\n",
+ 							  os_info.old_tablespaces[tblnum]);
+ 	}
+ 
  	PQclear(res);
  
  	PQfinish(conn);
