On Fri, Feb 06, 2026 at 07:11:07AM +0000, Ryo Matsumura (Fujitsu) wrote:
> I found the code that is likely to cause bugs in the future. It's not 
> currently a bug.
> Should I have misunderstood, please feel free to disregard this email.

Because this is a clear thinko.  pgstat_bestart_final() is always a
code path taken after pgstat_beinit() for auxiliary processes and the
rest of the world.  I am pretty sure that my intention here was to
use the argument and not MyProcNumber in the function
pgstat_create_backend() because we rely on MyProcNumber to be defined
when the create routine is called, and that's what
pgstat_bestart_final() offers as guarantee, due to pgstat_beinit().

There is no bug currently, but let's clean that up in all the branches
anyway for clarity and any future back-patch.  Hence, what do you think
about the attached? 
--
Michael
diff --git a/src/backend/utils/activity/pgstat_backend.c 
b/src/backend/utils/activity/pgstat_backend.c
index 1350f5f62f15..f2f8d3ff75f5 100644
--- a/src/backend/utils/activity/pgstat_backend.c
+++ b/src/backend/utils/activity/pgstat_backend.c
@@ -326,7 +326,7 @@ pgstat_create_backend(ProcNumber procnum)
        PgStatShared_Backend *shstatent;
 
        entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_BACKEND, InvalidOid,
-                                                                               
        MyProcNumber, false);
+                                                                               
        procnum, false);
        shstatent = (PgStatShared_Backend *) entry_ref->shared_stats;
 
        /*

Attachment: signature.asc
Description: PGP signature

Reply via email to