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 1vKNtg-00AASG-2K for pgsql-admin@arkaria.postgresql.org; Sat, 15 Nov 2025 21:33:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vKNtd-00AAQe-15 for pgsql-admin@arkaria.postgresql.org; Sat, 15 Nov 2025 21:33:25 +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 1vKNtc-00AAQW-2h for pgsql-admin@lists.postgresql.org; Sat, 15 Nov 2025 21:33:24 +0000 Received: from mail-107163.simplelogin.co ([79.135.107.163]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vKNta-007wH8-1R for pgsql-admin@lists.postgresql.org; Sat, 15 Nov 2025 21:33:24 +0000 ARC-Seal: i=1; a=rsa-sha256; d=simplelogin.co; s=arc-20230626; t=1763242400; cv=none; b=e2vsNb4J71W+U4zAqjeNHxQsHJWP2o/IO7hF0veWPS1XZ6EA7sJ+77dqyhALtyPXgKs5KLybTFYbQTZRAMH0Oh/DmnrvLS9VaTopTOAin6fV2lvJKQv+Qm/g1Ea8SUlw4Q9mjSd5eorlBVQv9l89E/Lp2dZyzq6+nhBEoeBLPbg9VY7edUFoR/FFY01VRAsHd/5qu5/+/rJGHvQLG7Fe2r5kU9LX3NzItfjtBtj46swwWDkii87H5YLWadDOAo3yXjz0yZzVbqLB77OwMgliAOpJsSDH9L4c1DcwNLENqfESSuWVtHM5at7oqzDF99K6YmGjMCikjeHRaxMTFT65PQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=simplelogin.co; s=arc-20230626; t=1763242400; c=relaxed/simple; bh=AO7hkZFupUmzOJxwBwPvGk8NPdP4mSojP70XO142qcQ=; h=Date:Subject:In-Reply-To:From:To:References; b=xflVhpdS7bHvJM3nZn2B7t7Glq4MFQeNaUAOWHgE6IiVNp9oTMHND6hVe3IK+xPd2RnqHRBIEzuM6btfbKc/A7NNZvDQSmzxKYFMi6ikqz0S8RU6VLsM48Bx8Z7NdUyk72LEwFfgfIB7n2iCWnv8FyAl2kxHS4mDMDo5808QaG3xVB2VGMtoh6mmoakTTyxvTekg1fyV33nRF9QsaliR3Xt1ZZeO6eqXLR7V7UIzJ1EuoHkIBUHVSkiu6oEH+UbuffwgQQPDhGJMa3QrFy/Bwcx+D+ps8WasBjHTiKt62DFjZtKcgOi2O2C11Jm6yQRaO/bYOm3rSnxc3Rjrx92v4A== ARC-Authentication-Results: i=1; mail.protonmail.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=georgiou.vip; s=dkim; t=1763242400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZGsu9MCoisUHNsQA0UjF28LM5irZZJw892a55a9Md0=; b=o6euAp8MBKq9rU1e4LEC+gwuk/aJCUgu92KaETRwrEe2PEVqHw/w5tz8KlKNND/m2HNpoc CRt7UV5AVTSflZZ9j0OjVgWKfDhYoAOyPrNHYyM0Wh4eDxkez2tsDANMEArB5Qajehvd73 TbwL1JKNpOgbD6YKf7QgVrwO+tQYL8E= Content-Type: multipart/alternative; boundary="------------AmsJ7mm5gclnuC5U7EdVKUXx" Date: Sat, 15 Nov 2025 16:33:17 -0500 MIME-Version: 1.0 Subject: Re: rebuild big tables with pgrepack In-Reply-To: Content-Transfer-Encoding: 7bit From: pg254kl@georgiou.vip To: Pgsql-admin Message-ID: <176324240033.6.6265117135512277017.1008813004@georgiou.vip> References: X-SimpleLogin-Type: Reply X-SimpleLogin-EmailLog-ID: 1008813004 X-SimpleLogin-Want-Signing: yes List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------AmsJ7mm5gclnuC5U7EdVKUXx Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/14/25 2:14 PM, ek ek - livadidrive at gmail.com wrote: > Hello everyone, > I’m going to rebuild a 900GB table using pg_repack. I’m hesitant to do > such a large operation in one go. > Is there an ideal or recommended way to repack very large tables? I recall almost 20 years ago when Bruce Momjian was educating us on PostgreSQL (using Sybase ASE, but migrating to PostgreSQL), we discussed the table and index rebuilding mania.  I never forgot the "we have clients that haven't rebuilt anything for years and they run just fine" haha.  OK, sometimes if you have very "hot" tables its warranted, but the point that stayed with me is that it's usually unnecessary. But ok, you may have your reasons, so... 1. Connect to your cluster from a box with good connectivity to it (eg: for AWS RDS this means an EC2 instance on same VPC) 2. Definitely run pg_repack inside a tmux session 3. Be safe and have at least 3 x pg_total_relation_size(table) free space 4. Make sure you understand the -k (--no-kill-backend) and --wait-timeout options.  By default (no -k) pg_repack will wait on blocking backends and on a busy table eventually timeout. Decisions decisions.  Definitely run when things are calm. 5. If your default toast compression is not lz4, and this table uses TOAST, consider changing it to lz4 prior to this pg_repack.  lz4 is blazingly fast with low cpu cost. 6. I don't like running anything heavy handed on production without practicing/testing first.  If things go bad and management asks "did you test this?" the answer should always be "yes".  If this is your first time pg_repacking such table, make sure you first do it on a staging environment under heavy load during a performance run.  The cache churn can be an issue if your workload depends on a hot cache.  Again, definitely run during the calmest window, but test under load ;) At 900GB I'd start considering partitioning, it will make maintenance jobs more efficient, not to mention the smaller indices should help with better use of your cache (if your partition strategy can segregate old unused data from newer used data). -- regards, Kiriakos Georgiou --------------AmsJ7mm5gclnuC5U7EdVKUXx Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 11/14/25 2:14 PM, ek ek - livadidrive at gmail.com wrote:
Hello everyone,
I’m going to rebuild a 900GB table using pg_repack. I’m hesitant to do such a large operation in one go.
Is there an ideal or recommended way to repack very large tables?

