diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 6db223ab070d19eddd74e1bc5b5f5509041bc01e..be66b24cf20883c93b4c8dec5dcc6c54998012bd 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -532,7 +532,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 #endif
 
 	/* delete old cluster's default tablespace */
-	fprintf(script, RMDIR_CMD " \"%s\"\n", fix_path_separator(old_cluster.pgdata));
+	fprintf(script, RMDIR_CMD " %c%s%c\n", PATH_QUOTE,
+			fix_path_separator(old_cluster.pgdata), PATH_QUOTE);
 
 	/* delete old cluster's alternate tablespaces */
 	for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
@@ -554,9 +555,10 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 						PATH_SEPARATOR);
 
 			for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
-				fprintf(script, RMDIR_CMD " \"%s%c%d\"\n",
+				fprintf(script, RMDIR_CMD " %c%s%c%d%c\n", PATH_QUOTE,
 						fix_path_separator(os_info.old_tablespaces[tblnum]),
-						PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
+						PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid,
+						PATH_QUOTE);
 		}
 		else
 		{
@@ -566,9 +568,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",
+			fprintf(script, RMDIR_CMD " %c%s%s%c\n", PATH_QUOTE,
 					fix_path_separator(os_info.old_tablespaces[tblnum]),
-					fix_path_separator(suffix_path));
+					fix_path_separator(suffix_path), PATH_QUOTE);
 			pfree(suffix_path);
 		}
 	}
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 4683c6f71c3093f6d09f11c8a10358d9321613f6..bb035e18813dd1314919dd7e3193daae56298397 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -74,6 +74,7 @@ extern char *output_files[];
 #define pg_mv_file			rename
 #define pg_link_file		link
 #define PATH_SEPARATOR		'/'
+#define PATH_QUOTE	'\''
 #define RM_CMD				"rm -f"
 #define RMDIR_CMD			"rm -rf"
 #define SCRIPT_PREFIX		"./"
@@ -85,6 +86,7 @@ extern char *output_files[];
 #define pg_mv_file			pgrename
 #define pg_link_file		win32_pghardlink
 #define PATH_SEPARATOR		'\\'
+#define PATH_QUOTE	'"'
 #define RM_CMD				"DEL /q"
 #define RMDIR_CMD			"RMDIR /s/q"
 #define SCRIPT_PREFIX		""