Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQoOU-0002Y4-AE for pgsql-bugs@arkaria.postgresql.org; Wed, 15 May 2019 07:32:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hQoOT-00008l-2P for pgsql-bugs@arkaria.postgresql.org; Wed, 15 May 2019 07:32:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQoOR-0008Tl-5M for pgsql-bugs@lists.postgresql.org; Wed, 15 May 2019 07:32:04 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQoON-00058u-Bp for pgsql-bugs@lists.postgresql.org; Wed, 15 May 2019 07:32:01 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 4504E48F; Wed, 15 May 2019 03:31:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 15 May 2019 03:31:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=8RtPJfym0VneSBAUftc45Du0P3h MowHOiunRHfDjj0Y=; b=IFDG7Provp7V4vVQQ1mD00P4zK2FZW0XHWnzlsLdLLF m/8AoqKqkoOchcf0wivtNucerwASmzBPt1Dt0yhImCAxs58SrulmqRImooXFrkoV QY7yzCAemb5cCR87wqEsiYOBC+fgcdRof+J6mPBrkRjMJsbWfmqa2mS2Y8PobUnu UnUD/lDT4tOHtmesG4HNDbFnIAzZCeg5WQ34q2/q9XfLro/UzPO0pNURL4unOmYs efR4MOuRAfTfifRsNFLWmsqF7KGiPdqebJFmojOyObHqSRH6ik+mfly/l1OppFJi i948QhH8M6SVxa+nH+tbM1EaRciMryKj+eL0/f8qWUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8RtPJf ym0VneSBAUftc45Du0P3hMowHOiunRHfDjj0Y=; b=Bk9uFBp/nm7wgN7GlWDJzV o8AySuIOT0avREdKSOhjLt4kzO2e1G8xiS3zm7WQeUCMkyEaChDxC0GsnxIRx4C8 nBIROXpMmg/Xu+p7Oxf3r1MzaC9bCBpkYwBcCKRBeqi9eKLPFbtGRZZBWcv/27IX zg+BVFWpResi9Uhr0XAt1j8+vjcaonApTa3wu4wBiFPFE6pab1LEwCn3BAfASSJ2 jJ1ko5KOva943WDKEz1uDB/26ibHnRSsiKL6NRhNyhJDFJ6NEI/izEAsclv+4IuF /Z0zx5t6e5jvOdLjVrXUj4EF7Po80fjdMS1pzKzUZyYBWgRdfqr91yki9s5zksyA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrleejgdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepudduuddruddtvddrudektddrudekheenucfrrghr rghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id CFB6D8005A; Wed, 15 May 2019 03:31:41 -0400 (EDT) Date: Wed, 15 May 2019 16:31:25 +0900 From: Michael Paquier To: Tom Lane Cc: Yuli Khodorkovskiy , pgsql-bugs@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG #15804: Assertion failure when using logging_collector with EXEC_BACKEND Message-ID: <20190515073125.GA1517@paquier.xyz> References: <15804-3721117bf40fb654@postgresql.org> <27CD45B5-88F7-4A09-8B31-EFE41FC37FE1@crunchydata.com> <26332.1557863524@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="uQr8t48UFsdbeI+V" Content-Disposition: inline In-Reply-To: <26332.1557863524@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --uQr8t48UFsdbeI+V Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, May 14, 2019 at 03:52:04PM -0400, Tom Lane wrote: > It might be better to give up the assertion in PGSharedMemoryNoReAttach, > and just make it work more like PGSharedMemoryDetach, ie "detach if > UsedShmemSegAddr is set, else do nothing". I don't remember for sure, > but if we do that, there might be no functional difference anymore > between those two functions, in which case we might as well merge 'em. It would be nice to fix that before beta1 is out, or we are going to get complaints :( So what about dropping PGSharedMemoryNoReAttach() completely and using (or abusing of?) the detach routine so as we rely on its no-op behavior when a subprocess is not attached yet to a shared memory segment. On Windows, the sub-processes calling NoReAttach don't map to a segment per the comments in the code, and I can indeed see some "could not map" LOG messages coming from these in the logs if enforcing the use of the detach routine in postmaster.c. It could actually be an advantage to unmap using UnmapViewOfFile() so as a subsequent call of ReAttach does not finish by mapping an extra time. We may consider lowering the LOG messages to DEBUG1, or extend the detach routine so as we control the level of logs with an elevel to avoid sparse LOG messages when unmapping from shared segments where we know it would fail. I have been playing with the attached using EXEC_BACKEND on Linux and some Windows builds FWIW. Thoughts? -- Michael --ZPt4rx8FFjLCG7dd Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="shmem-noattach.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index fda3442c5b..8b70dab1a9 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -827,38 +827,6 @@ PGSharedMemoryReAttach(void) UsedShmemSegAddr =3D hdr; /* probably redundant */ } =20 -/* - * PGSharedMemoryNoReAttach - * - * This is called during startup of a postmaster child process when we cho= ose - * *not* to re-attach to the existing shared memory segment. We must clea= n up - * to leave things in the appropriate state. This is not used in the non - * EXEC_BACKEND case, either. - * - * The child process startup logic might or might not call PGSharedMemoryD= etach - * after this; make sure that it will be a no-op if called. - * - * UsedShmemSegID and UsedShmemSegAddr are implicit parameters to this - * routine. The caller must have already restored them to the postmaster's - * values. - */ -void -PGSharedMemoryNoReAttach(void) -{ - Assert(UsedShmemSegAddr !=3D NULL); - Assert(IsUnderPostmaster); - -#ifdef __CYGWIN__ - /* cygipc (currently) appears to not detach on exec. */ - PGSharedMemoryDetach(); -#endif - - /* For cleanliness, reset UsedShmemSegAddr to show we're not attached. */ - UsedShmemSegAddr =3D NULL; - /* And the same for UsedShmemSegID. */ - UsedShmemSegID =3D 0; -} - #endif /* EXEC_BACKEND */ =20 /* diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index ccd7b6b5e3..fa080222f6 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -431,41 +431,6 @@ PGSharedMemoryReAttach(void) UsedShmemSegAddr =3D hdr; /* probably redundant */ } =20 -/* - * PGSharedMemoryNoReAttach - * - * This is called during startup of a postmaster child process when we cho= ose - * *not* to re-attach to the existing shared memory segment. We must clea= n up - * to leave things in the appropriate state. - * - * The child process startup logic might or might not call PGSharedMemoryD= etach - * after this; make sure that it will be a no-op if called. - * - * ShmemProtectiveRegion, UsedShmemSegID and UsedShmemSegAddr are implicit - * parameters to this routine. The caller must have already restored them= to - * the postmaster's values. - */ -void -PGSharedMemoryNoReAttach(void) -{ - Assert(ShmemProtectiveRegion !=3D NULL); - Assert(UsedShmemSegAddr !=3D NULL); - Assert(IsUnderPostmaster); - - /* - * Under Windows we will not have mapped the segment, so we don't need to - * un-map it. Just reset UsedShmemSegAddr to show we're not attached. - */ - UsedShmemSegAddr =3D NULL; - - /* - * We *must* close the inherited shmem segment handle, else Windows will - * consider the existence of this process to mean it can't release the - * shmem segment yet. We can now use PGSharedMemoryDetach to do that. - */ - PGSharedMemoryDetach(); -} - /* * PGSharedMemoryDetach * diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/p= ostmaster.c index 71ffb1345b..a10a9e0909 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -4834,8 +4834,8 @@ SubPostmasterMain(int argc, char *argv[]) /* * If appropriate, physically re-attach to shared memory segment. We want * to do this before going any further to ensure that we can attach at the - * same address the postmaster used. On the other hand, if we choose not - * to re-attach, we may have other cleanup to do. + * same address the postmaster used. On the other hand, if we choose to + * detach, get rid of any shared memory segment inherited previously. * * If testing EXEC_BACKEND on Linux, you should run this as root before * starting the postmaster: @@ -4854,7 +4854,7 @@ SubPostmasterMain(int argc, char *argv[]) strncmp(argv[1], "--forkbgworker=3D", 15) =3D=3D 0) PGSharedMemoryReAttach(); else - PGSharedMemoryNoReAttach(); + PGSharedMemoryDetach(); =20 /* autovacuum needs this set before calling InitProcess */ if (strcmp(argv[1], "--forkavlauncher") =3D=3D 0) diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h index 0535d4545c..88ad1c8205 100644 --- a/src/include/storage/pg_shmem.h +++ b/src/include/storage/pg_shmem.h @@ -79,7 +79,6 @@ extern void *UsedShmemSegAddr; =20 #ifdef EXEC_BACKEND extern void PGSharedMemoryReAttach(void); -extern void PGSharedMemoryNoReAttach(void); #endif =20 extern PGShmemHeader *PGSharedMemoryCreate(Size size, int port, --ZPt4rx8FFjLCG7dd-- --uQr8t48UFsdbeI+V Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlzbwE0ACgkQnvQgOdby QH1VZBAAkzp2z5+JDJ2VaeX+6vj8ScTJocaIpYi+ZhjQXUny3l798wv7a7XP5MU5 gcv8GpQLvUwJVRJTO2EHtVYKmxp1d5GdpWI6hzTDg4eYHj4uzgzq69UhGv2q54wF B7+VwKtn2O08ZNlJ8H/KsZUz1FS9nv7uFZWayfHI7wfAsodKH3yQsaseff21YgeO RjDuYzZutw1JGO1NHDuqwmHD/1EdWWhryIEfq/i8lDsCdxB3WZojgycwF+/s82rp AW/jB/Ueq6ApF2oLOxqVw/tiUA0HCa+nduE4XqqSATtsuHCy7REvbEHE8E7FQdwS ua28H5XAXRgdf3Ym55/ANLs7NoVcDOYqqrTshwKMrwfoSOlcYqqMB7UmIK658XPz 6gE8V7tVxANByccle6UxcGGl8gyT0PO97JOdBvC66sLOxQ9wppL4+THB1QnLUYDS m4E4qZ3Crn5AkX3bvmYXUjNlAX+7S4JZ5tb0ovsSRi2g5cIQpZVLjOYbOxRRjj6j uE2vWvm/9zsMYcfRxAa9NFUNr0VmXZYv+dbKhOf9HXjW+oLFbWu2m5CQcSgdNrky YEwj+IDrZvmmCxYInZsaUv6Mh0mAC0M69sNdY1jf6JaiwMXvWDVZjPu+kaxXsiD1 QXZeEtFaXunyxGUuWlG/Dsa8vMAlxe6rIjw5Gp0hWRFMFXP+ytQ= =t0JI -----END PGP SIGNATURE----- --uQr8t48UFsdbeI+V--