diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
index aa896b5..32d1e61 100644
--- a/contrib/pg_upgrade/check.c
+++ b/contrib/pg_upgrade/check.c
@@ -23,6 +23,36 @@ static void check_for_reg_data_type_usage(ClusterInfo *cluster);
 static void get_bin_version(ClusterInfo *cluster);
 
 
+/*
+ * fix_path
+ * combine two path segements, ignore second if it is NULL.
+ * For Windows convert to using backslashes such as is
+ * suitable for builtin commands like RMDIR and DEL
+ */
+static inline char *fix_path(char *p1, char *p2)
+{
+	char * result;
+	int len = strlen(p1) + (p2 == NULL ? 0 : strlen(p2));
+	int end;
+#ifdef WIN32
+	int i;
+#endif
+
+	result = pg_malloc(len+1);
+	end = strlcpy(result,p1,len+1);
+	if (p2 != NULL)
+		strlcpy(result + end,p2,len + 1 - end);
+
+#ifdef WIN32
+	for (i = 0; i < len; i++)
+		if (result[i] == '/')
+			result[i] = '\\';
+#endif
+	
+	return result;
+}
+
+
 void
 output_check_banner(bool *live_check)
 {
@@ -547,7 +577,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 #endif
 
 	/* delete old cluster's default tablespace */
-	fprintf(script, RMDIR_CMD " %s\n", old_cluster.pgdata);
+	fprintf(script, RMDIR_CMD " %s\n", fix_path(old_cluster.pgdata, NULL));
 
 	/* delete old cluster's alternate tablespaces */
 	for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
@@ -564,14 +594,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 			fprintf(script, "\n");
 			/* remove PG_VERSION? */
 			if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
-				fprintf(script, RM_CMD " %s%s/PG_VERSION\n",
-				 os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
+				fprintf(script, RM_CMD " %s%cPG_VERSION\n",
+						fix_path(os_info.tablespaces[tblnum], 
+								 old_cluster.tablespace_suffix),
+						PATH_SEPARATOR);
 
 			for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
 			{
-				fprintf(script, RMDIR_CMD " %s%s/%d\n",
-				  os_info.tablespaces[tblnum], old_cluster.tablespace_suffix,
-						old_cluster.dbarr.dbs[dbnum].db_oid);
+				fprintf(script, RMDIR_CMD " %s%c%d\n",
+						fix_path(os_info.tablespaces[tblnum], 
+								 old_cluster.tablespace_suffix),
+						PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
 			}
 		}
 		else
@@ -580,8 +613,9 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 			 * Simply delete the tablespace directory, which might be ".old"
 			 * or a version-specific subdirectory.
 			 */
-			fprintf(script, RMDIR_CMD " %s%s\n",
-				 os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
+			fprintf(script, RMDIR_CMD " %s\n",
+					fix_path(os_info.tablespaces[tblnum], 
+							 old_cluster.tablespace_suffix));
 	}
 
 	fclose(script);
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
index 77c7150..4a18497 100644
--- a/contrib/pg_upgrade/pg_upgrade.h
+++ b/contrib/pg_upgrade/pg_upgrade.h
@@ -72,6 +72,7 @@ extern char *output_files[];
 #define pg_copy_file		copy_file
 #define pg_mv_file			rename
 #define pg_link_file		link
+#define PATH_SEPARATOR      '/'
 #define RM_CMD				"rm -f"
 #define RMDIR_CMD			"rm -rf"
 #define SCRIPT_EXT			"sh"
@@ -81,6 +82,7 @@ extern char *output_files[];
 #define pg_mv_file			pgrename
 #define pg_link_file		win32_pghardlink
 #define sleep(x)			Sleep(x * 1000)
+#define PATH_SEPARATOR      '\\'
 #define RM_CMD				"DEL /q"
 #define RMDIR_CMD			"RMDIR /s/q"
 #define SCRIPT_EXT			"bat"
