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 1wMWKQ-0009NP-2Q for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 19:30:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wMWKO-002GYE-0h for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 19:30:08 +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.96) (envelope-from ) id 1wMWKN-002GY3-2i for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 19:30:08 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wMWKL-0000000067d-0sGA for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 19:30:07 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-488b150559bso36537295e9.1 for ; Mon, 11 May 2026 12:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1778527803; x=1779132603; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3IiSMuLHoW429QHh3h3P6W/LIGg8ue6/PhN5lZmTsE4=; b=GKTo0ikwhu25GCAvkZy1jYJbIlhib78hdXhBKSQxc2+Uh5wOqQwZLxkjyIfH69dZQY cGsexcxUd1abD1BSnV+/xYRxD5nAl0EAZnzEJVUb7Xy+TWTWBTK+6YCn/p/k7w3TCDeq fqI7zpxAxZdvQo5G1NbDbgAKQ0c+eK5SQLU6J0HRAYz39eBJOidp1+/UyQe+/YtfUb1m 91ucawlYlCRGaXpWnsUlO62rgL2EXQbObpR/ob4OvphdjpDsgla4/a1i/QFa568F20zm SLfbQUJm4MzqCxeEXYGctoQJ9+FbiIKDewi2hBu3byPk/ZgNM0ulndsqHRr/44tPSaOt aNrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778527803; x=1779132603; h=message-id:date:content-transfer-encoding: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=3IiSMuLHoW429QHh3h3P6W/LIGg8ue6/PhN5lZmTsE4=; b=Um41cHJJ/v78pM/CtADPtR6RG3qatAG+2nLRFj7HtPaoL4H09780wwZzcFmUyCHFUA b5LLQgRGcE5A2Im3NS+6ha8EdbGFwcrECW6C/lVLIp8XZ6/WrOUTu9xGwNBmp4Lvsdfz 2BGvtbZZ+2L6rK5T3ERZtFfjAMhAiYKwDqWEf7u5G5Z/8Na04WMAVjpzsizx9TZBEVBc XHZDWO+ht3GNxzglm7Cyf2SfZ0hW9wFdJJpLgV3Dk1ppWBJ02tMFUV3cCeEkrGLYpjZZ aKxKjvDYSS2xKRuLdZAnvTe6eI/PuZisec4lFAaSaDE4ekkewM8jQuquL6SG1z7RfFW4 Ty0Q== X-Forwarded-Encrypted: i=1; AFNElJ9IHmSgy+CRr37l9RmU/juFGbD5OK+p0VacrRU4XAeMSlxyHfJQi96OxC8S4FSGPRSqZAhOaQVHG68VYJHA@lists.postgresql.org X-Gm-Message-State: AOJu0Yw/xa5ghN+acNer0dEOiMVyk/EWdqvAeNPwu2tEI8FtUVzDP81L /pugE1iC+qV3hscLIcMjEVoFJuaNc0MeuMTKZHAaEiozkrl2VKbXhnPNcQkhFTg4lFo= X-Gm-Gg: Acq92OEatUNG4SRoRqVlmfb/AvHXpSQ3HxQHuZC1sgbJV8ZnVSsmS0yCfE85j1QBRyR Mh5ZSZz4V3jCCPHXNk6KU5de+44QP1YSNccQ3sXu4fCYDPrivOE9B/F0CPJi6nsocoDuUg9nVJ7 BwIIxVHeDHSuLKK6UrjC9YB+TeMFxVaJybFoNfEYTNTLxKvZQwQa8oi6AEX4G0jrKAGqDd+Z8qg pwbaFN9/13eYD0Etc0sGzqH6a5rcwuDnkpMElVdCa68mAcV+4yzdSu2LtqKz9uQjX+CJ8DCez2Y b5InvDxtrj5tRtJa4UBrFOp2uddAbOg+pMDMrFEiGzEp5xuEYutdCQTvaI8QlHT7M4E3hbZPiKH i/n+MHOz7jvYm201MBfM3jCVhJEpySrGGp/rdPPhLhcjGEomNDA94czoe03+p0NFfV3rk5pKKFk LSMOkjCNEzdhPrazHaOyRkqPoxJY2Gnf9lzpm9 X-Received: by 2002:a05:600c:46c6:b0:486:ff92:63e5 with SMTP id 5b1f17b1804b1-48e706acf88mr179196155e9.6.1778527802903; Mon, 11 May 2026 12:30:02 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8e5efe57sm4877935e9.2.2026.05.11.12.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 12:30:02 -0700 (PDT) From: Antonin Houska To: Amit Kapila Cc: Mihail Nikalayeu , Andres Freund , Alvaro Herrera , Srinath Reddy Sadipiralla , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: <70574.1778512672@localhost> References: <202604071230.b5axxf3qna3m@alvherre.pgsql> <227677.1775576304@localhost> <85813.1777901089@localhost> <27869.1777985266@localhost> <70574.1778512672@localhost> Comments: In-reply-to Antonin Houska message dated "Mon, 11 May 2026 17:17:52 +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: Mon, 11 May 2026 21:30:01 +0200 Message-ID: <82942.1778527801@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Antonin Houska wrote: > Amit Kapila wrote: >=20 > > On Tue, May 5, 2026 at 6:17=E2=80=AFPM Antonin Houska = wrote: > > > > > > Antonin Houska wrote: > > > > > > I think the problem is that with database-specific snapshot, > > > SnapBuildProcessRunningXacts() returns early, w/o adjusting builder->= xmin > > > > > > /* > > > * Database specific transaction info may exist to reach CONS= ISTENT state > > > * faster, however the code below makes no use of it. Moreove= r, such > > > * record might cause problems because the following normal (= cluster-wide) > > > * record can have lower value of oldestRunningXid. In that c= ase, let's > > > * wait with the cleanup for the next regular cluster-wide re= cord. > > > */ > > > if (OidIsValid(running->dbid)) > > > return; > > > > > > and thus some transactions whose XID is below running->oldestRunningX= id may > > > continue to be incorrectly considered running. > > > > > > I originally thought that this should not happen because such transac= tions > > > will be added to the builder's array of committed transactions by > > > SnapBuildCommitTxn() anyway. However, I failed to notice that COMMIT = record of > > > a transaction listed in the xl_running_xacts WAL record is not guaran= teed to > > > follow the xl_running_xacts record in WAL. In other words, even if > > > xl_running_xacts is created before a COMMIT record of the contained > > > transaction, it may end up at higher LSN in WAL. So the cleanup I rel= ied on > > > might not take place. > > > > >=20 > > BTW, is it possible to write a test by using injection_points or via > > manual steps (by using debugger, etc) so that we can more clearly > > understand this problem and proposed fix? >=20 > So far I could observe the situation in WAL, but have no idea how it can > happen. For example, transaction 49242 gets committed here >=20 > rmgr: Transaction len (rec/tot): 46/ 46, tx: 49242, lsn: 0/18BC28C8, prev > 0/18BC2890, desc: COMMIT 2026-05-11 16:38:16.603265 CEST >=20 > and then it appears in the 'xids' list of RUNNING_XACTS: >=20 > rmgr: Standby len (rec/tot): 106/ 106, tx: 0, lsn: > 0/18BC3140, prev 0/18BC3100, desc: RUNNING_XACTS nextXid 49255 > latestCompletedXid 49241 oldestRunningXid 49242; 13 xacts: 49248 49249 49= 246 > 49243 49252 49251 49244 49245 49242 49250 49253 49254 49247; dbid:5 >=20 >=20 > I thought the situation is quite common (and therefore nothing of > SnapBuildProcessRunningXacts() should be skipped), but when trying to > reproduce the problem, I noticed that LogStandbySnapshot() shouldn't allow > that ordering issue when logical decoding is enabled: >=20 > /* > * GetRunningTransactionData() acquired ProcArrayLock, we must release i= t. > * For Hot Standby this can be done before inserting the WAL record > * because ProcArrayApplyRecoveryInfo() rechecks the commit status using > * the clog. For logical decoding, though, the lock can't be released > * early because the clog might be "in the future" from the POV of the > * historic snapshot. This would allow for situations where we're waiting > * for the end of a transaction listed in the xl_running_xacts record > * which, according to the WAL, has committed before the xl_running_xacts > * record. Fortunately this routine isn't executed frequently, and it's > * only a shared lock. > */ > if (!logical_decoding_enabled) > LWLockRelease(ProcArrayLock); >=20 > So I don't have the answer right now. I think now that "waiting for the end of a transaction listed in the xl_running_xacts record" in the comment is about transaction removal from procarray. However, the COMMIT record can still be ahead of xl_running_xacts because RecordTransactionCommit() is called before ProcArrayEndTransaction(). I'll think again if the whole problem can be reproduced with injection points. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com