Hi Postgres Hackers,

I am wondering is there any elegant way for self-spawned background process
(forked by us) to get notified when the regular client-connected process
exit from the current database (switch db or even terminate)?

The background is that we are integrating a thread-model based storage
engine into Postgres via foreign data wrapper. The engine is not allowed to
have multiple processes to access it. So we have to spawn a background
process to access the engine, while the client process can communicate with
the spawned process via shared memory. In order to let the engine recognize
the data type in Postgres, the spawned process has to access catalog such
as relcache, and It must connect to the target database
via BackgroundWorkerInitializeConnection to get the info. Unfortunately, it
is not possible to switch databases for background process. So it has to
get notified when client process switches db or terminate, then we can
correspondingly close the spawned process. Please advise us if there are
alternative approaches.

Best,
Shichao

Reply via email to