Teach walsender to update its process title for replication commands.

Because the code path taken for SQL commands executed in a walsender
will update the process title, we pretty much have to update the
title for replication commands as well.  Otherwise, the title shows
"idle" for the rest of a logical walsender's lifetime once it's
executed any SQL command.

Playing with this, I confirm that a walsender now typically spends
most of its life reporting
	walsender postgres [local] START_REPLICATION
Considering this in isolation, it might be better to have it say
	walsender postgres [local] sending replication data
However, consistency with the other cases seems to be a stronger
argument.

In passing, remove duplicative pgstat_report_activity call.

Discussion: https://postgr.es/m/880181.1600026471@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2020-09-16 21:06:50 -04:00
parent add105840b
commit babef40c9a
1 changed files with 12 additions and 2 deletions

View File

@ -1616,12 +1616,14 @@ exec_replication_command(const char *cmd_string)
{ {
case T_IdentifySystemCmd: case T_IdentifySystemCmd:
cmdtag = "IDENTIFY_SYSTEM"; cmdtag = "IDENTIFY_SYSTEM";
set_ps_display(cmdtag);
IdentifySystem(); IdentifySystem();
EndReplicationCommand(cmdtag); EndReplicationCommand(cmdtag);
break; break;
case T_BaseBackupCmd: case T_BaseBackupCmd:
cmdtag = "BASE_BACKUP"; cmdtag = "BASE_BACKUP";
set_ps_display(cmdtag);
PreventInTransactionBlock(true, cmdtag); PreventInTransactionBlock(true, cmdtag);
SendBaseBackup((BaseBackupCmd *) cmd_node); SendBaseBackup((BaseBackupCmd *) cmd_node);
EndReplicationCommand(cmdtag); EndReplicationCommand(cmdtag);
@ -1629,12 +1631,14 @@ exec_replication_command(const char *cmd_string)
case T_CreateReplicationSlotCmd: case T_CreateReplicationSlotCmd:
cmdtag = "CREATE_REPLICATION_SLOT"; cmdtag = "CREATE_REPLICATION_SLOT";
set_ps_display(cmdtag);
CreateReplicationSlot((CreateReplicationSlotCmd *) cmd_node); CreateReplicationSlot((CreateReplicationSlotCmd *) cmd_node);
EndReplicationCommand(cmdtag); EndReplicationCommand(cmdtag);
break; break;
case T_DropReplicationSlotCmd: case T_DropReplicationSlotCmd:
cmdtag = "DROP_REPLICATION_SLOT"; cmdtag = "DROP_REPLICATION_SLOT";
set_ps_display(cmdtag);
DropReplicationSlot((DropReplicationSlotCmd *) cmd_node); DropReplicationSlot((DropReplicationSlotCmd *) cmd_node);
EndReplicationCommand(cmdtag); EndReplicationCommand(cmdtag);
break; break;
@ -1644,6 +1648,7 @@ exec_replication_command(const char *cmd_string)
StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node; StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node;
cmdtag = "START_REPLICATION"; cmdtag = "START_REPLICATION";
set_ps_display(cmdtag);
PreventInTransactionBlock(true, cmdtag); PreventInTransactionBlock(true, cmdtag);
if (cmd->kind == REPLICATION_KIND_PHYSICAL) if (cmd->kind == REPLICATION_KIND_PHYSICAL)
@ -1659,6 +1664,7 @@ exec_replication_command(const char *cmd_string)
case T_TimeLineHistoryCmd: case T_TimeLineHistoryCmd:
cmdtag = "TIMELINE_HISTORY"; cmdtag = "TIMELINE_HISTORY";
set_ps_display(cmdtag);
PreventInTransactionBlock(true, cmdtag); PreventInTransactionBlock(true, cmdtag);
SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node); SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node);
EndReplicationCommand(cmdtag); EndReplicationCommand(cmdtag);
@ -1670,6 +1676,7 @@ exec_replication_command(const char *cmd_string)
VariableShowStmt *n = (VariableShowStmt *) cmd_node; VariableShowStmt *n = (VariableShowStmt *) cmd_node;
cmdtag = "SHOW"; cmdtag = "SHOW";
set_ps_display(cmdtag);
/* syscache access needs a transaction environment */ /* syscache access needs a transaction environment */
StartTransactionCommand(); StartTransactionCommand();
@ -1688,8 +1695,11 @@ exec_replication_command(const char *cmd_string)
MemoryContextSwitchTo(old_context); MemoryContextSwitchTo(old_context);
MemoryContextDelete(cmd_context); MemoryContextDelete(cmd_context);
/* 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; debug_query_string = NULL;
return true; return true;