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 1xY7N1-00000003y85-1jQv for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2026 19:49:03 +0000 Received: from localhost ([127.0.0.1]:53638 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xY7Mz-0000000F1Af-32T8 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2026 19:49:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:51758) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xY7Mz-0000000F1AV-1Qz5 for pgsql-hackers@lists.postgresql.org; Mon, 30 Nov 2026 19:49:01 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xY7Mw-00000001G7T-3Qct for pgsql-hackers@lists.postgresql.org; Mon, 30 Nov 2026 19:49:00 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so50015765e9.2 for ; Mon, 30 Nov 2026 11:48:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1796068137; x=1796672937; 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=O+rAgL3I3YOTlnHbaEuhtvjFUVQX7DY4gNDQyWW1lKw=; b=d0bJzk9oyj7u7Vb5gP25NNo6DCBDjqZNyAEMaWSZo5W7dDb35/SZxUYiNna10aMQdj lVYrYTJq+tu6pVrkbmvhQ+5cjLFjytobk4T+8o7j5HKfh019c/jbhteqR77zwhJATckA 0uXegY5wvcxh34hirA1Nq6da+bPcMUPoESGj/J8MEwXU4uJ7zpSr0voXmFdlIR3DMjur oTgZi10LWW0RodkDGqyjqB/684foypxZFGZaIfG8D+2O0udo0WD+2gTdVdIss63ViTmA eJToEl7pkrUQ+N7x+16PEyxoCivzKbhj061bMhfT8/BsnWh15R8WmqnMJ7ppZzVXydrn AZQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796068137; x=1796672937; 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=O+rAgL3I3YOTlnHbaEuhtvjFUVQX7DY4gNDQyWW1lKw=; b=KgbJVp6jBkPhmWYCNSpdyivrypdzWHg5Nwg65uDZUYWHB6si5DGqANDTCoSlzDf0iA rzuRooZ/Qvt2+SQa+zQpdu1DHY9BrijrlaJFa9+qGX1kF0jgM0o/jN7+QeSx2ZbDSNRS N+xsXEF16DW3DlGrhWR6hlpAt04vOFohNHkSCVp6RGUN0xKyB1ciQgv/VyX2xZx4o47v 257fm0FheqWVmiJO63xcU5GZOQXAdTRv1Wwd6mbYYhRMY/ElkjHHGvWzbyg0D64XnsdF OJ9vSCdvD80Ptavi+6MMAMbvVBlakpT9Wwjg8shlY07CiF7yiW5dnm3Qcd/H33w5T7gS lzGw== X-Forwarded-Encrypted: i=1; AL+hErG7yUj0IFVwAMY80tTVE9RW55HZKNJZ70klsgwoq5m/iBDEPYJh4v75fKtuwZnnmaBIdL8MluzsHjjGkG3i@lists.postgresql.org X-Gm-Message-State: APuU4Z/KXTUMCWqJz13CdVzzgIYYzfpuznJAxOBPpdo1H8WQabhESQeB 0USW1B+bvQ0bkQiuJ9LozT9sqLzu8Zx8qmcqOaIVvxsa6v1uJFL1ujFUyYipxKIG01U= X-Gm-Gg: AZFdTZdGfwOgR8jZK89i8RtksS16qYfLgGFBx+9hIPc4HGN+9dTp8AE7McwSyfJdmW+ c9GlpbJJ6tJT4E4Tbkj/B/MTUvcHavKeJ/1dxZjHpQaazPyx37dZYecixMj6CLe9FD1ts7wxDGL E4XoUOBjYfdg1Md2RR22rII8RVetzvOdsaD0wMGTB7tWuuA9JSk+KJTdxfRKHDXf+PG1/PU37Fr Ox5trBTJ+NR+36rK3TLFPGd241FUY14FQbCSE/BgBGQeK1RAkU33FjxeqI7wZnXhFGulb+YXolo hCevvGbEPXAD7HSRpfcKFq+JC4cse0xN20oZpg8Q5GNQU3VMNaXfhzXAvCmK90nHjQJcu12/apb nFR8AJ2y2k0r/wEi++e95amUVn0s79ow+ZDbkEui1GAvn30bryykbpflM9MO6Rh7TxLuP8/or96 VyD0+6CZV6KkZ672dde7su4XBIQ8qSEwKqvVJsytsS6uhm122ovJ/ten129RGX7DjXLDoDCppkq Vgn3CcaKvzDQlqmxR4kfBUdKAUn36LXMXq3kLAs0ma1E12OcfO+KB+7wSMLIWgEJuvhZZehpzMg Xo2+8qV+DOWrr+N8QM8jtiD7TCyFwUcWkUsCdU7m X-Received: by 2002:a05:600c:8b11:b0:4a2:a9:ed5a with SMTP id 5b1f17b1804b1-4bb88826835mr694635275e9.8.1796068137140; Mon, 30 Nov 2026 11:48:57 -0800 (PST) Received: from chrudos (109-81-170-200.rct.o2.cz. [109.81.170.200]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853c9170sm1009202135e9.14.2026.11.30.11.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:48:56 -0800 (PST) From: Antonin Houska To: Mihail Nikalayeu cc: Manu , shihao zhong , pgsql-hackers@lists.postgresql.org Subject: Re: REPACK enhancements In-reply-to: References: <309062.1794403598@chrudos> <179461938749.1794772.16290685916698475395@gmail.com> Comments: In-reply-to Mihail Nikalayeu message dated "Sun, 29 Nov 2026 17:28:00 +0100." X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 31.1.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <115921.1796068135.1@chrudos> Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 20:48:55 +0100 Message-ID: <115922.1796068135@chrudos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Mihail Nikalayeu wrote: > I haven't read the thread, so, some parts may have already been discusse= d. > = > > SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED, > > HeapTupleHeaderGetRawXmax(tuple)); Sure this is a thinko, I'll fix that in the next version. > Should it be Xmin? > = > > PopActiveSnapshot(); > > InvalidateCatalogSnapshot(); > = > > /* See above. */ > > Assert(!TransactionIdIsValid(MyProc->xmin)); > = > I received some helpful feedback from Mathias on related task (CIC > snapshot rotation) - [0]. > I applied proposed fixes at [1]. > = > Main things we may apply here: > = > 1) RotateSnapshot (preserves a valid xmin all the time) Is the concern that, after the xmin (I suppose you mean MyProc->xmin) bein= g invalid for a while, the next snapshot can have its xmin older than the VA= CUUM xmin horizon? I don't think this can happen here because REPACK (CONCURREN= TLY) gets its snapshots from the logical decoding system, and the underlying replicaiton slot should not allow such situation. > 2) SnapshotRotation (structure to track rotation frequency) I don't think exactly this is appropriate, although a new structure is probably needed for the arguments of finalize_block_range(), which handles= the snapshot switching. (There's a TODO comment about that in front of the function.) > 3) Xmin asserts done by injection points with ERROR attachment. It is > done that way because sometimes it is not possible to avoid getting a > snapshot due to some expressions/computed columns/etc. I'm not sure REPACK has such a problem: 1) the heap tuples we copy already have the expression values computed, 2) indexes are built in separate transactions and CommitTransaction() should complain about an existing act= ive snapshot anyway. > 4) Handling IsolationUsesXactSnapshot in a non-error way (just > disables rotation) Is it a problem if, after getting the ERROR, the user adjusts the isolatio= n level and runs REPACK again? I wonder if it's better to let user run REPAC= K w/o ERROR and w/o snapshot rotation. Such an user might think everything i= s o.k. until he notices that, due to the xmin horizon not making progress, VACUUM does not work as efficiently as it should (and especially that too = many tuples remain unfrozen). > 5) Add stress-tests form [2] and rotate snapshot every page (or some > other extreme value) Yes, that makes sense at least for development. (As for merging the stress tests into the tree, I think it was already discussed with Alvaro. Some wo= rk is probably needed to combine the stress tests for REPACK with those for C= IC. > Also, seems like build_new_index may use new snapshot for each index > it builds (at least until CIC-related snapshot rotation is not in > core). build_new_indexes() actually uses a separate transaction for each index. T= his is because by creating a new index the backend inevitably gets XID assigne= d, and COMMIT is probably the easiest way to get it cleared. > Regarding the auxiliary table, have you considered adding some > additional information to tuplesort (like xmin/lsn/tombstone) and > later use that during insertion to strip unneeded rows (for all rows > with the same key, take only "last" one)? While copying the table contents, a concurrent UPDATE can cause two versio= ns of the same row appear in two different ranges. If both versions have the = same value of primary/unique key, and if we want to apply the concurrent change= s after having copied all the tuples into the new heap, the problem is that = we won't be able to build an unique index. Therefore, we always need to apply the concurrent changes before starting = the scan of next range: by replaying the UPDATE we delete the old row from the earlier range, thus eliminating the duplicity. However, we cannot do this while the data is still in the tuplestore because this structure has nothi= ng like an index. [ Your question indicates that you understand this problem, but I try to summarize it here for others.] Yes, it's probably possible to modify the tuplestore / tuplesort as you suggest, but I think it'd be trickier than using the auxiliary table. Thanks for your comments! > [0]: https://www.postgresql.org/message-id/CAEze2WhwwAB_DVAWfunO%3D_1QZu= -J%2BThbpVbvdoOyycswQETFfw%40mail.gmail.com > [1]: https://www.postgresql.org/message-id/CADzfLwV%2Bng11CQPju9HxJvK_rL= AZ0_Zozno_%2B4Td26ZL1V_%3DrA%40mail.gmail.com > [2]: https://www.postgresql.org/message-id/af3oWkvS9K83UqmK@alvherre.pgs= ql -- = Antonin Houska Web: https://www.cybertec-postgresql.com