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 1vLoLd-00B5th-1j for pgsql-admin@arkaria.postgresql.org; Wed, 19 Nov 2025 20:00:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vLoLc-00F7fN-0a for pgsql-admin@arkaria.postgresql.org; Wed, 19 Nov 2025 20:00:12 +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 1vLoLb-00F7fF-2b for pgsql-admin@lists.postgresql.org; Wed, 19 Nov 2025 20:00:12 +0000 Received: from mail-vs1-xe32.google.com ([2607:f8b0:4864:20::e32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vLoLa-000Pua-0C for pgsql-admin@lists.postgresql.org; Wed, 19 Nov 2025 20:00:11 +0000 Received: by mail-vs1-xe32.google.com with SMTP id ada2fe7eead31-5dfd2148bf3so62853137.1 for ; Wed, 19 Nov 2025 12:00:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763582408; x=1764187208; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tphuomadqv5mBjQZEGzjO26BVlmonGhpPl381FtuXes=; b=XoCBKzQlWK7eL5JjtXcLBR1meQ7n74PgAHpbK1G7L4Vq0+gB15saLtlFUxDPRQSGxK 3ImKM5hRh0+AudjMcR1LqpUCuIwqDgeWTmh/voxlmwZP4FY+OQ56OTHm/asBOVkiQyL8 rpsQ2hQRgNB8TcUpInGQWgSZoFj46eZhllR53ocA5R4jZkTiZTJlH2oIevJKMJ14+TpL uSFmiCzDRs3wSH3UYrgkPzHm9g5Ic6RjT+j/xCkKfj4SH5TRiWSevBlP4lJwuSFmc6/H 4ZQyEMfW5VmWC+FMwDk4+LPc8DzcbQUs0rBaY6AuDpi2Y5ZDWsrCoR23Wlq5KIQ0J5H0 KCTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763582408; x=1764187208; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tphuomadqv5mBjQZEGzjO26BVlmonGhpPl381FtuXes=; b=fJbVS91nckyz+7WUtEiTwUhErbJ/9KKchBPWTSxuk5qxm6pcb+Mm7+lHwtJD593AAf wys41vxLCRvc6hGgKTyT+WZSIwVYMg8WvvfFdw4CqQkyUgeaUL3l0ZVXqxcUlwKMlWUH +inr4v4OMzy2xzP+9QXjBzAlgnqnFnmtxmFYlXvrB5GO+gGEj7a6DAhYcvUdPCAvVpuJ HkCiQow4tWeilbfxfDoonwjU+/YyvoFC3a8CTpNpwHJy9/czG3s9Am62XGi8SDQNVR8t lYF7tMxTq9SDLT9Emzw8StEBXQ+em8g9H2YYQIuBKzfsJo3ME8y7H6EwL2kZJFMaSf66 U0/w== X-Gm-Message-State: AOJu0YyFC7/Cf13Eu87/EvnqwTLSBXtxpyAjVKec7FVpY4u4Ct72wAvU P9P1JsBvUJI3sT2tB79Qk5pKSU6KyL4qAe1D7x3wGFiflFfYef3bCaKzgU2R/0NAPat2miyaliF sLlmYHtnWAH3S5YkbFgLRop5IGiCpkOM= X-Gm-Gg: ASbGncv52xAK7pd/6Q0beU7mYL8D8YHx40xYAqbm0BYTOcHNzH1YaV4tbLWOYvho4Mx y9b6+IPjJov54Zvu1LBrTKF61pxJ1mJw+GuNlRETG4zs4Md6HG2RXAJEhF04/QQlP+8DEKOYvuI ut7h9v7RgFLi4wR1ypVe4MIOzEfFeislBof54kR8jynFMS3wz+WTz0TNs1J1q77tPvhoOT9BlV8 bN2d0ELds/dWUpzfNfY3TVjliNVygA29Y602ywYfaE9PzwGJJ9g6wg2LoqR8mrJtJSEBzbUumTT WQ3A7g== X-Google-Smtp-Source: AGHT+IGn+SBfbnLFEcH388jUrHdtP+Cd/bE/WsXBrfF8QVdzGuqnuFn9V6k2SwxSAdZlNT99c3vz4bJXUE2T6NtSKuw= X-Received: by 2002:a05:6102:5816:b0:5df:c10a:6677 with SMTP id ada2fe7eead31-5e1bbfef33cmr314853137.37.1763582407834; Wed, 19 Nov 2025 12:00:07 -0800 (PST) MIME-Version: 1.0 References: <176324240033.6.6265117135512277017.1008813004@georgiou.vip> In-Reply-To: <176324240033.6.6265117135512277017.1008813004@georgiou.vip> From: ek ek Date: Wed, 19 Nov 2025 22:59:54 +0300 X-Gm-Features: AWmQ_bkdSixdJlw61hsGQsTZyvb3pxCwehTqh4qfL_sRZEwhzdVbQMYK6yFYFAk Message-ID: Subject: Re: rebuild big tables with pgrepack To: pg254kl@georgiou.vip Cc: Pgsql-admin Content-Type: multipart/alternative; boundary="000000000000f37e130643f80628" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f37e130643f80628 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable These recommendations were very helpful for me, thank you all. On Sun, Nov 16, 2025, 00:33 wrote: > > On 11/14/25 2:14 PM, ek ek - livadidrive at gmail.com wrote: > > Hello everyone, > I=E2=80=99m going to rebuild a 900GB table using pg_repack. I=E2=80=99m h= esitant 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 client= s > 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 blo= cking > 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 y= ou > 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 enviro= nment > 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 job= s > more efficient, not to mention the smaller indices should help with bette= r > use of your cache (if your partition strategy can segregate old unused da= ta > from newer used data). > > > -- > regards, > Kiriakos Georgiou > > --000000000000f37e130643f80628 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
These recommendations were very helpful for me, thank you= all.

On Sun, Nov 16, 2025, 00:33 <pg254kl@georgio= u.vip> wrote:
=20 =20 =20

On 11/14/25 2:14 PM, ek ek - livadidrive at gmail.com wrote:
=20
Hello everyone,
I=E2=80=99m going to rebuild a 900GB table using pg_repack. I=E2=80=99m hesitant to do such a large operation in o= ne go.
Is there an ideal or recommended way to repack very large tables?

I recall almost 20 years ago when=C2=A0Bruce Momjian was educating us on PostgreSQL (using Sybase ASE, but migrating to PostgreSQL), we discussed the table and index rebuilding mania.=C2=A0 I never forgot the "we have clients that haven= 9;t rebuilt anything for years and they run just fine" haha.=C2=A0 OK, som= etimes if you have very "hot" tables its warranted, but the poin= t 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.=C2=A0 By default (no -k) pg_repack will wai= t on blocking backends and on a busy table eventually timeout.=C2=A0 Decisions decisions.=C2=A0 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.=C2=A0 lz4 is blazingly fast with low cpu cost.
  6. I don't like running anything heavy handed on production without practicing/testing first.=C2=A0 If things go bad and management asks "did you test this?" the answer should al= ways be "yes".=C2=A0 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.=C2=A0 The cache churn can be an issue if your workload depends on a hot cache.=C2=A0 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=C2=A0parti= tion strategy can segregate old unused data from newer used data).

--=20
regards,
Kiriakos Georgiou
--000000000000f37e130643f80628--