Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a4VTS-0004n3-Gd for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Dec 2015 15:07:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a4VTR-0001Fp-5v for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Dec 2015 15:07:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a4VTP-0001EK-Ck for pgsql-hackers@postgresql.org; Thu, 03 Dec 2015 15:07:07 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1a4VTH-0002vO-QK for pgsql-hackers@postgresql.org; Thu, 03 Dec 2015 15:07:06 +0000 Received: by wmww144 with SMTP id w144so25002979wmw.1 for ; Thu, 03 Dec 2015 07:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=nIj+Y4kfjUe1LpL92MsnQ2TTHoPSx+MNwbbYO8tZVF0=; b=YblHy6yidCrsD0aY+2aiEgL1yR98vrzfKmzBzlfDReTW2HCkaj27/6UMnkZ/7wTetW IbEB5Aol8+fjP/Jign+eHmqO6utvxetd8N3gp5WL8cIP4Y5inbUE+70N3oM5C7p3SLsW YDbBRRob5x/Wxv4sRZhqYSqu6C5JVaNQx9slzVtw89rfF2SkCEfixOLnJ9wWVI/3fzsg 42CvBC25IcyI5WhcvIIBEky2gZduxeENxsyZWgUgPcIRKqjq3Edlmotmpt66h7+3LHov F+4OGgyRa/a9VX5WcvL4P6FpxvrTx2LhpGGv3z+zNmi+N+wAS8MiJaQlhV7Z6AvNe2ER bdvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=nIj+Y4kfjUe1LpL92MsnQ2TTHoPSx+MNwbbYO8tZVF0=; b=hwW1fKpvsApJmxM1sv+GyXPiqhWv4v1RK4tLqq/wTnrV202MpmFmsWxVpP4b4SgvBj HJP/bxrDGh/D8Yrouh0S9tsGWXuIhqaBbrChLxfboj/K0XpSc40wjvWQQg1h4fNtGK9U iV5hlmkwxJ2Dc9cIHGz6nMvecGcxl+7rrJ50/6e3TqsyrJe2w/ZP6f/qTraQTmmy7tcu CL+osvxLM2zvbamK4gjPP+aqMdLODSMBkZJZaMRlxB4DsnfhhJFF2ewW6VvNSuNQMetf uxy8SS1Kn/+EFBH/gdcXxT3O7tEpVz9/jziDhxPSwY3pjMRp/omcYMhkrS3tbTOWXuwq Tx3Q== X-Gm-Message-State: ALoCoQkRf+HSzuQXWvPxbPp+mRfb4Sw6kX5UR5DtYlZ+0R8CCVCnRCDFmzQI+SYIp0J2CC9zetGO X-Received: by 10.194.117.228 with SMTP id kh4mr11257362wjb.171.1449155218520; Thu, 03 Dec 2015 07:06:58 -0800 (PST) Received: from ?IPv6:2a00:1028:96c9:ee5a:b02f:e053:ba51:f004? (dynamic-2a00-1028-96c9-ee5a-b02f-e053-ba51-f004.ipv6.broadband.iol.cz. [2a00:1028:96c9:ee5a:b02f:e053:ba51:f004]) by smtp.gmail.com with ESMTPSA id jz1sm7946664wjc.27.2015.12.03.07.06.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Dec 2015 07:06:57 -0800 (PST) Subject: Re: Logical replication and multimaster To: Craig Ringer , konstantin knizhnik References: <565C7756.9070604@postgrespro.ru> <565F5208.3070100@postgrespro.ru> Cc: pgsql-hackers Hackers , Robert Haas From: Petr Jelinek Message-ID: <56605A90.2010306@2ndquadrant.com> Date: Thu, 3 Dec 2015 16:06:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2015-12-03 14:32, Craig Ringer wrote: > On 3 December 2015 at 15:27, konstantin knizhnik > > 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