Re: Wake up autovacuum launcher from postmaster when a worker exits

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: li carol <carol(dot)li2025(at)outlook(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Wake up autovacuum launcher from postmaster when a worker exits
Date: 2026-01-15 16:03:13
Message-ID: 69945267-fb1f-4d73-a84f-8a6bf9401877@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 09/01/2026 00:20, Nathan Bossart wrote:
> On Thu, Jan 08, 2026 at 09:57:38PM +0200, Heikki Linnakangas wrote:
>> * It makes it consistent with background workers. When a background worker
>> exits, the postmaster sends the signal to the launching process (if
>> requested).
>
> I've wondered about making autovacuum workers proper background workers.

Yeah, me too...

>> I'm a little surprised it wasn't done this way to begin with, so I wonder if
>> I'm missing something?
>
> This code dates back to commit e2a186b03c. I skimmed through the nearby
> thread [0] and didn't immediately notice any discussion about this. My
> guess is that it seemed simpler to directly alert the launcher, since it's
> the one that needs to take action.
>
> [0] https://postgr.es/m/flat/20070404233954.GK19251%40alvh.no-ip.org

Thanks for checking. I suspect we wanted to keep postmaster as dumb as
possible, having all logic in the child process if at all possible. But
we perhaps went a little overboard with that; signaling child processes
seems squarely like postmaster's core business.

On 09/01/2026 10:27, li carol wrote:
>> On Thu, Jan 8, 2026 at 11:57 AM Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
>>>
>>> When an autovacuum worker exits, ProcKill() sends SIGUSR2 to the
>>> launcher. I propose moving that responsibility to the postmaster, because:
>>>
>>> * It's simpler IMHO
>>>
>>> * The postmaster is already responsible for sending the signal if
>>> fork() fails
>>>
>>> * It makes it consistent with background workers. When a background
>>> worker exits, the postmaster sends the signal to the launching process
>>> (if requested).
>>>
>>> * Postmaster doesn't need to worry about sending the signal to the
>>> wrong process if the launcher's PID is reused, because it always has
>>> up-to-date PID information, because the launcher is postmaster's child
>>> process. That risk was negligible to begin with, but this eliminates
>>> completely, so we don't need the comment excusing it it anymore.
>>
>> It sounds reasonable to me too. +1.
>
> I have completed the testing for this patch with a focus on the signaling logic from postmaster to launcher.
>
> ...
>
> This confirms that the postmaster successfully notifies the launcher and the worker slot is freed appropriately before the notification.
>
> The patch looks correct and robust. +1 from my side.

Committed, thanks for the reviews and testing!

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-01-15 16:06:53 Re: Row pattern recognition
Previous Message Nathan Bossart 2026-01-15 15:59:17 Re: refactor architecture-specific popcount code