Spawned Background Process Knows the Exit of Client Process? - Mailing list pgsql-hackers

From Shichao Jin
Subject Spawned Background Process Knows the Exit of Client Process?
Date
Msg-id CABCoBcLgtY5TtW-S5s4WZUA0jXUXWAHEQ8Qu_4QUGeebGDx5eA@mail.gmail.com
Whole thread Raw
Responses Re: Spawned Background Process Knows the Exit of Client Process?
List pgsql-hackers
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

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pg_stat_wal_receiver and flushedUpto/writtenUpto
Next
From: Pavel Stehule
Date:
Subject: Re: calling procedures is slow and consumes extra much memory againstcalling function