diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index c0c5524af53c8d96a9b5b168ac7627b2c104daf2..2bc065adcff044155b04dc65eafc65aa50592db0 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -341,8 +341,10 @@ initializeInput(int flags)
 		char		home[MAXPGPATH];
 
 		useReadline = true;
-		rl_initialize();
+
+		/* these two things must be done in this order: */
 		initialize_readline();
+		rl_initialize();
 
 		useHistory = true;
 		using_history();