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 1vT3Hw-00Bt0w-1Z for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 19:22:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vT3Hu-006HaL-2f for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 19:22:19 +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 1vT3Hu-006HaB-1Y for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 19:22:18 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vT3Hr-0046A9-2p for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 19:22:18 +0000 Received: from phl-compute-07.internal (phl-compute-07.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 413EC1400146; Tue, 9 Dec 2025 14:22:13 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Tue, 09 Dec 2025 14:22:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1765308133; x=1765394533; bh=I 6bhAxqor7sVHa81dbXXJaPrg1y4ezAo9YvwHdWTleI=; b=nT2yVJ68E9XOoxsVR Wyka2jyW/BfccLqOigCPejd51DxqLPjUchVWWCTI/iCBUVrpcJfRhZB9T5Tk7C5v kAwsK+NzFiD3bsrYEPjQ645hx3+tk4ifD9AQ4VHymFbXRAcmwhjd2NYPAlxo5TVW dh+vvJgfBnsltyVurlIPEHC9ZZSsFCtlUgW/h1lH6vGrSqMr8379SQSzl9VUeZlf 9k1uX5tsTxbvLT7GsqvvK54Qipp1XWx1IFeac8qeVHf4cSvZu4bJJ4IiZBfHa2UJ Je9sktDXLBjxY+ph3tp3Ib38Hhtgvi+fJu8ElPJ+lAzXvvfQ2TSy9KaGy2M3iBbb qV6rA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvtdeflecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghrohcu jfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqeenuc ggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeffgfdu fffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghr rhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtghpthhtohepgedpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtoheprghhsegthigsvghrthgvtgdrrghtpdhrtghpthht ohepmhhihhgrihhlnhhikhgrlhgrhigvuhesghhmrghilhdrtghomhdprhgtphhtthhope hpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdp rhgtphhtthhopehrohgsseigiihilhhlrgdrnhgvth X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Dec 2025 14:22:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1765308129; bh=axbUDtG1i5WsfRdkkoblztx+Z0i9PCgZeWcvHivLz4c=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=QcaPoo3YxclAza7SWaQEjyC60T2W3Oqnz5xCSOj9scEnT/TMbMlxS+A3JQOcv7TAd AbUsGOm/MkDHWaFSAleangXGoEFz3K+hSTlY4E/3EaPM/9fMMm6bzgAH51kXiA+xhq kQunP25Ql+XN4O5oNhLjWoXpzRgKQhEZ6echGkZNsIaF7W4SedrLkDPDRmukWxoNsy XiZdAtVJiT73owV4dBUTmY8MnJEVp7YA0GA5jhxKytaR9MhZyu1daGhDF/QHGD8CF9 KJmyP1Ffv2ratYuNf+EV+ZdvicjxtBzVGghhfeCVF1IfyJ6Wef80Fd2J9jvlPnMf0c jMiwCLAVx2a/w== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id E375A7B; Tue, 09 Dec 2025 20:22:09 +0100 (CET) Date: Tue, 9 Dec 2025 20:22:09 +0100 From: Alvaro Herrera To: Antonin Houska Cc: Mihail Nikalayeu , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] Message-ID: <202512091915.ws6fk7csn76r@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <171530.1765306357@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, many thanks for the new version. Here's a very quick proposal for a new top-of-file comment on cluster.c, * cluster.c * Implementation of REPACK [CONCURRENTLY], also known as CLUSTER and * VACUUM FULL. * * There are two somewhat different ways to rewrite a table. In non- * concurrent mode, it's easy: take AccessExclusiveLock, create a new * transient relation, copy the tuples over to the relfilenode of the * new relation, swap the relfilenodes, then drop the old relation. * * In concurrent mode, we lock the table with only ShareUpdateExclusiveLock, * then do an initial copy as above. However, while the tuples are being * copied, concurrent transactions could modify the table, and to cope * with those changes, we rely on logical decoding to obtain them from WAL. * A bgworker consumes WAL while the initial copy is ongoing (to prevent * excessive WAL from being reserved), and accumulates the changes in * a tuplestore. Once the initial copy is complete, we read the changes * from the tuplestore and re-apply them on the new heap. Then we * upgrade our ShareUpdateExclusiveLock to AccessExclusiveLock and swap * the relfilenodes. This way, the time we hold a strong lock on the * table is much reduced, and the bloat is greatly reduced. I haven't read build_relation_finish_concurrent() yet to understand how exactly do we do the lock upgrade, which I think is an important point we should address in this comment. Also not addressed is how exactly we handle indexes. Feel free to correct this, reword it or include any additional details that you think are important. (At this point we could just as well rename the file to repack.c, since very little of the original remains. But let's discuss that later.) Thanks, -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Doing what he did amounts to sticking his fingers under the hood of the implementation; if he gets his fingers burnt, it's his problem." (Tom Lane)