diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 21de158adbb..c10667d32e5 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -137,6 +137,11 @@ static bool xact_started = false;
  */
 static bool DoingCommandRead = false;
 
+/*
+ * Flag to indicate that we're reading from stdin, in single-user mode.
+ */
+static bool DoingInteractiveRead = false;
+
 /*
  * Flags to implement skip-till-Sync-after-error behavior for messages of
  * the extended query protocol.
@@ -333,7 +338,9 @@ interactive_getc(void)
 	 */
 	CHECK_FOR_INTERRUPTS();
 
+	DoingInteractiveRead = true;
 	c = getc(stdin);
+	DoingInteractiveRead = false;
 
 	ProcessClientReadInterrupt(false);
 
@@ -3029,7 +3036,7 @@ die(SIGNAL_ARGS)
 	 * Rather ugly, but it's unlikely to be worthwhile to invest much more
 	 * effort just for the benefit of single user mode.
 	 */
-	if (DoingCommandRead && whereToSendOutput != DestRemote)
+	if (DoingInteractiveRead)
 		ProcessInterrupts();
 }
 
