On 2015-12-03 14:32, Craig Ringer wrote:
On 3 December 2015 at 15:27, konstantin knizhnik
<k.knizh...@postgrespro.ru <mailto:k.knizh...@postgrespro.ru>> wrote:

    3. What is the right way of creation of background worker requiring
    access to shared memory, i.e. having control structure in main memory?


This is documented and well established.

    As far as I understand background workers have to be registered
    either PG_init, either outside Postmaster environment.
    If extension requires access to shared memory, then it should be
    registered in shared_preload_libraries list and should be
    initialized using shmem_startup hook.


Correct.

You can use dynamic shmem instead, but there are some issues there IIRC.
Petr may have more to say there.
Take a look at the BDR code for some examples, and there are some in
contrib too I think.


If you have your own flock of dynamic workers that you manage yourself, it's probably easier to use dynamic shared memory. You can see some examples in the tests and also in the parallel query code for how to do it. The only real issue we faced with using dynamic shared memory was that we needed to do IPC from normal backends and that gets complicated when you don't have the worker info in the normal shmem.


The registration timing and working with normal shmem is actually not a problem. Just register shmem start hook in _PG_init and if you are registering any bgworkers there as well make sure you set bgw_start_time correctly (usually what you want is BgWorkerStart_RecoveryFinished). Then you'll have the shmem hook called before the bgworker is actually started.

--
 Petr Jelinek                  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to