Re: Use standard die() handler for SIGTERM in bgworkers

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Kirill Reshke <reshkekirill@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2026-02-18T18:07:43Z
Lists: pgsql-hackers
On 18/02/2026 10:45, Kirill Reshke wrote:
> On Wed, 18 Feb 2026 at 02:18, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>> +  <para>
>> +   The default signal handlers merely set interrupt flags
>> +   that are processed later by <function>CHECK_FOR_INTERRUPTS()</function>.
>> +   <function>CHECK_FOR_INTERRUPTS()</function> should be called in any
>> +   long-running loop to ensure that the background worker doesn't prevent the
>> +   system from shutting down in a timely fashion.
>> +  </para>
> 
> Unless you are holding LWLock (or, more generally, inside the CRIT
> section). Should we update wording for this case, or is it maybe
> already assumed in doc?

It's OK to call CHECK_FOR_INTERRUPTS() while holding locks or in a 
critical section. It's a no-op in that case.

I wouldn't go into the details here on how to use 
CHECK_FOR_INTERRUPTS(). It would be good to document all that somewhere, 
but it should go to some more general section on how to write server C 
functions as it's applicable to any C code. For background workers, I 
think the above is good.

Pushed, thanks for the review!

- Heikki




Commits

  1. Use standard die() handler for SIGTERM in bgworkers