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 1vjC7X-00AOpA-2p for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 08:02:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vjC7W-00GfkO-09 for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 08:02:18 +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 1vjC7V-00GfkG-2J for pgsql-hackers@lists.postgresql.org; Fri, 23 Jan 2026 08:02:18 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vjC7T-001tW8-1n for pgsql-hackers@lists.postgresql.org; Fri, 23 Jan 2026 08:02:17 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4801bbbdb4aso20561105e9.1 for ; Fri, 23 Jan 2026 00:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1769155335; x=1769760135; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=J1XSdlqb5hT6S30bdmre0RCdzumlnvInS2viRR+exUo=; b=qTXW9MlZ/b8fm5dQjV0Ijau6nxYAajbHkHn8y7pKmbDDLuWudaSTo2o/aAncg/ziQw m2Q65aniKcYLqBBbjzehKmYrJ2OZ+FyAabVSdka2x09nFe/ZER+460AZmf0h2jji8rkJ ONOjxXvf9NNjtqloZ5doILb5I4lM40ayiM88ZXdzyb+tdMrKLgtuYgDywmQhzv5sVVKQ yxwmr8CHotLsAyjdlLfI2fgsIsTYugGeDNw85HXgb3ZiuPZa9EBjKO7z/Ra5pSpRqbk/ ask+wyex4gCDs15M2JyvQ+ddG3n+g/rE60k+yr2Fn1YMidnVx+pTM4w7tRXZ3drM4D/H n92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769155335; x=1769760135; h=message-id:date:content-transfer-encoding:content-id: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; bh=J1XSdlqb5hT6S30bdmre0RCdzumlnvInS2viRR+exUo=; b=dxpSAgb9M575n0yyo2ZxHQFfFtqiCGRRB1At1e/r6JubcEvpue0/5SE7Z6EWwRN69j c+YGC4WMncBY0BuAgcTjmrLQrkVRduhyPpSngF0U6A7J/uSUp87hFTrdNT9BY8NoKcAi unfVA8iKMDL+UTXSKN2iuXjc4YPWyNJ1o7ylgeBvmJ38GT+TST091ooMpblDlKu2WiLK LET6nwMxRoxo67zEnBmmeocM88ECfnWSvoEWORA7Pi/mvch8yFazFGNTtgKuy0vA9q3f 8PkBa4JQI2+QGmZQMbBwET+sdbYpvTEc6qFvl0ods6oRp36rxgP2l2vJnt+sacSNR6DG dsrw== X-Gm-Message-State: AOJu0YynLjsAS8936N4k0/OBk2NkjrHM5njevk3zRcDWdmimm8K3NHB+ uYSwOtLBLgF7RBMi/0xtoa/cH7h4HR9lkFEgKlDBnidEelly741mhmy7g1eKwKxTGvhwln//Er1 3BSLu X-Gm-Gg: AZuq6aIicHniRo2IInF+2wuc0WJVF7LsBtJ5u9tEmghEMle7AbGkCg7iriPAOC5mFb+ dKfMwxLwtn1WjeKaxu2PnlZbFvpo31nZQNyp3labLyk3DV1ZCLlMXnoNohHZr/skr/uw3sPLXmS hUUwN97lYPNxTAXM7RygaKxL3a9Dr2roUVPZP8B3a3F4fTssoia4UEpP9BqnP9feYqAscqTnx2j J8d3lAlJNPjKdNZmpNL2LYvUCoF7tTcCLRPSGqaTQ6wTFRj9S4B+wGh+9IYsTJC3x+VEG6yPsCw USpfQy0+1k5ifOq3Q2XYISKVXFIbVQNlVV3ZkfMF5d/5wkehXNsebH4C40RT/pD3yfEvXUqOhMN T9bgxsrmBiPwV1A0rJcfLroMKx9zoIgU5fL41I8SNfnGSb6A6mMqn2IAdSG5+EBx/6khl9KLBgP zMbzUldFJ2T73i4Hzoofpw2r5r X-Received: by 2002:a05:600c:c119:b0:477:a71c:d200 with SMTP id 5b1f17b1804b1-480470b7cfbmr68388615e9.11.1769155334675; Fri, 23 Jan 2026 00:02:14 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4804d4faecbsm16588865e9.1.2026.01.23.00.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 00:02:14 -0800 (PST) From: Antonin Houska To: Andres Freund cc: pgsql-hackers@lists.postgresql.org, alvherre@kurilemu.de Subject: Re: Race conditions in logical decoding In-reply-to: <5k2dfckyp6zv2fiovosvtbya5onvplgviz5n4kdamxupff4vi2@yytzfnwr2ox7> References: <85833.1768840165@localhost> <62335.1768897833@localhost> <5k2dfckyp6zv2fiovosvtbya5onvplgviz5n4kdamxupff4vi2@yytzfnwr2ox7> Comments: In-reply-to Andres Freund message dated "Tue, 20 Jan 2026 12:50:13 -0500." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5697.1769155332.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 23 Jan 2026 09:02:12 +0100 Message-ID: <5698.1769155332@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund wrote: > > Attached here is what I consider a possible fix - simply wait for the = CLOG > > update before building a new snapshot. > = > I don't think that's enough - during non-timetravel visibility semantics= , you > can only look at the clog if the transaction isn't marked as in-progress= in > the procarray. ISTM that we need to do that here too? I understand that CLOG must be up-to-date by the time the snapshot is used= for visibility checks, but I think that - from the snapshot user POV - what matters is "snapshot->xip vs CLOG" rather than "procarray vs CLOG". For procarray-based snapshots, this consistency is ensured by 1) not remov= ing the XID from procarray until the status is set in CLOG and 2) getting the = list of running transactions from procarray. Thus if an MVCC snapshot does not = have particular XID in its "xip" array, it implies that it's no longer in proca= rray and therefore it's been marked in CLOG. As for logical decoding based snapshots (whether HISTORIC_MVCC or those converted eventually to regular MVCC), we currently do not check if CLOG i= s consistent with the transaction list in snapshot->xip. What I proposed is = that we enforce this consistency by checking CLOG (and possibly waiting) before= we finalize the snapshot. Thus the snapshot user can safely assume that the snapshot->xip array is consistent with CLOG, as if the snapshot was based = on procarray. Or is there another issue with the CLOG itself? I thought about wraparound (i.e. getting the XID status from a CLOG slot which is still being used by= old transactions) but I wouldn't expect that (AFAICS, CLOG truncation takes pl= ace during XID freezing). Concurrent access to the slot should neither be a problem since only a single byte (which is atomic) needs to be fetched dur= ing the XID status check. Another hypothetical problem that occurs to me is memory access ordering, i.e. one backend creates and exports the snapshot and another one imports = it before it can see the CLOG update. It's hard to imagine though. Or are there other concerns? -- = Antonin Houska Web: https://www.cybertec-postgresql.com