diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
index d52051a6e9981ece81ec66655182c2bb800d0bde..f04707f9c6f510349ad3375d47ebf18a8cf04ee8 100644
--- a/contrib/pg_upgrade/check.c
+++ b/contrib/pg_upgrade/check.c
@@ -437,8 +437,14 @@ equivalent_locale(const char *loca, const char *locb)
 	if (!chara || !charb)
 		return (pg_strcasecmp(loca, locb) == 0);
 
-	/* Compare the encoding parts. */
-	if (!equivalent_encoding(chara + 1, charb + 1))
+	/*
+	 * Compare the encoding parts.	Windows tends to use code page numbers for
+	 * the encoding part, which equivalent_encoding() won't like, so accept if
+	 * the strings are case-insensitive equal; otherwise use
+	 * equivalent_encoding() to compare.
+	 */
+	if (pg_strcasecmp(chara + 1, charb + 1) != 0 &&
+		!equivalent_encoding(chara + 1, charb + 1))
 		return false;
 
 	/*