Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUeaA-00036x-52 for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2016 18:38:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bUea9-0003lZ-OH for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2016 18:38:25 +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_2) (envelope-from ) id 1bUea8-0003kn-OG for pgsql-hackers@postgresql.org; Tue, 02 Aug 2016 18:38:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bUea5-00008V-SL for pgsql-hackers@postgresql.org; Tue, 02 Aug 2016 18:38:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u72IcJOf000759; Tue, 2 Aug 2016 14:38:19 -0400 From: Tom Lane To: Alvaro Herrera cc: Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: PostmasterContext survives into parallel workers!? In-reply-to: <20160802182402.GA556987@alvherre.pgsql> References: <20160802182402.GA556987@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Tue, 02 Aug 2016 14:24:02 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <26697.1470162452.0@sss.pgh.pa.us> Date: Tue, 02 Aug 2016 14:38:19 -0400 Message-ID: <758.1470163099@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) 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 ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26697.1470162452.1@sss.pgh.pa.us> Alvaro Herrera writes: > Tom Lane wrote: >> It looks to me like the reason for it is simply not having bothered to >> copy the rw->rw_worker data to somewhere that would survive deletion >> of the PostmasterContext. I wonder though if anyone remembers a more >> fundamental reason? Surely the bgworker is not supposed to touch any >> of the rest of the BackgroundWorkerList? > I just checked BDR, which is the more complex code using workers I know > of, and I don't see any reason why this cannot be changed. The attached patch passes "make check-world" for me. Can you check it against BDR? (I'd be hesitant to back-patch it in any case, but I think it's okay for HEAD unless we can easily find something it breaks.) regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="no-postmaster-context-in-bgworkers.patch"; charset="us-ascii" Content-ID: <26697.1470162452.2@sss.pgh.pa.us> Content-Description: no-postmaster-context-in-bgworkers.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/p= ostmaster.c index 19d11e0..e48703a 100644 *** a/src/backend/postmaster/postmaster.c --- b/src/backend/postmaster/postmaster.c *************** do_start_bgworker(RegisteredBgWorker *rw *** 5529,5537 **** /* Close the postmaster's sockets */ ClosePostmasterPorts(false); =20=20 ! /* Do NOT release postmaster's working memory context */ =20=20 - MyBgworkerEntry =3D &rw->rw_worker; StartBackgroundWorker(); break; #endif --- 5529,5547 ---- /* Close the postmaster's sockets */ ClosePostmasterPorts(false); =20=20 ! /* ! * Before blowing away PostmasterContext, save this bgworker's ! * data where it can find it. ! */ ! MyBgworkerEntry =3D (BackgroundWorker *) ! MemoryContextAlloc(TopMemoryContext, sizeof(BackgroundWorker)); ! memcpy(MyBgworkerEntry, &rw->rw_worker, sizeof(BackgroundWorker)); !=20 ! /* Release postmaster's working memory context */ ! MemoryContextSwitchTo(TopMemoryContext); ! MemoryContextDelete(PostmasterContext); ! PostmasterContext =3D NULL; =20=20 StartBackgroundWorker(); break; #endif ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--