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.94.2) (envelope-from ) id 1ufmsM-00Bp9d-G9 for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Jul 2025 21:56:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ufmsJ-00CRS7-Gi for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Jul 2025 21:56:15 +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.94.2) (envelope-from ) id 1ufmsI-00CRRy-7K for pgsql-hackers@lists.postgresql.org; Sat, 26 Jul 2025 21:56:15 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ufmsE-000wPm-0Y for pgsql-hackers@lists.postgresql.org; Sat, 26 Jul 2025 21:56:13 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id D5BD7EC0265; Sat, 26 Jul 2025 17:56:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Sat, 26 Jul 2025 17:56:08 -0400 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:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1753566968; x=1753653368; bh=KbFPNFhJYAWD+ll3eQzJBGSqkbCD ABI30VcJt3dluWc=; b=KWT2kwUNSyqDXZTQb3qvgcawN/10ZWot9XyOFavc2z9m sayWA3AKYR73XqKUeibTdHlnk3omkk34Nl2UGz9T7bXllqL8g+QVM8Gl/gcYtWYD 815YoBmrgSlF5RRU1dngpDOEQuCTJMG1MEFNwocvqZfEem7I9pWa/EnaPXiywvIl g6pHt0h8ZQbJgFeK9pyreqQF15PeVaBZZr2zKXJbxfKLcrE1bg47qDrJwOG9BQor SHjPfoul/JehCTcq5SPGqXs0U1us9i5Uy7r5uypuv5kpbQI8x11KKqfvIetnu1yz 5PhWqGtSh/PMZHuuPDgRPkUI/+At/4c2hWlzjb1kZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdekjeehgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfggtggugfesmhekreertddtjeenucfhrhhomheptehlvhgrrhhoucfj vghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqnecugg ftrfgrthhtvghrnhephfduleegleffgfelgeffveeihedvteetjeelteettdehledthfeh veehheevledunecuffhomhgrihhnpehpohhsthhgrhdrvghspdgvnhhtvghrphhrihhsvg gusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprhgtphhtth hopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrhhestgihsggvrhhtvggt rdgrthdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsth hgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 26 Jul 2025 17:56:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1753566964; bh=mJjoyMby9Re4LBTBr5ETYWkq+IloBSXGqSzWJaRLn3U=; h=Date:From:To:Cc:Subject:From; b=HAToqeQBd60so+riq5PafPSmGuB0bPpTEjdewlJ6JMxYoeAFz5exeNTXomlUrzhHk mUvFdyOFdiE3CRaP8PNTwG2GLVrF698fDHRB2iLvHsijM/8LLLBCMoQbm2KJtDCVx5 gqbm9F0erhtGEpEpuo+Sb3w+L5+QHdpfT2LbI2t+zLk1oOSTifAoIhdg+ln41dJd+V x7yKw1wkZZnoT+K0MBwhAkkEZ73MZzcL1PhHoTkb+nOoD/Lv4vEpBit9Q4IQKnQNz+ +vr3x4tsaPPHDrgYRgVAXK2AreNbRf+YNGUbfHW2msn12I78DhMfbmfhW22NoebB+N vePEA/GI9ReWw== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id D88098D; Sat, 26 Jul 2025 23:56:04 +0200 (CEST) Date: Sat, 26 Jul 2025 23:56:04 +0200 From: Alvaro Herrera To: Pg Hackers Cc: Antonin Houska Subject: Adding REPACK [concurrently] Message-ID: <202507262156.sb455angijk6@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="v55yi6h5s6effx24" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --v55yi6h5s6effx24 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hello, Here's a patch to add REPACK and eventually the CONCURRENTLY flag to it. This is coming from [1]. The ultimate goal is to have an in-core tool to allow concurrent table rewrite to get rid of bloat; right now, VACUUM FULL does that, but it's not concurrent. Users have resorted to using the pg_repack third-party tool, which is ancient and uses a weird internal implementation, as well as pg_squeeze, which uses logical decoding to capture changes that occur during the table rewrite. The patch submitted here, largely by Antonin Houska with some changes by me, is based on the the pg_squeeze code which he authored, and first introduces a new command called REPACK to absorb both VACUUM FULL and CLUSTER, followed by addition of a CONCURRENTLY flag to allow some forms of REPACK to operate online using logical decoding. Essentially, this first patch just reshuffles the CLUSTER code to create the REPACK command. I made a few changes from Antonin's original at [2]. First, I modified the grammar to support "REPACK [tab] USING INDEX" without specifying the index name. With this change, all possibilities of the old commands are covered, which gives us the chance to flag them as obsolete. (This is good, because having VACUUM FULL do something completely different from regular VACUUM confuses users all the time; and on the other hand, having a command called CLUSTER which is at odds with what most people think of as a "database cluster" is also confusing.) Here's a list of existing commands, and how to write them in the current patch's proposal for REPACK: -- re-clusters all tables that have a clustered index set CLUSTER -> REPACK USING INDEX -- clusters the given table using the given index CLUSTER tab USING idx -> REPACK tab USING INDEX idx -- clusters this table using a clustered index; error if no index clustered CLUSTER tab -> REPACK tab USING INDEX -- vacuum-full all tables VACUUM FULL -> REPACK -- vacuum-full the specified table VACUUM FULL tab -> REPACK tab My other change to Antonin's patch is that I made REPACK USING INDEX set the 'indisclustered' flag to the index being used, so REPACK behaves identically to CLUSTER. We can discuss whether we really want this. For instance we could add an option so that by default REPACK omits persisting the clustered index, and instead it only does that when you give it some special option, say something like "REPACK (persist_clustered_index=true) tab USING INDEX idx" Overall I'm not sure this is terribly interesting, since clustered indexes are not very useful for most users anyway. I made a few other minor changes not worthy of individual mention, and there are a few others pending, such as updates to the pg_stat_progress_repack view infrastructure, as well as phasing out pg_stat_progress_cluster (maybe the latter would offer a subset of the former; not yet sure about this.) Also, I'd like to work on adding a `repackdb` command for completeness. On repackdb: I think is going to be very similar to vacuumdb, mostly in that it is going to need to be able to run tasks in parallel; but there are things it doesn't have to deal with, such as analyze-in-stages, which I think is a large burden. I estimate about 1k LOC there, extremely similar to vacuumdb. Maybe it makes sense to share the source code and make the new executable a symlink instead, with some additional code to support the two different modes. Again, I'm not sure about this -- I like the idea, but I'd have to see the implementation. I'll be rebasing the rest of Antonin's patch series afterwards, including the logical decoding changes necessary for CONCURRENTLY. In the meantime, if people want to review those, which would be very valuable, they can go back to branch master from around the time he submitted it and apply the old patches there. [1] https://postgr.es/m/76278.1724760050@antos [2] https://postgr.es/m/152010.1751307725@localhost -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ --v55yi6h5s6effx24 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v1-0001-Add-REPACK-command.patch"