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.98.2) (envelope-from ) id 1xENjm-000000014fH-0dmM for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Oct 2026 09:14:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xENjk-00000005ctM-0Kyf for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Oct 2026 09:14:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xENjj-00000005ctD-33hl for pgsql-bugs@lists.postgresql.org; Wed, 07 Oct 2026 09:14:55 +0000 Received: from mail.w14.tutanota.de ([185.205.69.214]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xENjg-00000000rWM-2wYU for pgsql-bugs@lists.postgresql.org; Wed, 07 Oct 2026 09:14:55 +0000 Received: from tutadb.w10.tutanota.de (w10.api.tuta.com [IPv6:fd:ac::d:10]) by mail.w14.tutanota.de (Postfix) with ESMTP id B6ED919144F90 for ; Wed, 7 Oct 2026 11:14:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791364461; s=s1; d=rhyadav.dev; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Content-Transfer-Encoding:Cc:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=xveDif2D0viqz85kvVTeeVB7NN9FCjuE4pchch9iE9A=; b=T1L1wjxLeWmR0kZXdqT/pHTAmeN+872qYyUBGXRDo+ab9KgxEDQYzM1/+60V3yUU JUMunwE10xPoVpDVBc5kXwLWVeNTCK4At1rhw1Ra1Toy/D4vpZ2dvCGmfwiLnoSNwxQ Zgv7WK/PW5COiNvAcBjq/8qehMdafoZjrc8STlLBHHyAQKfnbigDHSxSVQph1DaX+vt O0xL6DZ5KfwhKu4zkwvTyxGAQYTsWabBJJqKCOwNsU1Ib7g0GhWgSBEvFj0VP1elE9H p5dzbEj5CyYcBcRD7arJxZMd+0gRWaGA59jtZdeJw/ix9mgZHH33y4YGEawKOqcrhEO DeFZ8d06pQ== Date: Wed, 7 Oct 2026 11:14:21 +0200 (CEST) From: Rahul To: Yk Verma2000 , Pgsql Bugs Cc: Pgsql Bugs , Yk Verma2000 Message-ID: In-Reply-To: <19733-5fcd39e85fa221a4@postgresql.org> References: <19733-5fcd39e85fa221a4@postgresql.org> Subject: Re: BUG #19733: Row not visible to a new snapshot after its transactional logical decoding message has been streamed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Feedback-ID: 01f8c5108c48fea26a092a077590a8fcdbfcdbb733bc38e3db5db9540fc242b99227bb05256e786b1fc713cdb05f073377d63f8aec9e32cbf77d26f42c5d89118b:TurnOnPrivacy!:tutamail List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Yash, Thanks for the detailed report and the scripts. I think this comes from the order of the steps at commit, in CommitTransaction() (src/backend/access/transam/xact.c): =C2=A0 1. RecordTransactionCommit() writes and flushes the commit record, =C2=A0=C2=A0=C2=A0=C2=A0 and waits for synchronous standbys if there are an= y. =C2=A0 2. After that, ProcArrayEndTransaction() removes the transaction =C2=A0=C2=A0=C2=A0=C2=A0 from the procarray, which is what makes it visible= to new =C2=A0=C2=A0=C2=A0=C2=A0 snapshots. A walsender can decode and send the transaction as soon as its commit record is flushed, so a fast client can receive it and take a new snapshot between steps 1 and 2.=C2=A0 That snapshot still treats the transaction as in progress.=C2=A0 This isn't specific to logical messages: any decoded transaction can briefly be invisible on the primary after the client has received it. I couldn't hit it on unmodified master here (macOS, about 210,000 messages each with your settings and with 64 clients).=C2=A0 To confirm the window, I added a 20 ms sleep just before ProcArrayEndTransaction() in a test build and ran your setup with 8 clients for 10 seconds: =C2=A0 plain SELECT=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 3430 of 3456 reads stale =C2=A0 SELECT ... FOR SHARE=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0 = of 3318 =C2=A0 wait until the xid is visible first=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0 = of 3608 FOR SHARE works because it waits for the writer's row lock, which is released after step 2.=C2=A0 It doesn't help for rows the transaction inserted, as there is nothing to lock yet. A more general workaround is to put the writer's xid in the message and have the consumer wait until it is visible before reading: =C2=A0 -- writer =C2=A0 SELECT pg_logical_emit_message(true, 'outbox', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ... || ':' || pg_current_xact_id= ()); =C2=A0 -- consumer, in READ COMMITTED, repeated until it returns true =C2=A0 SELECT pg_visible_in_snapshot(''::xid8, pg_current_snapshot()); I don't see a quick fix.=C2=A0 Making decoding wait until the transaction is visible would deadlock when the walsender is a synchronous standby, because the committing backend waits for it in step 1, before the transaction becomes visible.=C2=A0 The longer-term direction is making visibility follow WAL order, which Jeff Davis's "Commit Sequence Numbers and Visibility" thread on -hackers discusses [1].=C2=A0 This report is a concrete case for that discussion. [1] https://postgr.es/m/ea6ecdc74dbce67849526668a461bc4760241439.camel@j-da= vis.com Regards, Rahul Yadav