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 1vl7vI-007STH-1a for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 15:57:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vl7vH-002Cg9-0Q for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 15:57:39 +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.96) (envelope-from ) id 1vl7vG-002Cg1-2A for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 15:57:39 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vl7vE-002l7o-0p for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 15:57:37 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2a09a3bd9c5so51062165ad.3 for ; Wed, 28 Jan 2026 07:57:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769615855; cv=none; d=google.com; s=arc-20240605; b=V5k7e7a/x+FMStd6BISqYdjgjHJPZBKVg9EijWr59AwKIH5fAKmIJtMnZBHgRoPy+G MC15oqWMEAhfdZ1IdsL+fXidrsDI8OkgCTNiK4MKBMDKApx+NmIJ37hMykbScS0r4MSB t3WP3mP8zKmPH+gcUGRbFR9lx4yXr5/eX0HKwdqk86sLR5gDLBrw3YJsf1So/rMhsdlY fcPbUmc7cBSsQ/+aQP8JMy/vkFjHcwZQ/FSsN6UirRPmMRlzN2gsqEhHYZNNB5fV6zp0 3rcFBce8HhaUdpbcLdPZ79X7a68wGjTkSWzwYKA4E1FX5dIwutubXibXOVp7RUWtZ03o 3CQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Ttw2Z4LI200/JC89vaKFiS2QQZyxgvr3itXQmc2uMKA=; fh=U9Vkrj/8YXu+wNKP4ImG87p6jlJYRxuB/zicT9qNons=; b=LipJLNa4GPEQlNo3Vfz4664d5ReqyOS8fYvEMdVJnGcton7EJpL3A5QrOyGoUu98x4 Blj3+v2W5AvL+LH7njBQQRL1+9WP8l0qRjsxRXHp3YJo/qMUxLf1birw2aThKEhee1IP amLH02hkIL6YDAx7EZfWHGiVrdXt770FFBgfitoHBWqia7UFHhj5JoPzAQVLa2cAAilR lWpyK4ADmYWnIL+FDP2Qpw5OYFODwtWfwb9VOg7uKmXZVBU4R1eFvlikNVtykvPMRwHU G6jJ34vOAhlBPguyLe6kX8HM1VQrxIqwlcRxpHPWA3U+uxSPMQ8vvTh2juHHksBL7IXn IZ/A==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769615855; x=1770220655; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=Ttw2Z4LI200/JC89vaKFiS2QQZyxgvr3itXQmc2uMKA=; b=PVpKv0+IECcu3YCTlS1MuCLNLZxAAR96dmgxherQXB2VoUe3qPIosX5RvIw1MVjQUu rio4Li0yE90jgx4jVmiKiA4I3FebBxaYSahcVi3L62Fswv/4nvQ85om04F/SGR7Exqv8 +R4ecWjdRU7pLIjHWedQtUCFNsCEAr2bFOlozuEhJg72ooT73T0giH7G+luOy5Gvg8fB EMnriHrn4RbOGsrfJY0xaoejKhnCmGP5hodob/4OFhTKMQEfRVO/V5vFcrbBdpU8kW16 qzk/IzaeL51/v6LAIY+vE0LtDR2e6OOnXjK1fXe20QUxBWSSQ/161pxhn/fDDfwVNyTk ypyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769615855; x=1770220655; h=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=Ttw2Z4LI200/JC89vaKFiS2QQZyxgvr3itXQmc2uMKA=; b=NegexSrE3BTiOZatBJ7DUwWOqhSvAwb2q6HxjmMhrLkn5HKPZH/ih4HzMeSijdvfLk jWZRvvZAiqzoqaJ/XIM69luIEZng+nQnbfeq+4q7C6O3xpH3eDMyp0ozEs0GzINvT0o5 ePf68NASNKnu/VkUdHRbTdcMkMMVQoqwc8gGBFQkWD3t4nV5XgN4lldEoT3AUd5LSinW ZrBpWT76SaLo/KCIXvXtLLAWvOhoN4BpP25OKKpMHlqXywa/wEKsJHpVMZluyAk9sd02 FlMrmaGHmbaxJ3G+xDZnOKHy6OIi5Dtf87zLG4R5JTloNrryQXarFOYR98oHy1VRMmjx lVPA== X-Gm-Message-State: AOJu0Yywbm6lJ1C1yP7Nb1+Zf/Jfyia6B9Q/R/+ehX7ZosIC6Y5A9Up+ ene2wptChoDYGA30UNroHIp/h0NblkGntucysB7SAHUhK8/z7l1gvnh66ZM8ix/p0dXF0wVcGGg Iz+DK6W4tJXfiFqZON0VsGq9NMZ5Zh3E61Q== X-Gm-Gg: AZuq6aJClaSR7rH+vCh/uRNtg+PGQvdAGukGz9hY6a4b2nJz30yJ5wWdjRToLvCF64+ 56thV1qxgsprzSaYaBUSmOM2/Iv6a0j3X9MwRUsRm9ZuPol6GIJRG5k0JoS0OVoWWpDrDqrUAlb kOej4VCRp0FNTf1uy/0jV9OOYFVNu/ydiFEVd5oc6em2Rn5tDjD2A9bjxt0P5DZ1Ai+hJo8zxQm ybMpUUxIHS++7JVSEuUANpoeXpambiN0EbMdA67s0I4SMmjB3pvMnIbqimO13v8zwo3lg6j X-Received: by 2002:a17:902:ce11:b0:2a7:9ded:9b48 with SMTP id d9443c01a7336-2a870dc9bf6mr51537195ad.38.1769615854798; Wed, 28 Jan 2026 07:57:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Wed, 28 Jan 2026 10:57:22 -0500 X-Gm-Features: AZwV_QhTsOT0-0F2utbwROWobDhloZJZQHgMdwkUY790_5dZd70yk_PP2gS_Vlc Message-ID: Subject: Re: Attempting to delete excess rows from table with BATCH DELETE To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000006a0c08064974cc63" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006a0c08064974cc63 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 28, 2026 at 10:39=E2=80=AFAM Greg Sabino Mullane wrote: > On Tue, Jan 27, 2026 at 10:31=E2=80=AFPM David G. Johnston < > david.g.johnston@gmail.com> wrote: > >> Strongly encourage you to try to accomplish your goal without any delete >> commands at that scale that causes vacuuming. Can you just create an em= pty >> copy and load the data to keep into it then point at the newly filled >> database? Truncate is OK. >> > > This is really the best solution, especially if most of the rows are > 75 > days old. This removes 100% of your bloat, allows you to keep the old dat= a > around in case something goes wrong, reduces WAL compared to massive > deletes, and removes the need to mess with autovacuum. > Looping DELETE is the Dirt Simple option when the application is writing 24x7, when there's a lot of FK dependencies, etc. It also allows you to throttle the process (bash sleep between DELETE statements, or only purging a few old days per script execution and then only run the script at night). --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000006a0c08064974cc63 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jan 28, 2026 at 10:39=E2=80=AFAM = Greg Sabino Mullane <htamfids@gmai= l.com> wrote:
=
On Tue, Jan 27, 2026 at 10:31=E2=80=AFPM David G. Johnston <david.g.johnst= on@gmail.com> wrote:
Strongly encourage you to try to ac= complish your goal without any delete commands at that scale that causes va= cuuming.=C2=A0 Can you just create an empty copy and load the data to keep = into it then point at the newly filled database?=C2=A0 Truncate is OK.

This is really the best solution, especia= lly if most of the rows are > 75 days old. This removes 100% of your blo= at, allows you to keep the old data around in case something goes wrong, re= duces WAL compared to massive deletes, and removes the need to mess with au= tovacuum.

Looping DELETE is the Dirt Simple option when the application is writing = 24x7, when there's a lot of FK dependencies,=C2=A0etc.=C2=A0 It also al= lows you to throttle the process (bash sleep between DELETE statements, or = only purging a few old days per script execution and then only run the scri= pt at night).

--=
Dea= th to <Redacted>, and butter sauce.
Don't boil me, I'm st= ill alive.
<Redacted> lobster!
--0000000000006a0c08064974cc63--