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 1vkH7V-00Cz0I-2m for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 07:34:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkH7U-006kAM-36 for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 07:34:45 +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 1vkH7U-006kAE-20 for pgsql-hackers@lists.postgresql.org; Mon, 26 Jan 2026 07:34:44 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vkH7S-002Ltg-1P for pgsql-hackers@lists.postgresql.org; Mon, 26 Jan 2026 07:34:44 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-43246af170aso2330967f8f.0 for ; Sun, 25 Jan 2026 23:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1769412882; x=1770017682; 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=YlRVDMu+qcbc/QERacRaWeQZ9jotdBtJMgg/42uXqLo=; b=nlokgJEKboUT2GtFnNkfVecjiM6g9iQlvxrZC02FEkJGn2X/DliVBM8yskCOj0ZvGB 4cc9jf7BzAyniCDGsInzS1inKkFt/PMaJsdvY5tdJss/Ko62VKNOeX+uRrjcUoD1E1i7 AKywwjIlZmC0o3V2WZu8ARb89Ud7c+C3yzyEux4LIv33irWO2DR9X85MEDQmOUk8nCC9 CvPcNGg683XoT7QslmAxoih8raiJPXmCk9gxssQw6PZIYAByPDEzwpXqh+OjzrrqyvVW S3lVQ/qGtI+UfHOSdUeHWh2uY8esr2J3EeZ8ylQGejGTqCJRrwCupwl15dtGm106/uxL wQFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769412882; x=1770017682; 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=YlRVDMu+qcbc/QERacRaWeQZ9jotdBtJMgg/42uXqLo=; b=NFHrKesBdgFQfIAtZqxA8p4PhkhGHOXtN0FhYBBtwRmju1hfcH90ryE0yfIY1jC7K5 hXYbzy9EYm/o9dq8LWtU8yrYZr+e9qT0RqKiwK1iNh9e3nVgsrKs3M2sFHcvj4Xk+ewa TSkqnBBLjjosqbNFCY+5Zx4/3DchMFkZ9EmdHz6zd6j6K9y5sf7EJ7QaOhmoMdME8ugV 8s4jWXtB/T1KH8uLLvKlblH6LAOqdCAJ/lTrhzvBdofmQH70hFm3R7mJ+BfSYN2jniZ+ jlhiCci9FNerDDLcJz0gmZsprb/Sd/8SB27a4BmYcFycbkN3IYbwN9q7a6YsyhiHyEv/ CYaw== X-Forwarded-Encrypted: i=1; AJvYcCWW+0U8EcM8krFMcdhvXul9EM/jcm06Olc/NTeRLURsDFe6eaepb9/pi0tt5iRujt/DczbvlvldHk01yIV5@lists.postgresql.org X-Gm-Message-State: AOJu0Yy3V4/xXRBCGdhuEi53rZ2rKIp0s6c9h1P7ZQ+s0R1I31wRztYT baqB6BcMo/63TUujR/gyPlFQgGxpP5hXHYh8A4Sb/4BqiaBpr3epfD+QI7Z10LiF+3QeUYFE6uv nYMhf X-Gm-Gg: AZuq6aKsGZmp92BJmFRxIG9/btMx2rKEXcWga8LxCOuf4vhV2zrgu3u5etuqb2zWT8f aEnmEgPvwQkGZEWNqCOuvAxde3hGKU5a3nSPRXZ68o5qOpP6p/hP1iYud2Vvu0wh02C2drM8YkE xkKN8Th/7zEszv6nxmmFQeticE07FNtct0oN/hQBw2x1EBc0LlajaegKaE252dvcse7MYKOKRC7 oSohsNSf4PG9zqWxGp29ugsYCQWQZQwzQxNKsrP7i8+essAA0SyXmcsB022SqnopMzFwn2ZVdHi jKIFXIsoBRf37eZNUTEDxglWYFVoBb/jAGqYX9BdsTVfMlZFDpfxbI+9zzRqG2S4pt0HV1OKvUV eAS8y9U++eSExggigbf3f4oyoxAlU7i7kzXRk7UvnJITOtM0Xc9E4qXYQNl1j3GPp6nKRYBbzod Y+yRmJ6VdiyPtaWVaCkCy6tAC5 X-Received: by 2002:a5d:5d12:0:b0:435:9144:13fe with SMTP id ffacd0b85a97d-435c9d22d9bmr6451955f8f.26.1769412881551; Sun, 25 Jan 2026 23:34:41 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1b6e2besm27971639f8f.0.2026.01.25.23.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 23:34:41 -0800 (PST) From: Antonin Houska To: Mihail Nikalayeu cc: Alvaro Herrera , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: References: <202512151349.vlq3mpfniyk3@alvherre.pgsql> <11247.1767609087@localhost> <11558.1767609632@localhost> <141054.1767891540@localhost> <137668.1768235610@localhost> <74802.1769071060@localhost> Comments: In-reply-to Mihail Nikalayeu message dated "Sun, 25 Jan 2026 17:31:00 +0100." 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: <3900.1769412880.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Mon, 26 Jan 2026 08:34:40 +0100 Message-ID: <3901.1769412880@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Mihail Nikalayeu wrote: > PART 1: > = > I started rebasing the MVCC-safe version on top of the multi-snapshot ve= rsion and realized it becomes complex. = > But, what's really bad about MVCC-unsafety is the ability to access *inc= orrect* data and break some logic (or even constraints). > = > If we may *prevent* such data access with some kind of error (which is g= oing to be very infrequent) - I don't see any sense to achieve true > MVCC-safety. > = > I remembered a way it works with indcheckxmin for indexes. And made some= thing similar for pg_class: it records the rewriting transaction > XID and causes the executor to raise an error if a transaction with an o= lder snapshot attempts to access the rewritten relation. > = > For the normal case - check is never executed, no performance regression= here. Also, the flag is automatically cleared by VACUUM once the > transaction ID is frozen. > = > It also "fixes" ALTER TABLE, not only REPACK concurrently. > = > Attached patch contains more details (some in the commit message). A few days ago, when thinking about it, I realized that my implementation = of MVCC safety is not correct, as it does not preserve the whole HOT chains a= s CLUSTER / VACUUM FULL does. To resolve that, we should not allow access to= the new table until the parts of HOT chains not copied by REPACK are DEAD. Better solution might be to improve rewriteheap.c (which does keep the HOT chains) so it 1) works w/o AccessExclusiveLock on the table, 2) does not c= opy tuples which will eventually be retrieved by the logical decoding output plugin, 3) allows snapshot switching/resetting in 2). I think these requirements are rather hard to implement. I've noticed recently that the MVCC safety patch you posted is not exactly what I wrote, but maybe the copying part is identical. So it's possible th= at the problem you saw is related to what I try to describe here. Let's see in the future if the demand for the MVCC safety will ever justif= y the effort to implement it. > PART 2: > = > I have continued working with stress tests. This time I added your WIP p= atch to fix the LR\CLOG race. > = > I made the following configs: > 1) just REPACK CONCURRENTLY - ok > 2) + relcheckxmin (see PART1) - ok > 3) + worker - ok > 4) + multiple snapshots - broken in multiple ways. > = > You may see example of run here - https://cirrus-ci.com/build/6359048020= 295680 > = > Some examples: > = > 1) 'pgbench: error: client 11 script 0 aborted in command 20 query 0: E= RROR: could not read blocks 0..0 in file "base/5/16414": read only 0 > of 8192 bytes > 2) at /home/postgres/postgres/contrib/amcheck/t/008_repack_concurrently.= pl line 51. > [15:36:37.204] # 'pgbench: error: client 5 script 0 ab= orted in command 28 query 0: ERROR: division by zero > 3) 'pgbench: error: client 12 script 0 aborted in command 6 query 0: = ERROR: cache lookup failed for relation 17400 Thanks, I'll check these. -- = Antonin Houska Web: https://www.cybertec-postgresql.com