pgsql: Fix restart of interruptible bgworkers after database commands

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix restart of interruptible bgworkers after database commands
Date: 2026-11-10 23:36:52
Message-ID: E1xQvOW-00000000EeS-31BQ@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)parragi(at)percona(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Aya Iwata <iwata(dot)aya(at)jp(dot)fujitsu(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAN4CZFNP+_aVsTqxfyNLU+AtRZMJeDRAR9XRfjPTwsWs3TXVaQ@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5bf919736b20ffdc8d646c33ed2d9054609b23ec

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-11-11 00:31:30 pgsql: Fix uninitialized cache use in gtsvector_picksplit()
Previous Message David Rowley 2026-11-10 22:51:18 pgsql: Avoid integer wraparound when adding new HASH partition