Fix background worker not restarting after crash-and-restart cycle.
authorFujii Masao <[email protected]>
Fri, 25 Jul 2025 09:38:36 +0000 (18:38 +0900)
committerFujii Masao <[email protected]>
Fri, 25 Jul 2025 09:38:36 +0000 (18:38 +0900)
commitb5d084c5353f29e2e217dfa86f327e14d02998c1
tree751ad6b6d0a0c6c4c8cf37cbbefebb58752c01b8
parent641f20d4c433b66df2928408fb2b44bd165c2329
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 <[email protected]>
Reported-by: ChangAo Chen <[email protected]>
Author: Andrey Rudometov <[email protected]>
Author: ChangAo Chen <cca5507@qq.com>
Co-authored-by: Fujii Masao <[email protected]>
Reviewed-by: ChangAo Chen <[email protected]>
Reviewed-by: Shveta Malik <[email protected]>
Discussion: https://postgr.es/m/CAF6JsWiO=i24qYitWe6ns1sXqcL86rYxdyU+pNYk-WueKPSySg@mail.gmail.com
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 18
src/backend/postmaster/bgworker.c
src/backend/postmaster/postmaster.c