Re: pgsql: Refactor how some aux processes advertise their ProcNumber
Re: pgsql: Refactor how some aux processes advertise their ProcNumber
On Thu, Jul 9, 2026 at 6:57 AM Thom Brown wrote: > @@ -724,6 +725,14 @@ 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); > > I'm looking for the places this gets called from. I can only see > auxprocess.c which the launcher doesn't go through. The same question > for similar code in AuxiliaryProcKill(). You're right. The autovacuum launcher does not go through AuxiliaryProcessMainCommon(), so it never calls InitAuxiliaryProcess(). Instead, it initializes its PGPROC with InitProcess(). As a result, the avLauncherProc assignment added to InitAuxiliaryProcess() is never executed for the launcher, and the corresponding cleanup in AuxiliaryProcKill() is never reached either. It seems we should move the avLauncherProc set/clear operations to InitProcess()/ProcKill() path, as in the attached patch. Regards, -- Fujii Masao
Re: pgsql: Refactor how some aux processes advertise their ProcNumber
On Wed, Jul 08, 2026 at 05:43:01PM +0000, Heikki Linnakangas wrote: > Switch to pg_atomic_uint32 for the fields. Seems easier to reason > about than volatile pointers. There was some precedence for that, as > were already using pg_atomic_uint32 for the procArrayGroupFirst and > clogGroupFirst fields, which also store ProcNumbers. Since removing volatile qualifiers is on my mind, I noticed that this patch makes it possible to remove two more. Patch attached. -- nathan
Re: pgsql: Refactor how some aux processes advertise their ProcNumber
От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
On 09/07/2026 03:57, Fujii Masao wrote: > On Thu, Jul 9, 2026 at 6:57 AM Thom Brown wrote: >> @@ -724,6 +725,14 @@ 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); >> >> I'm looking for the places this gets called from. I can only see >> auxprocess.c which the launcher doesn't go through. The same question >> for similar code in AuxiliaryProcKill(). > > You're right. The autovacuum launcher does not go through > AuxiliaryProcessMainCommon(), so it never calls > InitAuxiliaryProcess(). Instead, it initializes its PGPROC with > InitProcess(). > > As a result, the avLauncherProc assignment added to > InitAuxiliaryProcess() is never executed for the launcher, and the > corresponding cleanup in AuxiliaryProcKill() is never reached either. Huh, you're right. That raises some questions: Why is the autovacuum launcher not an aux process? I guess it's because it needs to acquire a heavy-weight lock in order to read the list of databases. How come none of the tests failed? I guess the path to wake up the launcher isn't critical for correctness, it just makes autovacuum slower to react. > It seems we should move the avLauncherProc set/clear operations to > InitProcess()/ProcKill() path, as in the attached patch. Thanks! Committed that, and also Nathan's volatile removal. - Heikki
Re: pgsql: Refactor how some aux processes advertise their ProcNumber
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Jul 9, 2026 at 9:17 PM Heikki Linnakangas wrote: > Why is the autovacuum launcher not an aux process? I guess it's because > it needs to acquire a heavy-weight lock in order to read the list of > databases. That seems to be one of the reasons, based on the comment about auxiliary processes in miscadmin.h: ------------------------- * Auxiliary processes. These have PGPROC entries, but they are not * attached to any particular database, and cannot run transactions or * even take heavyweight locks. There can be only one of each of these * running at a time, except for IO workers. ------------------------- Regards, -- Fujii Masao
Re: pgsql: Refactor how some aux processes advertise their ProcNumber
От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Jul-09, Heikki Linnakangas wrote:
> Why is the autovacuum launcher not an aux process? I guess it's because it
> needs to acquire a heavy-weight lock in order to read the list of databases.
Because it scans pg_database.
commit 00e6a16d01683762c2f34eb4909fc739093ab3bf
Author: Tom Lane []
AuthorDate: Mon Aug 31 19:41:00 2009 +0000
CommitDate: Mon Aug 31 19:41:00 2009 +0000
Change the autovacuum launcher to read pg_database directly, rather than
via the "flat files" facility. This requires making it enough like a backend
to be able to run transactions; it's no longer an "auxiliary process" but
more like the autovacuum worker processes. Also, its signal handling has
to be brought into line with backends/workers. In particular, since it
now has to handle procsignal.c processing, the special autovac-launcher-only
signal conditions are moved to SIGUSR2.
Alvaro, with some cleanup from Tom
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"If you want to have good ideas, you must have many ideas. Most of them
will be wrong, and what you have to learn is which ones to throw away."
(Linus Pauling)