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.94.2) (envelope-from ) id 1vBMJI-00FZ0k-AP for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 00:02:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vBMJG-00CX5D-W9 for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 00:02:34 +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.94.2) (envelope-from ) id 1vBMJG-00CX54-3y for pgsql-hackers@lists.postgresql.org; Wed, 22 Oct 2025 00:02:33 +0000 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vBMJD-00345C-0Z for pgsql-hackers@postgresql.org; Wed, 22 Oct 2025 00:02:32 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id C10A51D000EA; Tue, 21 Oct 2025 20:02:29 -0400 (EDT) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-04.internal (MEProxy); Tue, 21 Oct 2025 20:02:30 -0400 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=fm2; t=1761091349; x=1761177749; bh=yVp4eR+NfTIENfHzBv2p5xTzqspturIy1YxqMuYiclo=; b= DAEz4xqrhkNc7POpLfjBuyEoA+whl2xKz0Z4SWoLaXOKWbIG8vd89CFYgw2aUQOM +N9JDGOl8VMMghtTSQyf6uvpsGQLDHVqwQPLkaLPnJyZw31Pj4qj4tFrKMdGajvG wtWe4Pjtzhdur0r5tJ/RtFIRiN0wI1Xm4IVQtR8++769NQ7uLYieYIe7Mp2aGmiN zMktmgBM78VtRAHhPibzQNC5HkLl1ZNOZpZwfGqqI99WTLrdKNy74xvDuDBKfV9J d3NhUnlhhzz72GmnusWIEoiLK688tIA+xFQTWnts9zJKWcxkIPE8yG0psJ4EcGcC iPr44V1GE8XrA0mj8jzHtQ== 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=fm2; t=1761091349; x= 1761177749; bh=yVp4eR+NfTIENfHzBv2p5xTzqspturIy1YxqMuYiclo=; b=O kwNRuPAS0/V4WStyLw91wPx7kEU01VcDYec/kP/dfFrycmE1NVgZ+U+4xZkydr8c DmwoqSlqVrM79TcgUwG/mANoXiUN9ehsPiIkcLI7A7W1GmEE5BusjkAYqXTNIy5I WJ1GBSydLrpYovoSMIuUW3oi6Jr6e4ft7EAjYKfwHWGXypwxKWbjpoeEsY9mlu/b VuKYNNXgdnxbNjs+k6GP7rnnXdDNoyXrgvqV2wrQb/T8Z0mgbmeDOJLKXLMh/w+c +xeL/lNWSsf/SqI++Fg7KOVMHnh9NsVnh/CpontUADOlWdoBsuGyb/po2KTiu69/ qFWrM6mYxqIXuvRzX0Xnw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddugedvtdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgfgsehtqhertdertdejnecuhfhrohhmpedflfhovghl ucflrggtohgsshhonhdfuceojhhovghlsegtohhmphhilhgvrhdrohhrgheqnecuggftrf grthhtvghrnhepgffgueehfeehueefgeekieeffffhgfevffdtudeuhfefleetgeelhefh tdeivefgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epjhhovghlsegtohhmphhilhgvrhdrohhrghdpnhgspghrtghpthhtohepuddtpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopeefuggrnhhishhsihhmohesghhmrghilhdrtg homhdprhgtphhtthhopegrlhgvgigrnhgurhgrrdifrghnghdrohhsshesghhmrghilhdr tghomhdprhgtphhtthhopegrrhhsvghnihihrdhmuhhkhhhinhdruggvvhesghhmrghilh drtghomhdprhgtphhtthhopehmrghthhgvuhhsshhsihhlvheljeesghhmrghilhdrtgho mhdprhgtphhtthhopehrihhshhhurdhpohhsthhgrhgvshesghhmrghilhdrtghomhdprh gtphhtthhopehsrgifrggurgdrmhhshhhksehgmhgrihhlrdgtohhmpdhrtghpthhtohep rghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvpdhrtghpthhtohephidrshhokhholh hovhesphhoshhtghhrvghsphhrohdrrhhupdhrtghpthhtohepphhgshhqlhdqhhgrtghk vghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C0F8418E0054; Tue, 21 Oct 2025 20:02:28 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AYKEI1WM5q2o Date: Wed, 22 Oct 2025 03:02:08 +0300 From: "Joel Jacobson" To: "Matheus Alcantara" , "Masahiko Sawada" Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , "Arseniy Mukhin" , "Rishu Bagga" , "Yura Sokolov" , "Daniil Davydov" <3danissimo@gmail.com>, "Alexandra Wang" , pgsql-hackers , "Tom Lane" Message-Id: <7726d706-4a11-4747-900e-ea27f8de9b65@app.fastmail.com> In-Reply-To: References: <202510201414.56f2msqusjla@alvherre.pgsql> Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Oct 22, 2025, at 02:16, Matheus Alcantara wrote: >> Regarding the v8 patch, it introduces a fundamentally new way of >> managing notification entries (adding entries with 'committed' state >> and marking them 'aborted' in abort paths). This affects all use >> cases, not just those involving very old unconsumed notifications, and >> could introduce more serious bugs like PANIC or SEGV. For >> backpatching, I prefer targeting just the problematic behavior while >> leaving unrelated parts unchanged. Though =C3=81lvaro might have a >> different perspective on this. >> > Thanks very much for this explanation and for what you've previously > wrote on [1]. It's clear to me now that the v8 architecture is not a > good way to go. How about doing some more work in vac_update_datfrozenxid()? Pseudo-code sketch: ``` void vac_update_datfrozenxid(void) { /* After computing newFrozenXid from all known sources... */ TransactionId oldestNotifyXid =3D GetOldestQueuedNotifyXid(); if (TransactionIdIsValid(oldestNotifyXid) && TransactionIdPrecedes(oldestNotifyXid, newFrozenXid)) { /* * The async queue has XIDs older than our proposed freeze point. * Attempt cleanup, then back off and let the next VACUUM benefi= t. */ if (asyncQueueHasListeners()) { /* * Wake all listening backends across *all* databases * that are not already at QUEUE_HEAD. * They'll hopefully process notifications and advance * their pointers, allowing the next VACUUM to freeze furthe= r. */ asyncQueueWakeAllListeners(); } else { /* * No listeners exist - discard all unread notifications. * The next VACUUM should succeed in advancing datfrozenxid. * asyncQueueAdvanceTailNoListeners() would take exclusive l= ock * on NotifyQueueLock before checking * QUEUE_FIRST_LISTENER =3D=3D INVALID_PROC_NUMBER */ asyncQueueAdvanceTailNoListeners(); } /* * Back off datfrozenxid to protect the old XIDs. * The cleanup we just performed should allow the next VACUUM * to freeze further. */ newFrozenXid =3D oldestNotifyXid; } } ``` Maybe it wouldn't solve all problematic situations, but to me it seems like these measures could help many of them, or am I missing some crucial insight here? /Joel