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 1wB9Ye-000my5-2Z for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 10:57:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wB9Yd-00BOFK-0d for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 10:57:52 +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 1wB9Yc-00BOFB-2n for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 10:57:51 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wB9Yb-00000000LBM-1px7 for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 10:57:51 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-43d04fc3bf2so1120293f8f.3 for ; Fri, 10 Apr 2026 03:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1775818668; x=1776423468; darn=lists.postgresql.org; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=eT4tDDBdaGCHxQx1pWA98FqSMV9jG5KTGVs2nbRZ/N8=; b=pGVFuOTVB0vYK5mKCh36kra12rt8jZIbJT7QjUri5cbQ+L4NGc1UkW3cbXTRC3keg2 EfcDx/Pc3YBJwzS2CjIyFBCqMcKcwkZJ8ZZOUFdiDvDFfYj/sKlIROFnTGBwTS/o8n1k zHpdrIONQlmt1cWrKYINMDiaOGu12ngtMeZExgyfSlIO5YPf3RvtY6QUu30vzUo0GQWg +vFjL6JVnpvhhLwRFWeUcQZDlRy7f3fTCaCSvfEUi9hvuJ9OGh/vhMUk2vPiyUFIljx0 7CteNlOvjxlDYGqoU8k4YxZAMU/BPiqxoF3paDSJNfx7JMaZP9REO16yIzAX/7FBYWs2 EYHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775818668; x=1776423468; h=message-id:date: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=eT4tDDBdaGCHxQx1pWA98FqSMV9jG5KTGVs2nbRZ/N8=; b=G8Kkh4amdP0PEhwZuF6ozBFhl70MczCBKkf9OkSmupomyaN1Xfkg48RZ9aHAfP4XfN PH8hpPo7YR2dyOu3DGlOeRfHVcX3Lspz5cbcpCJMuMQO3vsdvrYskIfBXPPQdI61kHGn lRrG+py8/NeQjuhfi7NHUKUePT/iiTPu3+8qQ29gJSKxdfNxm7aKteRK98lPcL6om3ZK Uoikor5LD6kzSa0O+Wy8ulmk/idyFKYewwGW2We93NR1x/9XSymO1F3nIxx6Qj6h2BaS 4unrqzH/1BmICcmlHIaYZ9Y9TXFk8GqD0w1/cjMHNx7EYS3VAL6kUTWoLqn3pqa8ANqm zo3w== X-Forwarded-Encrypted: i=1; AJvYcCVoqQIEybVhDSmWMzbKskwf+n8PjpzoazyYm8rVzmv7baax2NqrXwR0hxVBSVGJQvbWo1vtL+OT8mEYO4Gl@lists.postgresql.org X-Gm-Message-State: AOJu0Yzkcjx1Q2pfI5toNUam89hhK6rDvbOGyu1D3GjXfvmjUsXYcJFQ RcDnsmp0AINjhuQhK3JEvOy6AmQbbPoLQI4/6AxcpD8YFprPrnBiihNjaNjzdFi3Lqs= X-Gm-Gg: AeBDietB0MUuf5RcP/X0xLxsB6vi9qRweJ+EPPSG904e5HEOVmaYB7NvxLOOJP7mX7x rXHC1efYeFaQUaMgmjmXVfgmyP9aFENRZL3LAsO6cax9QtlpfI33cj6XUg8V7qbLvnvGaXHwFX/ J51cSqTl9DBR9+ix+hvP0g9Hu7uGu49o/Lp1UL0lqYJeeoGWTSJ1bmowAiSdgWaebyRvllXq1NC LEdckjOUI5gne81wPWe6y7gXl4a9WSb3spAGFg2B4fBCtfV6AGGVJ5368q5GlO4lG7DDiU7EYr/ F0n2aAoRfam2lekSmdOf5dsvKmGbLk3Fo/3S2S50x5JgfFu+p1XZkretyx2gjV6mwDSRUxToaWa g5QfbP4Viv2zcS6JnwOevUdmKIHxpqfbdk6jDpLG4dpXTDuLMFZWMeDB+GgbQz+aFmlPSvxbmzb 7KVFv0ZVZgxl1VVixKJzZVpGGhjttcDv/YrJtw76nsOgIv3zg= X-Received: by 2002:a05:6000:40df:b0:43b:43ae:8c2e with SMTP id ffacd0b85a97d-43d642cb435mr4255601f8f.51.1775818668316; Fri, 10 Apr 2026 03:57:48 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e468c5sm6925695f8f.20.2026.04.10.03.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 03:57:47 -0700 (PDT) From: Antonin Houska To: Alexander Lakhin cc: Alvaro Herrera , Amit Kapila , "Hayato Kuroda (Fujitsu)" , Srinath Reddy Sadipiralla , Mihail Nikalayeu , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: References: <202604072027.gazfa2zt2l2j@alvherre.pgsql> Comments: In-reply-to Alexander Lakhin message dated "Fri, 10 Apr 2026 10:00:00 +0300." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Fri, 10 Apr 2026 12:57:47 +0200 Message-ID: <121156.1775818667@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Alexander Lakhin wrote: > Could you please look at an assertion failure produced by the following > script, starting from 0d3dba38c:? > createdb db1 > createdb db2 > > echo " > CREATE TABLE t0 (a text); > BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; > INSERT INTO t0 VALUES ('a'); > SELECT pg_sleep(1); > " | psql db1 & > > echo " > CREATE TABLE t1 (id int PRIMARY KEY); > CREATE TABLE t2 (id int PRIMARY KEY, a TEXT, FOREIGN KEY (id) REFERENCES t1); > SET min_parallel_table_scan_size = 1; > REPACK (CONCURRENTLY) t2; > " | psql db2 > wait > > It triggers for me: > TRAP: failed Assert("TransactionIdPrecedesOrEquals(TransactionXmin, RecentXmin)"), File: "procarray.c", Line: 2071, PID: 3529520 Attached is a fix that works for me. Nevertheless, REPACK (CONCURRENTLY) in your test goes ahead only due to commit 0d3dba38c7, which will probably be reverted [1]. Then REPACK will wait for the transaction in the other database (db1) to complete before it can actually start. Thanks for the report! [1] https://www.postgresql.org/message-id/cdgw4sbbfcgk6du3iv54r2dgiy4tfywoklbotlmj4irxavdcr3@glxfw5jj277q -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Do-not-push-the-active-snapshot-for-copy_table_data-.patch From 3fd0a70566f42d695b92c1cb2d26d3dbd5918a58 Mon Sep 17 00:00:00 2001 From: Antonin Houska Date: Fri, 10 Apr 2026 12:17:36 +0200 Subject: [PATCH] Do not push the active snapshot for copy_table_data before it's needed. make_new_heap() can launch parallel workers when building index on TOAST relation. If the snapshot for copy_table_data() is already the active snapshot, the workers can incorrectly consider it their transaction snapshot. --- src/backend/commands/repack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index 58e3867246f..08fd132a4e3 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -1013,8 +1013,6 @@ rebuild_relation(Relation OldHeap, Relation index, bool verbose, * Wait until the worker has the initial snapshot and retrieve it. */ snapshot = get_initial_snapshot(decoding_worker); - - PushActiveSnapshot(snapshot); } /* for CLUSTER or REPACK USING INDEX, mark the index as the one to use */ @@ -1038,6 +1036,8 @@ rebuild_relation(Relation OldHeap, Relation index, bool verbose, NewHeap = table_open(OIDNewHeap, NoLock); /* Copy the heap data into the new table in the desired order */ + if (snapshot) + PushActiveSnapshot(snapshot); copy_table_data(NewHeap, OldHeap, index, snapshot, verbose, &swap_toast_by_content, &frozenXid, &cutoffMulti); -- 2.47.3 --=-=-=--