Fix thinko when ending progress report for a backend
authorMichael Paquier <[email protected]>
Wed, 4 Sep 2019 06:47:01 +0000 (15:47 +0900)
committerMichael Paquier <[email protected]>
Wed, 4 Sep 2019 06:47:01 +0000 (15:47 +0900)
The logic ending progress reporting for a backend entry introduced by
b6fb647 causes callers of pgstat_progress_end_command() to do some extra
work when track_activities is enabled as the process fields are reset in
the backend entry even if no command were started for reporting.

This resets the fields only if a command is registered for progress
reporting, and only if track_activities is enabled.

Author: Masahiho Sawada
Discussion: https://postgr.es/m/CAD21AoCry_vJ0E-m5oxJXGL3pnos-xYGCzF95rK5Bbi3Uf-rpA@mail.gmail.com
Backpatch-through: 9.6

src/backend/postmaster/pgstat.c

index bc624c27a927070a4e46fc859a7664339ed125ff..f98003555b5846c40cc6b0b26180ca87d322eaa6 100644 (file)
@@ -3024,10 +3024,10 @@ pgstat_progress_end_command(void)
 {
    volatile PgBackendStatus *beentry = MyBEEntry;
 
-   if (!beentry)
+   if (!beentry || !pgstat_track_activities)
        return;
-   if (!pgstat_track_activities
-       && beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
+
+   if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
        return;
 
    PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);