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 1w5hNf-003X91-1C for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2026 09:51:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5hNc-001wC0-2T for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2026 09:51:57 +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 1w5hNc-001wBs-11 for pgsql-hackers@lists.postgresql.org; Thu, 26 Mar 2026 09:51:56 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5hNa-000000017TA-3HT4 for pgsql-hackers@lists.postgresql.org; Thu, 26 Mar 2026 09:51:55 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-486b9675d36so6996505e9.0 for ; Thu, 26 Mar 2026 02:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1774518712; x=1775123512; 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=4YTQgqi9U1RYH/RHo/GJaI8aHPi+aDlh6uNMNoq8TrM=; b=sSn2Uj3dO9xOJ/QBCJoa7vIcm/urp88UYbMPAvhs8K9hVrT5dpB4yohEy4CzjGg/R0 7e16q/becUuQRUKyRRNNYLP0u2HyJkLNs1qBqRWuDSV50/TbHRbx3ReUBGwQILEfw9yk RW/8KSIi06kKmjnR4NBoCcRmB1rftwaVDI+zrozdWZJzpc114X6tMd/ShYaQnEc52vHU ENfPX56BglvCOdKG8VL+FsG8XLHEekbHw2YX+kTda59fn2PbdUbtKjvIXOrdkxeaf2i9 RM4Cv6tgTr0uaZbDgD14pHuJUXuD9SW2euTOwhM3jOe078+CaM+/gQvEaCmvVGvTjWBy /9Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774518712; x=1775123512; 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=4YTQgqi9U1RYH/RHo/GJaI8aHPi+aDlh6uNMNoq8TrM=; b=OVoZoL/Q4+ErIcdY3GwFWSRpEeexB/8vnNNznzAGzdRcvgElJcWrWMgq01zoQVmv62 bp/Qx3OwiT8imXNPwv1UpTDje6BFKjf4oyNHFrAyU6e2QGD/fuf8oWhPkcG+VS7VL2Dd xGUgcrs7IgjRewiHOdZi8vmTXCdtzDDP3gAfcngkWhXZKsmm+01Z4vB91bT7nU4/2cKZ EgjOVduIQSzpGWa1j+//pJkdU9Nwwh/0Sr2zDjuWBCkT9xBc8TSUqwMLgkZWE7TMCHtv lT0xjynERPlBwInBMLXnJBf1/hOZwHGkxdbN0XYcWxf4f+q2H/LWjgmO8cPb05nG8g8c yxcA== X-Forwarded-Encrypted: i=1; AJvYcCVoJipfSkpca7f9yKMxJym5owzj6CKVpl0dhtPsUh5bsIC/aWFq6RMwuhsj2P8t/wyhdjLEuAuhJqAujwpo@lists.postgresql.org X-Gm-Message-State: AOJu0YyIdLcXB5xE3beWCdvQu8PEDMHTm0gEVEUeeqOcL5y51/KKh0Tg EOgKMb/fh3NNAGfnPYMFK0PQSj258aF2zuJCGEbdHeFe/YKU154gwH83x9sdK++Kb9k= X-Gm-Gg: ATEYQzxpzZ2AeZ4dmgV7cpITdLFMJkxubD/aMEzGta6DLfgvPN04K0yb+wwYvkAgHKa aSFcrd3G3OIcSJBhjTepjhoGNpEME7wvyUZYLgHwAgcNiFQWWrZPFJaUEoo6rrOApOIhv9SYmxR +4vSEj4maoktUQ3Uu3WTtxDtFhTrl7ES5niAnW9b1EXd106mLFq2rp2grAoUENC1I7PQaaRgrDq jH9bQnkxMLG2RTey/lJMEuCciJXNaXHfxDPJpLy3gVswLUtI1bu+Rf4tU1CUb4JycimqpYc3AWf vJrxsrHi4ICrjoVNmDD2UpKOsNkCJ4M05LWbYovmt6vPLNY3TExsjsNjAJYHb0zrnfNWH5e4blV /UHftMNdsGhc4H6tlK5r5tHoQQsrc1p88rUthe3AAFxSJ8QD6vH4OpT2EbzoZ/kIZ6gC8EysvDQ jD88kHWp+XU7ND5vWViG4p32lsb6daBsE/Rql0 X-Received: by 2002:a05:600c:1d0e:b0:485:3ec6:e634 with SMTP id 5b1f17b1804b1-48715febda2mr99943345e9.15.1774518711796; Thu, 26 Mar 2026 02:51:51 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4871fba8fe6sm16756965e9.1.2026.03.26.02.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 02:51:51 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Srinath Reddy Sadipiralla , Mihail Nikalayeu , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: <202603252005.quy5h4oipoxd@alvherre.pgsql> References: <202603252005.quy5h4oipoxd@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Wed, 25 Mar 2026 21:12:48 +0100." 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: Thu, 26 Mar 2026 10:51:50 +0100 Message-ID: <23138.1774518710@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera wrote: > On 2026-Mar-25, Srinath Reddy Sadipiralla wrote: >=20 > > Then as suggested by Alvaro off-list I checked the lock upgrade > > behavior during the table swap phase. I observed that if another > > transaction holds a conflicting lock on the table when the swap is > > attempted, it can lead to =E2=80=9Ctransient table=E2=80=9D data loss d= uring a manual > > or timeout abort. when a REPACK (concurrent) waits for a conflicting > > lock to be released and eventually hits a lock_timeout (or is > > cancelled via ctrl+c), the transaction aborts. During this abort, the > > cleanup process triggers smgrDoPendingDeletes. This results in the > > removal of all transient table relfiles and decoder worker files > > created during the process. This effectively wipes out the work done > > by the transient table creation before the swap could successfully > > complete, this happens because during transient table creation we add > > the table to the PendingRelDelete list. >=20 > I think we certainly need to make the files be deleted in some > reasonable fashion if repack fails partway through. I think that Srinath tries to explain the cleanup in detail, but in fact that's a normal processing of transaction abort. Not sure we need to do anything special. > As for lock upgrade, I wonder if the best way to handle this isn't to > hack the deadlock detector so that it causes any *other* process to die, > if they detect that they would block on REPACK. Arguably there's > nothing that you can do to a table while its undergoing REPACK > CONCURRENTLY; any alterations would have to wait until the repacking is > compelted. We can implement that idea simply enough, as shown in this > crude prototype. (I omitted the last three patches in the series, and > squashed my proposed changes into 0003, as announced in my previous > posting.) I haven't thought of it because I'm not familiar with the deadlock detector, but what you do seems consistent with the way blocking by autovacuum is handled. The only problem I noticed is that PROC_IN_CONCURRENT_REPACK is not cleared= at the end of transaction. Perhaps it should be added to PROC_VACUUM_STATE_MASK (name of which is already misleading due to the presence of PROC_IN_SAFE_IC, but that's another problem). > The isolation test file is also a bit crude; I just copied repack.spec > to a new file and removed the uninteresting bits. Maybe just add a new permutation to repack.spec? I don't remembery if I created repack_toast.spec as a separate file just for better readability or= if there was some other issue, but the deadlock test might fit into repack.spe= c. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com