Обсуждение: Background Processes in Postgres Extension
Hey,
I'm developing a postgres extension as a custom Table Interface method definition.
WIthin the extension, I"m planning to create two background processes using `fork()` that will process data in the background.
Are there any recommendations / guidelines around creating background processes within extensions in postgres?
Thanks,
Sushrut
Sushrut Shivaswamy <sushrut.shivaswamy@gmail.com> writes: > I'm developing a postgres extension as a custom Table Interface method > definition. > WIthin the extension, I"m planning to create two background processes using > `fork()` that will process data in the background. > Are there any recommendations / guidelines around creating background > processes within extensions in postgres? fork() is entirely the wrong way to do it, mainly because when the creating session exits the postmaster will be unaware of those now-disconnected child processes. See the mechanisms for creating background worker processes (start with bgworker.h). regards, tom lane
Thanks for the suggestion on using postgres background worker.
I tried creating one following the implementation in worker_spi and am able to spawn a background worker successfully.
However, the background worker seems to cause postmaster to crash when I wait for it to finish using `WaitForBackgroundWorkerShutdown.
The function called by the background worker is empty except for logging a message to disk.
Any ideas on what could be going wrong / tips for debugging?
Thanks,
Sushrut
On Sat, Apr 27, 2024 at 9:26 PM Sushrut Shivaswamy <sushrut.shivaswamy@gmail.com> wrote:
Thanks for the suggestion on using postgres background worker.I tried creating one following the implementation in worker_spi and am able to spawn a background worker successfully.However, the background worker seems to cause postmaster to crash when I wait for it to finish using `WaitForBackgroundWorkerShutdown.The function called by the background worker is empty except for logging a message to disk.
When debugging a crash, backtrace from core dump is useful. if you can reproduce the crash, running reproduction with gdb attached to a process intended to crash is more useful.
--
Best Wishes,
Ashutosh Bapat