@@ -2520,7 +2520,7 @@ pgstat_beshutdown_hook(int code, Datum arg)
2520
2520
* pgstat_report_activity() -
2521
2521
*
2522
2522
* Called from tcop/postgres.c to report what the backend is actually doing
2523
- * (usually "<IDLE>" or the start of the query to be executed ).
2523
+ * (but note cmd_str can be NULL for certain cases ).
2524
2524
*
2525
2525
* All updates of the status entry follow the protocol of bumping
2526
2526
* st_changecount before and after. We use a volatile pointer here to
@@ -2540,36 +2540,40 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2540
2540
if (!beentry )
2541
2541
return ;
2542
2542
2543
- /*
2544
- * To minimize the time spent modifying the entry, fetch all the needed
2545
- * data first.
2546
- */
2547
- current_timestamp = GetCurrentTimestamp ();
2548
-
2549
- if (!pgstat_track_activities && beentry -> st_state != STATE_DISABLED )
2543
+ if (!pgstat_track_activities )
2550
2544
{
2551
- /*
2552
- * Track activities is disabled, but we have a non-disabled state set.
2553
- * That means the status changed - so as our last update, tell the
2554
- * collector that we disabled it and will no longer update.
2555
- */
2556
- beentry -> st_changecount ++ ;
2557
- beentry -> st_state = STATE_DISABLED ;
2558
- beentry -> st_state_start_timestamp = current_timestamp ;
2559
- beentry -> st_changecount ++ ;
2560
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2545
+ if (beentry -> st_state != STATE_DISABLED )
2546
+ {
2547
+ /*
2548
+ * track_activities is disabled, but we last reported a
2549
+ * non-disabled state. As our final update, change the state and
2550
+ * clear fields we will not be updating anymore.
2551
+ */
2552
+ beentry -> st_changecount ++ ;
2553
+ beentry -> st_state = STATE_DISABLED ;
2554
+ beentry -> st_state_start_timestamp = 0 ;
2555
+ beentry -> st_activity [0 ] = '\0' ;
2556
+ beentry -> st_activity_start_timestamp = 0 ;
2557
+ /* st_xact_start_timestamp and st_waiting are also disabled */
2558
+ beentry -> st_xact_start_timestamp = 0 ;
2559
+ beentry -> st_waiting = false;
2560
+ beentry -> st_changecount ++ ;
2561
+ Assert ((beentry -> st_changecount & 1 ) == 0 );
2562
+ }
2561
2563
return ;
2562
2564
}
2563
2565
2564
2566
/*
2565
- * Fetch more data before we start modifying the entry
2567
+ * To minimize the time spent modifying the entry, fetch all the needed
2568
+ * data first.
2566
2569
*/
2567
2570
start_timestamp = GetCurrentStatementStartTimestamp ();
2568
2571
if (cmd_str != NULL )
2569
2572
{
2570
2573
len = pg_mbcliplen (cmd_str , strlen (cmd_str ),
2571
2574
pgstat_track_activity_query_size - 1 );
2572
2575
}
2576
+ current_timestamp = GetCurrentTimestamp ();
2573
2577
2574
2578
/*
2575
2579
* Now update the status entry
0 commit comments