On Fri, Dec 22, 2017 at 2:31 AM, Michael Paquier <michael.paqu...@gmail.com> wrote:
> On Thu, Dec 21, 2017 at 02:46:15PM +0100, Magnus Hagander wrote: > > On Thu, Dec 21, 2017 at 1:38 AM, Michael Paquier < > michael.paqu...@gmail.com> > > wrote: > >> I think that the call to pgstat_report_activity in WalSndLoop() should > >> be kept as well. There is a small gap between the moment the process > >> is started and the first replication command is run. > >> > > > > Eh. But WalSndLoop() is called *after* exec_replication_command(), isn't > > it? exec_replication_command() is called from PostgresMain(), and then > > calls WalSndLoop(). > > > > So I agree there is a small gap, but actually moving it to > > exec_replication_command() makes that gap smaller than it was before, no? > > My turn to read things wrong then, thinking that WalSndLoop() was the > main routine used for starting the WAL sender process. You are right > removing > the call there is adapted. > > Could you update the patch? > I thought I had, but I can see now that email was a figment of my imagination :) PFA an actual patch. -- Magnus Hagander Me: https://www.hagander.net/ <http://www.hagander.net/> Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 6a252fcf45..f2e886f99f 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1504,6 +1504,9 @@ exec_replication_command(const char *cmd_string) initStringInfo(&reply_message); initStringInfo(&tmpbuf); + /* Report to pgstat that this process is running */ + pgstat_report_activity(STATE_RUNNING, NULL); + switch (cmd_node->type) { case T_IdentifySystemCmd: @@ -1555,6 +1558,9 @@ exec_replication_command(const char *cmd_string) ereport(ERROR, (errmsg("cannot execute SQL commands in WAL sender for physical replication"))); + /* Report to pgstat that this process is now idle */ + pgstat_report_activity(STATE_IDLE, NULL); + /* Tell the caller that this wasn't a WalSender command. */ return false; @@ -1570,6 +1576,9 @@ exec_replication_command(const char *cmd_string) /* Send CommandComplete message */ EndCommand("SELECT", DestRemote); + /* Report to pgstat that this process is now idle */ + pgstat_report_activity(STATE_IDLE, NULL); + return true; } @@ -2089,9 +2098,6 @@ WalSndLoop(WalSndSendDataCallback send_data) last_reply_timestamp = GetCurrentTimestamp(); waiting_for_ping_response = false; - /* Report to pgstat that this process is running */ - pgstat_report_activity(STATE_RUNNING, NULL); - /* * Loop until we reach the end of this timeline or the client requests to * stop streaming.