Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vNzRI-004gGi-18 for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Nov 2025 20:15:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vNzRG-00BJwv-2P for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Nov 2025 20:15:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vNzRF-00BJwi-2d for pgsql-hackers@lists.postgresql.org; Tue, 25 Nov 2025 20:15:02 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vNzRD-001Rzr-1g for pgsql-hackers@postgresql.org; Tue, 25 Nov 2025 20:15:01 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1E7311400215; Tue, 25 Nov 2025 15:14:59 -0500 (EST) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-05.internal (MEProxy); Tue, 25 Nov 2025 15:14:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1764101699; x=1764188099; bh=Q1RInTFigN5UkjBz+qygY4We+v7BNJTF8fG/OzN99S4=; b= POd4Xjxlc8ItGrKXv1bl4Qz+sH1OAqMELMePJ+i0u1A0F9kTgQKyZ9/fBeW1oVCB fqXnE74KOaPaIo8GRh06tY3RllOHcQNkg8NIGDmWcw6jJPgXSIUcmPnfRQH3mJuw bFyLYZQZaKn2u2eGHOS6B9QOdhiEBy1jxyQKrgmhoVIS9zytT1usRD6nExEwGEFZ MnTeAPxGUoxE6/dRDOS1i0L2dZ2JinKLO4LDZm0l9WRN7mq6MVDIkcUhvKzu68y5 kWuNYoZ+dks3E/sUU3R5R5l0VpGWvEXKuxK3JiHR9b0jGWi+9zxUrYOWy1tp37oD H3BlZI6pi/AdHOu7UWIe/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1764101699; x= 1764188099; bh=Q1RInTFigN5UkjBz+qygY4We+v7BNJTF8fG/OzN99S4=; b=H ZQX8kQryb2Fxru28wjyZNOhN5FchuQhgZwbKYKKj6BhbfEj//AlEGd4vmEfRmWdW SJ5sJ5TgE8b46zNTP7Ym5iyuj0ueesRmKif9lk1P83v9cqtRTcybTyq+sp5kysCm 4Ru2Ke+TG9UxtYDlyXJG6gvT1NMBm1poZ1x4SL+TnsfAs80teru1kk62pyLDExTy pgxJU0Tr2oQJPUit0ej4uyIDGGmsJBbpjuEIWGJU2/B4QJ1Z4sjUeI+9FKXigVi2 mCJ1nGqkdjeHc3qjBPkvB9NYcoVBriw62Fe6pNYWlwWtMJrwDySG3SBXwlS28NUt RiEOv0R2OB9Vlse7pdQCQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedvgedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvvefkjghfufgtgfesthejre dtredttdenucfhrhhomhepfdflohgvlhculfgrtghosghsohhnfdcuoehjohgvlhestgho mhhpihhlvghrrdhorhhgqeenucggtffrrghtthgvrhhnpeefheelffegvdelfeevteejtd ekteefleeihfdtudelkeeijedtvefgueevieekieenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehjohgvlhestghomhhpihhlvghrrdhorhhgpd hnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihdr vghvrghnrdgthhgrohesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrg gtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehtghhlsehsshhs rdhpghhhrdhprgdruhhs X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 94CFD18E0069; Tue, 25 Nov 2025 15:14:58 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AE1r89ybsZ1g Date: Tue, 25 Nov 2025 21:14:12 +0100 From: "Joel Jacobson" To: "Tom Lane" Cc: "Chao Li" , pgsql-hackers Message-Id: <96a9778e-ffa5-42a6-8524-4793ed45efca@app.fastmail.com> In-Reply-To: <2067239.1763670416@sss.pgh.pa.us> References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> <1073593.1759423179@sss.pgh.pa.us> <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> <85828f29-e72e-4400-94f3-9a69bc8dc239@app.fastmail.com> <2495353.1759860890@sss.pgh.pa.us> <8aeae418-92a6-4bbd-9c06-9574c79e59f7@app.fastmail.com> <2531672.1759868124@sss.pgh.pa.us> <474efa78-337c-41cd-a73a-f845a0115109@app.fastmail.com> <2749343.1759949176@sss.pgh.pa.us> <8bfca2be-1ec0-4e15-aafb-0b7b661fe936@app.fastmail.com> <9eba307f-f2fb-48f0-9507-2e197f39ef9e@app.fastmail.com> <8c71183a-0d28-4bcf-a806-78446ff95404@app.fastmail.com> <1009807.1760476747@sss.pgh.pa.us> <1F7227F5-C33D-4E2C-8511-33F1468590D0@gmail.com> <0a5a20d3-4621-46b3-b2ab-903f63a20dea@app.fastmail.com> <6F913129-ABEF-4004-AAF3-F22FC3!4!29AE8@gmail.com> <1547585.1760645808@sss.pgh.pa.us> <14865EB6-0BF4-462B-9072-10BDAC10C0> <2067239.1763670416@sss.pgh.pa.us> Subject: Re: Optimize LISTEN/NOTIFY Content-Type: text/plain Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Nov 20, 2025, at 21:26, Tom Lane wrote: > So I think there needs to be a serious effort made to move as > much as we possibly can of the potentially-risky stuff into > PreCommit_Notify. In particular I think we ought to create > the shared channel hash entry then, and even insert our PID > into it. We could expand the listenersArray entries to include > both a PID and a boolean "is it REALLY listening?", and then > during Exec_ListenCommit we'd only be required to find an > entry we already added and set its boolean, so there's no OOM > hazard. Possibly do something similar with the local > listenChannelsHash, so as to remove that possibility of OOM > failure as well. > > (An alternative design could be to go ahead and insert our > PID during PreCommit_Notify, and just tolerate the small > risk of getting signaled when we didn't need to be. But > then we'd need some mechanism for cleaning out the bogus > entry during AtAbort_Notify.) [...back from a little detour with new insights...] It looks to me like it would be best with two boolean fields; one boolean to stage the updates during PreCommit_Notify, that each pendingActions could flip back and forth, and another boolean that represents the current value, which we would overwrite with the staged value during AtCommit_Notify. This way, cleanup for the rare edge-case when we did PreCommit_Notify followed by AtAbort_Notify, seems simple; we just need to go through all entires and delete those where current=false, since those entries were newly added by PreCommit_Notify, i.e. we were not listening to those channels since before. Probably also setting a flag in PreCommit_Notify, so that we only need to do cleanup in AtAbort_Notify if we actually hit PreCommit_Notify. I haven't implemented this yet, but I have a good feeling about this approach. Just wanted to share the plan before I start working, in case anyone see any flaw with it, or see a better approach. /Joel