Re: Logical replication and multimaster

From: Petr Jelinek <petr(at)2ndquadrant(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>, konstantin knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
Cc: pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Logical replication and multimaster
Date: 2015-12-03 15:06:56
Message-ID: 56605A90.2010306@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2015-12-03 14:32, Craig Ringer wrote:
> On 3 December 2015 at 15:27, konstantin knizhnik
> <k(dot)knizhnik(at)postgrespro(dot)ru <mailto:k(dot)knizhnik(at)postgrespro(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2015-12-03 15:41:51 Re: Fwd: Another little thing about psql wrapped expanded output
Previous Message Amit Kapila 2015-12-03 14:58:08 Re: proposal: add 'waiting for replication' to pg_stat_activity.state