diff --git a/configure b/configure
index 1e69edacde66dbdef7d34b958dd318c85e0d3383..ddb3c8b1ba1f7b6a81c4112841cfcef642be2524 100755
--- a/configure
+++ b/configure
@@ -15942,6 +15942,17 @@ fi
 
 # Win32 (really MinGW) support
 if test "$PORTNAME" = "win32"; then
+  for ac_func in _configthreadlocale
+do :
+  ac_fn_c_check_func "$LINENO" "_configthreadlocale" "ac_cv_func__configthreadlocale"
+if test "x$ac_cv_func__configthreadlocale" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE__CONFIGTHREADLOCALE 1
+_ACEOF
+
+fi
+done
+
   ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
 if test "x$ac_cv_func_gettimeofday" = xyes; then :
   $as_echo "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h
diff --git a/configure.in b/configure.in
index 556186cf2d43e6dcbba232fd1651f09b1554a2ba..3d8888805cc7e4f8be10139d2a155761da19304d 100644
--- a/configure.in
+++ b/configure.in
@@ -1754,6 +1754,7 @@ fi
 
 # Win32 (really MinGW) support
 if test "$PORTNAME" = "win32"; then
+  AC_CHECK_FUNCS(_configthreadlocale)
   AC_REPLACE_FUNCS(gettimeofday)
   AC_LIBOBJ(dirmod)
   AC_LIBOBJ(kill)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 2c899a15692b06f5431362df1c47b91b9c9c7554..82547f321f3b1788cad6d976c950e13bf4562af1 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -757,6 +757,9 @@
 /* Define to 1 if your compiler understands __builtin_unreachable. */
 #undef HAVE__BUILTIN_UNREACHABLE
 
+/* Define to 1 if you have the `_configthreadlocale' function. */
+#undef HAVE__CONFIGTHREADLOCALE
+
 /* Define to 1 if you have __cpuid. */
 #undef HAVE__CPUID
 
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 396443386a255108bed3d5969dd0712bc42c4325..a3c44f0fd80b20863c288f9520064ddbc65c3054 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -596,6 +596,9 @@
 /* Define to 1 if your compiler understands __builtin_unreachable. */
 /* #undef HAVE__BUILTIN_UNREACHABLE */
 
+/* Define to 1 if you have the `_configthreadlocale' function. */
+#define HAVE__CONFIGTHREADLOCALE 1
+
 /* Define to 1 if you have __cpuid. */
 #define HAVE__CPUID 1
 
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 71cef1517247cf8b61faea68a1d6e34f0939bee4..aeb33636607911eb3fc6c2236740b8e647ac6294 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -495,7 +495,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
 		if (stmt.clocale != (locale_t) 0)
 			stmt.oldlocale = uselocale(stmt.clocale);
 #else
-#ifdef WIN32
+#ifdef HAVE__CONFIGTHREADLOCALE
 		stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
 #endif
 		stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
@@ -517,7 +517,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
 			setlocale(LC_NUMERIC, stmt.oldlocale);
 			ecpg_free(stmt.oldlocale);
 		}
-#ifdef WIN32
+#ifdef HAVE__CONFIGTHREADLOCALE
 		if (stmt.oldthreadlocale != -1)
 			_configthreadlocale(stmt.oldthreadlocale);
 #endif
diff --git a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
index 41851d59007466ba02418ea75be4e7e368c71677..ae2dcfc617286c704c5e5a327b6f09efb7c503b5 100644
--- a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
+++ b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
@@ -69,7 +69,7 @@ struct statement
 	locale_t	oldlocale;
 #else
 	char	   *oldlocale;
-#ifdef WIN32
+#ifdef HAVE__CONFIGTHREADLOCALE
 	int			oldthreadlocale;
 #endif
 #endif
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 81aaf10f0886a8a4f958c753101d54f14e4737a7..a9f945e6188d65706ec09f78fe05f0c0c2fa6d66 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1778,7 +1778,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
 	 * Make sure we do NOT honor the locale for numeric input/output since the
 	 * database wants the standard decimal point.  If available, use
 	 * uselocale() for this because it's thread-safe.  Windows doesn't have
-	 * that, but it does have _configthreadlocale().
+	 * that, but it usually does have _configthreadlocale().
 	 */
 #ifdef HAVE_USELOCALE
 	stmt->clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
@@ -1794,7 +1794,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
 		return false;
 	}
 #else
-#ifdef WIN32
+#ifdef HAVE__CONFIGTHREADLOCALE
 	stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
 	if (stmt->oldthreadlocale == -1)
 	{
@@ -2019,7 +2019,7 @@ ecpg_do_epilogue(struct statement *stmt)
 	if (stmt->oldlocale)
 	{
 		setlocale(LC_NUMERIC, stmt->oldlocale);
-#ifdef WIN32
+#ifdef HAVE__CONFIGTHREADLOCALE
 		_configthreadlocale(stmt->oldthreadlocale);
 #endif
 	}