I recall almost 20 years ago when Bruce Momjian was educating us on PostgreSQL (using Sybase ASE, but migrating to PostgreSQL), we discussed the table and index rebuilding mania.  I never forgot the "we have clients that haven't rebuilt anything for years and they run just fine" haha.  OK, sometimes if you have very "hot" tables its warranted, but the point that stayed with me is that it's usually unnecessary.

But ok, you may have your reasons, so...

  1. Connect to your cluster from a box with good connectivity to it (eg: for AWS RDS this means an EC2 instance on same VPC)
  2. Definitely run pg_repack inside a tmux session
  3. Be safe and have at least 3 x pg_total_relation_size(table) free space
  4. Make sure you understand the -k (--no-kill-backend) and --wait-timeout options.  By default (no -k) pg_repack will wait on blocking backends and on a busy table eventually timeout.  Decisions decisions.  Definitely run when things are calm.
  5. If your default toast compression is not lz4, and this table uses TOAST, consider changing it to lz4 prior to this pg_repack.  lz4 is blazingly fast with low cpu cost.
  6. I don't like running anything heavy handed on production without practicing/testing first.  If things go bad and management asks "did you test this?" the answer should always be "yes".  If this is your first time pg_repacking such table, make sure you first do it on a staging environment under heavy load during a performance run.  The cache churn can be an issue if your workload depends on a hot cache.  Again, definitely run during the calmest window, but test under load ;)

At 900GB I'd start considering partitioning, it will make maintenance jobs more efficient, not to mention the smaller indices should help with better use of your cache (if your partition strategy can segregate old unused data from newer used data).

-- 
regards,
Kiriakos Georgiou
--------------AmsJ7mm5gclnuC5U7EdVKUXx--