pgsql: Fix background worker not restarting after crash-and-restart cyc

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix background worker not restarting after crash-and-restart cyc
Date: 2025-07-25 09:41:08
Message-ID: E1ufEvM-000eX4-10@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix background worker not restarting after crash-and-restart cycle.

Previously, if a background worker crashed (e.g., due to a SIGKILL) and
the server restarted due to restart_after_crash being enabled,
the worker was not restarted as expected. Background workers without
the never-restart flag should automatically restart in this case.

This issue was introduced in commit 28a520c0b77, which failed to reset
the rw_pid field in the RegisteredBgWorker struct for the crashed worker.

This commit fixes the problem by resetting rw_pid for all eligible
background workers during the crash-and-restart cycle.

Back-patched to v18, where the bug was introduced.

Bug fix patches were proposed by Andrey Rudometov and ChangAo Chen,
but this commit uses a different approach.

Reported-by: Andrey Rudometov <unlimitedhikari(at)gmail(dot)com>
Reported-by: ChangAo Chen <cca5507(at)qq(dot)com>
Author: Andrey Rudometov <unlimitedhikari(at)gmail(dot)com>
Author: ChangAo Chen <cca5507(at)qq(dot)com>
Co-authored-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: ChangAo Chen <cca5507(at)qq(dot)com>
Reviewed-by: Shveta Malik <shveta(dot)malik(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAF6JsWiO=i24qYitWe6ns1sXqcL86rYxdyU+pNYk-WueKPSySg@mail.gmail.com
Discussion: https://postgr.es/m/tencent_E00A056B3953EE6440F0F40F80EC30427D09@qq.com
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b5d084c5353f29e2e217dfa86f327e14d02998c1

Modified Files
--------------
src/backend/postmaster/bgworker.c | 1 +
src/backend/postmaster/postmaster.c | 7 +++++++
2 files changed, 8 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2025-07-25 09:41:34 pgsql: Fix background worker not restarting after crash-and-restart cyc
Previous Message Michael Paquier 2025-07-25 07:17:58 pgsql: Fix assertion failure with latch wait in single-user mode