diff --git a/configure b/configure
index 8d5b44e8b3b88c3b42a98e4a55adbaf01314dc9a..9cf410ba67dc3c3b4d6afbe15be33e42f42c4812 100755
--- a/configure
+++ b/configure
@@ -13408,6 +13408,28 @@ _ACEOF
 fi
 done
 
+# strto[u]ll may exist but not be declared
+ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_includes_default"
+if test "x$ac_cv_have_decl_strtoll" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_STRTOLL $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_includes_default"
+if test "x$ac_cv_have_decl_strtoull" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_STRTOULL $ac_have_decl
+_ACEOF
+
 
 # Lastly, restore full LIBS list and check for readline/libedit symbols
 LIBS="$LIBS_including_readline"
diff --git a/configure.in b/configure.in
index 8c90daca82263cafaaf1ac3752d370b55dd06fce..f3cb696bb420388424332569eae3c5fa49b12e47 100644
--- a/configure.in
+++ b/configure.in
@@ -1686,6 +1686,8 @@ fi
 
 AC_CHECK_FUNCS([strtoll strtoq], [break])
 AC_CHECK_FUNCS([strtoull strtouq], [break])
+# strto[u]ll may exist but not be declared
+AC_CHECK_DECLS([strtoll, strtoull])
 
 # Lastly, restore full LIBS list and check for readline/libedit symbols
 LIBS="$LIBS_including_readline"
diff --git a/src/include/c.h b/src/include/c.h
index 3a569c8060296928d1d03c8c85ef3518aceeddea..18f6db275a3a8075695575f74a3b7574de02bdba 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1056,6 +1056,14 @@ extern int	snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_p
 extern int	vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 #endif
 
+#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
+extern long long strtoll(const char *str, char **endptr, int base);
+#endif
+
+#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
+extern unsigned long long strtoull(const char *str, char **endptr, int base);
+#endif
+
 #if !defined(HAVE_MEMMOVE) && !defined(memmove)
 #define memmove(d, s, c)		bcopy(s, d, c)
 #endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index aa569c525948fa380df98c2c3112aa7a11cb513d..11556f2ef4b674be41cb0a4924cb3321edf769bd 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -144,6 +144,14 @@
    don't. */
 #undef HAVE_DECL_STRLCPY
 
+/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
+   don't. */
+#undef HAVE_DECL_STRTOLL
+
+/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
+   don't. */
+#undef HAVE_DECL_STRTOULL
+
 /* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
    don't. */
 #undef HAVE_DECL_SYS_SIGLIST
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 97fc757b1ed3ae538e37ff9c876ea06ff4d5d3e2..4312422e3017937de3efb25c2ea2fa69c614934d 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -96,6 +96,14 @@
    don't. */
 #define HAVE_DECL_SNPRINTF 1
 
+/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRTOLL 1
+
+/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRTOULL 1
+
 /* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
    don't. */
 #define HAVE_DECL_VSNPRINTF 1