diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 67093383e6..a34c5745de 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1619,19 +1619,23 @@ exec_replication_command(const char *cmd_string)
 	switch (cmd_node->type)
 	{
 		case T_IdentifySystemCmd:
+			set_ps_display("IDENTIFY_SYSTEM");
 			IdentifySystem();
 			break;
 
 		case T_BaseBackupCmd:
+			set_ps_display("BASE_BACKUP");
 			PreventInTransactionBlock(true, "BASE_BACKUP");
 			SendBaseBackup((BaseBackupCmd *) cmd_node);
 			break;
 
 		case T_CreateReplicationSlotCmd:
+			set_ps_display("CREATE_REPLICATION_SLOT");
 			CreateReplicationSlot((CreateReplicationSlotCmd *) cmd_node);
 			break;
 
 		case T_DropReplicationSlotCmd:
+			set_ps_display("DROP_REPLICATION_SLOT");
 			DropReplicationSlot((DropReplicationSlotCmd *) cmd_node);
 			break;
 
@@ -1639,6 +1643,7 @@ exec_replication_command(const char *cmd_string)
 			{
 				StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node;
 
+				set_ps_display("START_REPLICATION");
 				PreventInTransactionBlock(true, "START_REPLICATION");
 
 				if (cmd->kind == REPLICATION_KIND_PHYSICAL)
@@ -1651,6 +1656,7 @@ exec_replication_command(const char *cmd_string)
 			}
 
 		case T_TimeLineHistoryCmd:
+			set_ps_display("TIMELINE_HISTORY");
 			PreventInTransactionBlock(true, "TIMELINE_HISTORY");
 			SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node);
 			break;
@@ -1660,6 +1666,7 @@ exec_replication_command(const char *cmd_string)
 				DestReceiver *dest = CreateDestReceiver(DestRemoteSimple);
 				VariableShowStmt *n = (VariableShowStmt *) cmd_node;
 
+				set_ps_display("SHOW");
 				/* syscache access needs a transaction environment */
 				StartTransactionCommand();
 				GetPGVariable(n->name, dest);
@@ -1680,8 +1687,11 @@ exec_replication_command(const char *cmd_string)
 	SetQueryCompletion(&qc, CMDTAG_SELECT, 0);
 	EndCommand(&qc, DestRemote, true);
 
-	/* Report to pgstat that this process is now idle */
-	pgstat_report_activity(STATE_IDLE, NULL);
+	/*
+	 * We need not update ps display or pg_stat_activity, because PostgresMain
+	 * will reset those to "idle".  But we must reset debug_query_string to
+	 * ensure it doesn't become a dangling pointer.
+	 */
 	debug_query_string = NULL;
 
 	return true;
