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 1vRBUr-008mVz-1f for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 15:43:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRBUn-003E84-2p for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 15:43:54 +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 1vRBUn-003E7v-18 for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 15:43:53 +0000 Received: from fout-b7-smtp.messagingengine.com ([202.12.124.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRBUk-0037rz-2P for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 15:43:53 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id 371781D000B6; Thu, 4 Dec 2025 10:43:48 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 04 Dec 2025 10:43:48 -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=1764863028; x=1764949428; bh=U CNpEG+TN/ZN2I9ZXe2RhsjRQXRUd56RgVb8BAHsLfk=; b=uZySY63sXccwCzKhl 4vMuu5MPrfeG1QdSbWutX+MI9Bo35KIX2nYa8nGnlh5MnneGOsI8BtIlWrtXcJF9 IekZk92x2r6UuZtpwtdk4ncz1YRdClOHpym4uvtN6fUdK/3Jrg96qNYnD/DRqCAA V6w7JyDH5+gBYwLwKg30z0CrE5Bl91K+LLSlqJ8KsoWKR4hClU7kLocLyNgGV65C O4lOTAfn7Pchjlm2kr9jED7rW3VQ8FjbeLKyAGIn3c44fDR9sT5HS9MccxqV8W1w VmwUE7dV+Q5n6MLMCn+pshmuz054FFIhKr5wKRCWvQ37kPbwYwM1BiumZyPXEMoA hnprg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdehleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhhoucfj vghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqnecugg ftrfgrthhtvghrnhepvdehueffhefgueekueefheehgffhuefgfedukeejveduffegffek geffffevgeehnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprhgtphhtthhopeeipdhmohguvgepsh hmthhpohhuthdprhgtphhtthhopegurghvihgurdhklhhikhgrsegrthhlrghsrdgtiidp rhgtphhtthhopegrhhestgihsggvrhhtvggtrdgrthdprhgtphhtthhopehjihgrnhdruh hnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhihhgrihhl nhhikhgrlhgrhigvuhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrg gtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehr ohgsseigiihilhhlrgdrnhgvth X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 4 Dec 2025 10:43:46 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1764863024; bh=b7X57GrwlaiwkeABPhU4X89gLjHu8L5EBM9cjWyh7rc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=SnTZcZ7arwBNL9MnCL4/Sy+CkIKkUW8McnCtfYbF0RIygWPgAUCq9BM7zuJ8sJhm/ glFnCQfXthvFI7yuBFvLJCufjlKUs5yFsl9EFfLwoQpj+2w3r86UUQIYFJG+XufGfr mYTLUQHIWeDxQQjYd6tf49WfTSyaNCIoE4qLHhqAIryj9G38zUjtwcFliymfJtwXjJ rv9iodguAu+cT98i72JINYWRfItUh7NApN5Az46U2O6F0Xr5Xn7DLC92IAAGXZHWEQ ldm/X998SppJhChOaK4cNGuqFpn27oynJg5OAWme8PuQsCA1Ia02NrSpxxSBkBQntx 3QqhYaW0gF6yg== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id B7B667B; Thu, 04 Dec 2025 16:43:44 +0100 (CET) Date: Thu, 4 Dec 2025 16:43:44 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: David Klika Cc: ah@cybertec.at, jian.universality@gmail.com, pgsql-hackers@lists.postgresql.org, mihailnikalayeu@gmail.com, rob@xzilla.net Subject: Re: Adding REPACK [concurrently] Message-ID: <202512041531.4yz4szwnfsqk@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <84a6d065-1dc3-4b37-af7b-75904d967ab4@atlas.cz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello David, Thanks for your interest in this. On 2025-Dec-04, David Klika wrote: > Let's consider a large table where 80% blocks are fine (filled enough by > live tuples). The table could be scanned from the beginning (left side) to > identify "not enough filled" blocks and also from the end (right side) to > process live tuples by moving them to the blocks identified by the left side > scan. The work is over when both scan reaches the same position. If you only have a small number of pages that have this problem, then you don't actually need to do anything -- the pages will be marked free by regular vacuuming, and future inserts or updates can make use of those pages. It's not a problem to have a small number of pages in empty state for some time. So if you're trying to do this, the number of problematic pages must be large. Now, the issue with what you propose is that you need to make either the old tuples or the new tuples visible to concurrent transactions. If at any point they are both visible, or none of them is visible, then you have potentially corrupted the results that would be obtained by a query that's scanning the table and halfway through. The other point is that you need to keep indexes updated. That is, you need to make the indexes point to both the old and new, until you remove the old tuples from the table, then remove those index pointers. This process bloats the indexes, which is not insignificant, considering that the number of tuples to process is large. If there are several indexes, this makes your process take even longer. You can fix the concurrency problem by holding a lock on the table that ensures nobody is reading the table until you've finished. But we don't want to have to hold such a lock for long! And we already established that the number of pages to check is large, which means you're going to work for a long time. So, I'm not really sure that it's practical to implement what you suggest. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/