]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix advertising autovacuum launcher's ProcNumber
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 9 Jul 2026 12:14:19 +0000 (15:14 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 9 Jul 2026 12:14:19 +0000 (15:14 +0300)
Autovacuum launcher is not an aux process, so it needs to be
advertised in InitProcess() rather than InitAuxiliaryProcess()

In the passing, also remove some now-unnecessary 'volatile' qualifiers
left behind by the same commit.

Reported-by: Thom Brown <thom@linux.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAA-aLv6UHXubNxmAjNH8PnyKKkaXePO1ggB15=iidNW08T4hSg@mail.gmail.com

src/backend/postmaster/checkpointer.c
src/backend/storage/lmgr/proc.c
src/include/storage/proc.h

index a09d4097d51a8fccf34b5dd1a1b9db6b4af0e6d4..f6351f1eb105a0d0b41a5cd3f417b87fb8be6cfa 100644 (file)
@@ -1114,8 +1114,7 @@ RequestCheckpoint(int flags)
 #define MAX_SIGNAL_TRIES 600   /* max wait 60.0 sec */
        for (ntries = 0;; ntries++)
        {
-               volatile PROC_HDR *procglobal = ProcGlobal;
-               ProcNumber      checkpointerProc = pg_atomic_read_u32(&procglobal->checkpointerProc);
+               ProcNumber      checkpointerProc = pg_atomic_read_u32(&ProcGlobal->checkpointerProc);
 
                if (checkpointerProc == INVALID_PROC_NUMBER)
                {
@@ -1536,8 +1535,7 @@ FirstCallSinceLastCheckpoint(void)
 void
 WakeupCheckpointer(void)
 {
-       volatile PROC_HDR *procglobal = ProcGlobal;
-       ProcNumber      checkpointerProc = pg_atomic_read_u32(&procglobal->checkpointerProc);
+       ProcNumber      checkpointerProc = pg_atomic_read_u32(&ProcGlobal->checkpointerProc);
 
        if (checkpointerProc != INVALID_PROC_NUMBER)
                SetLatch(&GetPGProcByNumber(checkpointerProc)->procLatch);
index 59640bb4f970cd07326026696782bf3127141ecd..9d6e69175a58a70240f00c07ede073e8bf50cbf6 100644 (file)
@@ -550,6 +550,10 @@ InitProcess(void)
         */
        PGSemaphoreReset(MyProc->sem);
 
+       /* autovacuum launcher is specially advertised in ProcGlobal */
+       if (MyBackendType == B_AUTOVAC_LAUNCHER)
+               pg_atomic_write_u32(&ProcGlobal->avLauncherProc, MyProcNumber);
+
        /*
         * Arrange to clean up at backend exit.
         */
@@ -726,8 +730,6 @@ InitAuxiliaryProcess(void)
        PGSemaphoreReset(MyProc->sem);
 
        /* Some aux processes are also advertised in ProcGlobal */
-       if (MyBackendType == B_AUTOVAC_LAUNCHER)
-               pg_atomic_write_u32(&ProcGlobal->avLauncherProc, MyProcNumber);
        if (MyBackendType == B_WAL_WRITER)
                pg_atomic_write_u32(&ProcGlobal->walwriterProc, MyProcNumber);
        if (MyBackendType == B_CHECKPOINTER)
@@ -989,6 +991,12 @@ ProcKill(int code, Datum arg)
        SwitchBackToLocalLatch();
        DisownLatch(&MyProc->procLatch);
 
+       if (MyBackendType == B_AUTOVAC_LAUNCHER)
+       {
+               Assert(pg_atomic_read_u32(&ProcGlobal->avLauncherProc) == MyProcNumber);
+               pg_atomic_write_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER);
+       }
+
        proc = MyProc;
        procgloballist = proc->procgloballist;
 
@@ -1113,11 +1121,6 @@ AuxiliaryProcKill(int code, Datum arg)
        /*
         * If this was one of the aux processes advertised in ProcGlobal, clear it
         */
-       if (MyBackendType == B_AUTOVAC_LAUNCHER)
-       {
-               Assert(pg_atomic_read_u32(&ProcGlobal->avLauncherProc) == MyProcNumber);
-               pg_atomic_write_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER);
-       }
        if (MyBackendType == B_WAL_WRITER)
        {
                Assert(pg_atomic_read_u32(&ProcGlobal->walwriterProc) == MyProcNumber);
index 0314f979e60575243e27af3160b5e025a36837e0..03a1a466fa8b9e4beac86d5c0e2a85263e70860d 100644 (file)
@@ -491,9 +491,10 @@ typedef struct PROC_HDR
         * Current proc numbers of some auxiliary processes. There can be only one
         * of each of these running at a time.
         */
-       pg_atomic_uint32 avLauncherProc;
        pg_atomic_uint32 walwriterProc;
        pg_atomic_uint32 checkpointerProc;
+       /* avlauncher is not an aux process, but it is advertised the same way */
+       pg_atomic_uint32 avLauncherProc;
 
        /* Current shared estimate of appropriate spins_per_delay value */
        int                     spins_per_delay;