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 1x4MiX-00763B-1T for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2026 18:08:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4MiW-00H7Jd-1O for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2026 18:08:16 +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 1x4MiW-00H7JO-0F for pgsql-hackers@lists.postgresql.org; Wed, 09 Sep 2026 18:08:16 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x4MiU-00000004okX-0F1Z for pgsql-hackers@lists.postgresql.org; Wed, 09 Sep 2026 18:08:14 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-48441a2ba1bso4521242f8f.1 for ; Wed, 09 Sep 2026 11:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1788977292; x=1789582092; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-type:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=5vn09Mm3mQBXbRHHzuYrsq9BhC2axv7wbGYgdsB2/z4=; b=ATR1ZVNAdBY8WLRVlj0pLqYDn2vhUHg/PV5NlfV4r7zxhkBWwl4MGwtTt/X1bhqrAl /PDT2LTU3iCXfDHZS0deIm1HZr7uSp8lAfeNKMbtODYhdxf69UrXVrCkeUPW+C5v3cXt Ei4Z0izeXnPj8k8fRI164VFj0KYOmRbrK9GNCf7BSJYmEND9ZiCDDpxMTkgyfkiJF5YW jIoF6Mc1aONJd/zLANQVxZhVogjwsKwHvmr5FkkCYFwntIXXMVwqu2EAV1LP7BTSvRLw uzIzBOzSJICpypAs7cb7GMIm3n9rEFrmHbsmisV/oHiPYdTxrJ4jRuCTM2/DjkZZRPEO X3zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788977292; x=1789582092; h=message-id:date:content-transfer-encoding:content-type:mime-version :comments:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5vn09Mm3mQBXbRHHzuYrsq9BhC2axv7wbGYgdsB2/z4=; b=F1mslQK2QRkYy6+xU8Tsvy5M+QQ7WYJZticdATjov+ETWFD+OSaK5UXzxpeOKLyAbI nM3jRzkxZmOnIaYhTsZdmZyGBHo8nXuQyRJvUD/N9Ii0xjvJMEdJfz7RUp6INI21YxYX kbGOJj08mhpgaHL9PTtFLizIfsQfYJPVij/JzIffgZEHqanhMpzXJLM46KW5TLvz995e v9YRgS96EXHr183vRHVSEyuMdKl63QIZVZhWSGcx7s4a55jJgD9fyXKp24B0wvKchu37 bTCweAfyIm3too8tVJXCwWmiH/X3sZCuX/g2zcVzVucbVHnvDxI25owLXDucyDUIpob1 DyRQ== X-Forwarded-Encrypted: i=1; AKwUvBwfLAzdqAYEVI7x0s0FhhkXXFQ3/fs2MCMYCF2OHzbWVbrnQ0QeTJMJz2phCgUDTY9DQqh+f1C7K6O4af6f@lists.postgresql.org X-Gm-Message-State: AFuF++ns85trAHAf75d3NB+lKY0YQ1O39Zs+KE6ZdA8i80EhE4rwy0NU MxXL5S7zQtxFoOndcbMZvCjG5gdAw9U68masaG0Cg9e3+/Mq6pmBKCoCIvTqe1I6a4s= X-Gm-Gg: AYBFou2any2aVeeSjElXLMgF4+ZPf6Elh9lcmj2zP5zP3jmajthO2kRBYjyLFMg5Kcs tSkH+EJG6/XqrjvPMYlgxlF6i0QfkaDeDnNZaP7c5kmGMvqZKs/dTeuOGG0IrIKjo7YRKEdtkcJ YVH6IUZENLO7ppgrX4Z4Dg1Nf3gNjUmvhv4klvAqlRghfBbCrm0FX7kdYTTr0PmdOwVelD2m7aq tP8Hq/F6gHDIIVuMOa+CC8GIb/uRCqbb+/vziiIvKPBbt/1GjfGGNuaYtRlmL/upEaNY0hxxsOE emsmkLZqiuRSO0YxxnH9Vp3dWo4adWv7f6+EXL4+gJ09E9bv7pG4ugp+0Aun9RZLq6nebcxx7X6 q/UOQlWuCCE9J2pfAu2N8fJEYGL5xTQnQwlx1OLhopuPSVjcReC++j17gbeKawIAiVC5HzpdOQ/ Qd+I9AmWEvVvFTLlHRJfYCTALhVyzWprvqrwGdT7Pb8FA6+EkXoYNkiPkRWHxt4sg4S4lq7psu5 HnlUgoQe7hz X-Received: by 2002:a05:600c:4e0e:b0:499:bf8c:cfd1 with SMTP id 5b1f17b1804b1-49cf81e6063mr354634475e9.2.1788977292213; Wed, 09 Sep 2026 11:08:12 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49d1fb04f1esm62507095e9.0.2026.09.09.11.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 11:08:11 -0700 (PDT) From: Antonin Houska To: alvherre@kurilemu.de cc: "Zhijie Hou (Fujitsu)" , "pgsql-hackers@lists.postgresql.org" , Mihail Nikalayeu , Andres Freund Subject: Re: Race conditions in logical decoding In-reply-to: References: Comments: In-reply-to =?us-ascii?Q?=3D=3Futf-8=3FQ=3F=3DC3=3D81lvaro=3F=3D?= Herrera message dated "Wed, 09 Sep 2026 12:20:22 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 09 Sep 2026 20:08:11 +0200 Message-ID: <14036.1788977291@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =C3=81lvaro Herrera wrote: > Hello, replying to Hou and Houska emails in one. >=20 > On 2026-Aug-22, Zhijie Hou (Fujitsu) wrote: >=20 > > I think the cache might be better placed in the SnapBuild struct (at le= ast on > > HEAD) rather than in static variables. As currently written, it persist= s across > > decoding sessions in the same backend - a session could build a snapsho= t, drop > > the slot, and later create a new slot and build another snapshot, poten= tially > > consulting stale entries from the first builder. For example, it has a = wraparound > > concern: after XID wrap, a cached value could refer to a different tran= saction, > > causing us to skip the CLOG wait and reintroduce the inconsistency this= patch > > aims to fix. >=20 > Hmm, yeah, there's definitely a problem with that. Now, this bug can > affect logical decoding in existing releases as well, so we should > backpatch this fix, and I'm not sure about changing SnapBuild in > backbranches. Maybe another approach is to use file-level statics > (rather than function-level) so that they can be reset by slot drop > routines. >=20 > > Besides, just to confirm one note: IIUC, for exported snapshots by logi= calrep, a > > transaction could be treated as committed while still in PGPROC, while > > concurrent MVCC snapshots still see it as in progress which looks incon= sistent. > > I understand that waiting for ProcArray removal in the general case cou= ld > > deadlock against synchronous replication, so it's probably acceptable t= o leave > > it unchanged for internal usage in active replication processes. >=20 > OK. TBH I'm somewhat unease about this inconsistency; I wondered about > doing the CLOG-based test only in sync replication and using > XidIsInProgress otherwise, but didn't really try (which is to say: I'm > not even sure if it's _possible_ at all.) I'm trying to understand if this kind of inconsistency has the chance to be seen by users. I suspect the concern is about a session having isolation le= vel at least REPEATABLE_READ which scans the table two times using the same snapshot, however another session runs REPACK (CONCURRENTLY) in between. Due to the inconsistency explained above, the snapshot might miss some changes that REPACK already does see. IMO the 2nd scan will not see a different version of the table the table had to be locked before the first scan started, so REPACK won't be able to fini= sh until the whole transaction is finished. Even w/o keeping the lock between = the scans, both scans would retrieve the same rows as long as REPACK (CONCURRENTLY) is MVCC-safe (currently it's is not, but should be in the future). Regarding logical replication, yes, this inconsistency can be the reason so= me data changes are already visible on the replica while some snapshots don't = yet see it on the primary. However I think that can happen anyway if the MVCC snapshot for the scan on the primary had been created before the snapshot f= or the logical replication. Maybe I've just misunderstood something. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com