diff --git a/configure b/configure
index 8c61390ca778dbbce56cd60198beb3f6982efbb0..5772d0e9c4c839005c4bd92f712386e0fd61ae1b 100755
--- a/configure
+++ b/configure
@@ -13232,7 +13232,7 @@ if test x"$pgac_cv_var_rl_completion_append_character" = x"yes"; then
 $as_echo "#define HAVE_RL_COMPLETION_APPEND_CHARACTER 1" >>confdefs.h
 
 fi
-  for ac_func in rl_completion_matches rl_filename_completion_function
+  for ac_func in rl_completion_matches rl_filename_completion_function rl_reset_screen_size
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.in b/configure.in
index b5868b04d289be439fcce09626789c7651e84887..44f832f14963c388ea518c5671be6d9c8da274e0 100644
--- a/configure.in
+++ b/configure.in
@@ -1635,7 +1635,7 @@ LIBS="$LIBS_including_readline"
 
 if test "$with_readline" = yes; then
   PGAC_VAR_RL_COMPLETION_APPEND_CHARACTER
-  AC_CHECK_FUNCS([rl_completion_matches rl_filename_completion_function])
+  AC_CHECK_FUNCS([rl_completion_matches rl_filename_completion_function rl_reset_screen_size])
   AC_CHECK_FUNCS([append_history history_truncate_file])
 fi
 
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index e3771040072f6ad4bf10cfff7336cd397cb7a004..c0c5524af53c8d96a9b5b168ac7627b2c104daf2 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -65,6 +65,17 @@ gets_interactive(const char *prompt)
 	{
 		char	   *result;
 
+		/*
+		 * Some versions of readline don't notice SIGWINCH signals that arrive
+		 * when not actively reading input.  The simplest fix is to always
+		 * re-read the terminal size.  This leaves a window for SIGWINCH to be
+		 * missed between here and where readline() enables libreadline's
+		 * signal handler, but that's probably short enough to be ignored.
+		 */
+#ifdef HAVE_RL_RESET_SCREEN_SIZE
+		rl_reset_screen_size();
+#endif
+
 		/* Enable SIGINT to longjmp to sigint_interrupt_jmp */
 		sigint_interrupt_enabled = true;
 
@@ -330,6 +341,7 @@ initializeInput(int flags)
 		char		home[MAXPGPATH];
 
 		useReadline = true;
+		rl_initialize();
 		initialize_readline();
 
 		useHistory = true;
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index a20e0cd1d667cf0a2f18676fccbbdfdb0edc6701..16a272efdee0337d156db55ee8ca708bd19b1edc 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -428,6 +428,9 @@
 /* Define to 1 if you have the `rl_filename_completion_function' function. */
 #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION
 
+/* Define to 1 if you have the `rl_reset_screen_size' function. */
+#undef HAVE_RL_RESET_SCREEN_SIZE
+
 /* Define to 1 if you have the <security/pam_appl.h> header file. */
 #undef HAVE_SECURITY_PAM_APPL_H