There are some cases when the wait_latch loop in background worker is not being interrupted after the postmaster was exited.
It can be reproduced by running postgres directly using /opt/homebrew/opt/postgresql@17/bin/postgres -D /opt/homebrew/var/postgresql@17 and after the background worker will be started you will need to send SIGKILL to the postmaster process. (the issue is not reproducible when managing postgres via pg_ctl, I have encountered this issue during local development as homebrew service runs postgres directly using postgres binary)
Then you can see that the postgres will be exited, but background worker process will remain active.
Simple bgworker extension code to reproduce the issue:
Make sure the WL_POSTMASTER_DEATH flag is set when calling that function, and verify the return code for a prompt exit in the emergency case that postgres itself has terminated.
There are some cases when the
wait_latch
loop in background worker is not being interrupted after the postmaster was exited.It can be reproduced by running postgres directly using
/opt/homebrew/opt/postgresql@17/bin/postgres -D /opt/homebrew/var/postgresql@17
and after the background worker will be started you will need to sendSIGKILL
to the postmaster process. (the issue is not reproducible when managing postgres viapg_ctl
, I have encountered this issue during local development as homebrew service runs postgres directly usingpostgres
binary)Then you can see that the postgres will be exited, but background worker process will remain active.
Simple bgworker extension code to reproduce the issue:
It also suggests in the documentation to check for return code after calling
WaitLatch
to make sure the postmaster was not exited.https://www.postgresql.org/docs/current/bgworker.html