pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix restart of interruptible bgworkers after database commands
Date: Tue, 10 Nov 2026 23:36:52 +0000
Message-ID: <E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org> (raw)

Fix restart of interruptible bgworkers after database commands

TerminateBackgroundWorkersForDatabase() sets the terminate flag of the
workers' slots, so the postmaster unregistered them regardless of
bgw_restart_time, even if the database command failed afterwards.

Let's signal the workers directly instead, like CountOtherDBBackends()
does for autovacuum workers, so that they are restarted based on
bgw_restart_time.  This gives the option for extension developers to
decide if an interruptible worker can be restarted or not, instead of
always been thrown away.  There can be an appeal in the restart if the
bgworker relies on a database to connect to coming from a GUC, if its
value can be reloaded.

Oversight in f1e251be80a0.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Aya Iwata <iwata.aya@jp.fujitsu.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/CAN4CZFNP+_aVsTqxfyNLU+AtRZMJeDRAR9XRfjPTwsWs3TXVaQ@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1a561b3484c05b9f1b4cf4f76370cc32b3ef48ae

Modified Files
--------------
doc/src/sgml/bgworker.sgml                         |  6 ++--
src/backend/postmaster/bgworker.c                  | 32 +++++++++++++---------
.../modules/worker_spi/t/002_worker_terminate.pl   | 20 ++++++++++++--
src/test/modules/worker_spi/worker_spi--1.0.sql    |  3 +-
src/test/modules/worker_spi/worker_spi.c           |  4 ++-
5 files changed, 46 insertions(+), 19 deletions(-)



view thread (2+ messages)

Message-ID: <E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org>
Permalink:  ../E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Fix restart of interruptible bgworkers after database commands
  In-Reply-To: <E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org>
  References: <E1xQvOW-00000000EeU-36UL@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox