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 1x7aS4-00000000V2C-2LAp for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2026 15:24:37 +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 1x7aR4-0000000210n-03fB for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2026 15:23: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.98.2) (envelope-from ) id 1x7aR3-0000000210c-2waa for pgsql-hackers@lists.postgresql.org; Fri, 18 Sep 2026 15:23:33 +0000 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x7aR1-0000000031S-1m5x for pgsql-hackers@lists.postgresql.org; Fri, 18 Sep 2026 15:23:32 +0000 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ce364488dso2886875e9.0 for ; Fri, 18 Sep 2026 08:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1789745010; x=1790349810; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id: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=4G9dMMM1T/u7hkaTKMo6BmIoZPXoMgnSkj1WUkRKo1Q=; b=MrOLuxlKO2Fu2vGiBxlRJaWPxDT3pAs+YmqiUG8ehXJlNf4GHOd57PEtPfYgk/QNNV 3rJIihqwgxcziKu5y89fmtqgu9ObQNBfmmhXxeY3I9JLpEqYP48L7EWH6Tw+My8o7CBx sNO2qGxIgzVw75xOBVt2+qER1uUk+dlCFU+iigLHSB8DrCb++hNKyiZHpbPxdsnByEfP Pn1M+1f996pj9yPz5h0C4mnnAQS6geNv5jSL+wnyGzV1j5CboxsdvdkxQqaVG97h6Ipl me1lLlLy7/2tEl5hHVi59pY9sDJqUY8hpyL9FQ3qBHYEw5eA5U1i2pt1fXMV47RMh9Kp do8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789745010; x=1790349810; h=message-id:date:content-transfer-encoding:content-id: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=4G9dMMM1T/u7hkaTKMo6BmIoZPXoMgnSkj1WUkRKo1Q=; b=ybyvZ1ij1d0p3692ZSE3KKFk/7QHcuwVUa+U8Ys8dx4PFyItcrTbl2brwIEX32zJnp fMMFLrqmztlTjQzaUWgMYwK3e5iMPFAmin5qwYxh813moDc2YdhEENbpOT6RnUFK+1LY HkEB0GYrX7V4jtTLwNjFct/OLLANZc9+veHap7Z7lhT7VwuJM8VDq2CnQE1/bkhmYU2Q /K6ZKEHPGj5YFrvK8Yx+uaRmLldZLWcxs8vnhwrzQjtmeNii+obzqvJNX439fhKXeqCU gnPKHilw3YCJ8ODTAAHg9sTuTsdAwqhjTIQlFkYiSrbYpX+Regwofttr+aa7Z5hrvZxk FekQ== X-Forwarded-Encrypted: i=1; AKwUvBy5b0vW1EFAZCGvA725v19cg/35qu/1uGMakZbHo5wY7sNRMon93ZHCqcRPTcFk5uVASAdAxf6197QNRXbq@lists.postgresql.org X-Gm-Message-State: AFuF++kT1i007oDh1qVkGpSQitlV/CtCj9NrPQGEhL8+Qci+rhVn0RRq PuyOQGyZK/MzmlMOMYhrmr4yM43iKDm1PhoSTmkmV4qlMCMp4Io8w5oo1Yc7cSnXVQg= X-Gm-Gg: AYBFou0Qv/zDjs9+hGmxGQcw5lLGeapWK+J2ySXwLBkcG6mbBEybMtdVYTmJnJSCxJJ Tvvk8ZJyIgcfmxhcS/vLla2NZqI/au/1jGG+O4GX6gRcP2Cf6znj0HXP1HiS5hpmmwt2ILXUcRl f1AK6Cz34FQeabCeb59zRPBKmMHfJG11I1utVljtxdrbQPqASIP6aEZrNuAGEzoWuk5kvjS3fVe GC5zrpo2l4TSZ6yxnAqvZUABsfCRcCl9pdeskmd7698uvqwtJ9foyQtOghtpO77nvk9BWsDmCkc xTsaHufQznaAJX4RetpAMd0hgtZiXZwEWEoyUnYR5cUjCTrfymXjRpyOgW/v1Ddv+ND78vHaerC J01PtNtO9j7kBznpnz1hDO7OMY2K7od55TeIWCGqo61sVLjy6gdjivd8fREgq+TPCo0JjzlRC49 1Y1uxuXgaZZxMZ7kiHnPgxu2dK3gLxiCrqIFDnnid9S+qGxP7Ni0ALz6xxioW3iH/Vni7SUWD13 09PmgZNVzom X-Received: by 2002:a05:600c:8a95:b0:49b:8f5e:51fb with SMTP id 5b1f17b1804b1-49fc52783f3mr33607305e9.3.1789745010484; Fri, 18 Sep 2026 08:23:30 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc53b1b78sm42444665e9.3.2026.09.18.08.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 08:23:30 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Rui Zhao , Andres Freund , pgsql-hackers@lists.postgresql.org, Mihail Nikalayeu Subject: Re: Race conditions in logical decoding In-reply-to: References: Comments: In-reply-to Alvaro Herrera message dated "Fri, 18 Sep 2026 16:29:20 +0200." 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: <12833.1789745009.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 18 Sep 2026 17:23:29 +0200 Message-ID: <12834.1789745009@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera wrote: > On 2026-Sep-18, Antonin Houska wrote: > = > > Maybe I miss the point, but what's wrong about modifying the existing = loop > > that inverts the meaning of the ->xip array > > = > > /* > > * snapbuild.c builds transactions in an "inverted" manner, which mea= ns it > > * stores committed transactions in ->xip, not ones in progress. Buil= d a > > * classical snapshot by marking all non-committed transactions as > > * in-progress. This can be expensive. > > */ > > for (xid =3D snap->xmin; NormalTransactionIdPrecedes(xid, snap->xmax)= ;) > > { > > ... > > } > > = > > by calling XactLockTableWait() for each XID we find in the array (i.e.= each > > committed transaction)? > = > Ah, you mean something like the attached quick POC? This does pass the > two tests that Rui wrote, also attached. (I didn't test Zhijie's, which > AFAICT is written to pass with the bug and fail without it.) Yes, I mean checking if those transactions have really ended. Regarding [1], perhaps the idea is to avoid calling XactLockTableWait() if= the transaction is no longer in procarray. I'm not sure it's a problem to call that function (possibly many times) for transactions that are no longer running. (GetRunningTransactionData() is not free either.) And regarding the deadlock with synchronous replica, my understanding is t= hat we avoid it by waiting in SnapBuildInitialSnapshot() instead of in SnapBuildBuildSnapshot(). [1] https://www.postgresql.org/message-id/CAHWVJhHXyLtS-8mdL9WhEWfsERb%3DF= N7JdPD0GYAXgTmCnqbYGw%40mail.gmail.com -- = Antonin Houska Web: https://www.cybertec-postgresql.com