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 1vl02E-005Y5s-2X for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 07:32:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vl02D-000IBS-2Q for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 07:32:18 +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 1vl02D-000IBH-0P for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 07:32:17 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vl02A-002hNs-23 for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 07:32:16 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-45c7f550f46so2087130b6e.3 for ; Tue, 27 Jan 2026 23:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769585535; cv=none; d=google.com; s=arc-20240605; b=U1GNVulr05pe476Q0FwV75ATOn6RLH/0r0k0OkOu8k0sW3eooOTD4iuHHlAV1AYhfn Sfh3wZH2UqZyDjYPhg3s/pwE4kuI2wRG2k/04PfvzIFE69bT0VITTNttb20VJlxZZn4V bvvdk7DyoYVh8n7PsPTyh26alubNUa0TOKwiFmo2oMjOOeDZWh//qER1OcXofaHbJTXH TN31xOGCCxF4itRqisMcQwNRVQMGaYOODuM6hLdvmUCnw4TPz/slfrFPZwZf/5nO7rzs YK070+jc+nXRWN3Qk5OnnCUCemSh5bjGuH21nfPZMnpOKjuE5SA+vrhprfOgDGKQNTrW WBww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=2ASjZEY7DiT8aqeFdcbcRDTAOi3kSISoK3mOn4vmbPE=; fh=yBLYP183Tj0KJZT2vP4q1gQaxuJrkCX8Yy6eijSsrIw=; b=EMN6EeIPIrDGWBnkFRjRR3TaHkNM2TlWBMCbkt1oeXOQoc/qPEY95klNxCXuqeOOVZ EYENKXcP2y96j+9k1G5mhfLMnMsfLvRbfH0W4QnUOPSVVrp6ztymvBh/uJklx6jnI69m v182l4HhxJquz2tiOy+qhAaUVO8ALDNZZEzKnLZSsAYUVaXD76OooYLH7pG3SxadmYhx apcN/QN/f+6dnTyiM2ioGnJVk8T4koWr2if/kr3lFZEF2Z4+3jIlf50F7VGpDb1ET/8x 3T4iiV8omf8ChomqF9mDVFuCza8b0Ms2aW41XVs0Dr8B5OIFzHwl2Iq8rHzyXOAdYrWk Qcig==; 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=gautherot.net; s=google; t=1769585535; x=1770190335; 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=2ASjZEY7DiT8aqeFdcbcRDTAOi3kSISoK3mOn4vmbPE=; b=B67VWJ9Tp3jYXxCmosRMoLcjpoMS/Joasq2Gr3aFFPCcc9GaFrM0/JqvWS7sLWbb/V eqBKcwCTnAa/1hHd+UyJsJQiz4d8r/GKgUlWD08cSBbcuOjhmtKJQS0qgWKZ0F3BH0TQ NmJ9f9I7QaO/kjdun6QoTWfJWSZNeHRFJpTlEzbw+kuzwgCATErvepe1zsWNQsPE43xK /pT5mAQIelu3hQd+jJAmGeGbsVDenbXN8JFx7SvpSYVBXZGw834zrh59w9XI0uclhqBU BtIwFenzPTTLErDvcaJ3RDTDLkkkrJcZ0ypkV1qD+FP8/TTQSIkAtG8NMNiiNi82o/G3 bWeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769585535; x=1770190335; 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=2ASjZEY7DiT8aqeFdcbcRDTAOi3kSISoK3mOn4vmbPE=; b=msVT8NzjO2pcDeA4MWXgvexW1PbxwgaT9h4HDV1rx5QGK/lzqGpQgrP7rOVTa90Q/7 tgCUq0NUYNEtexfgIEigrQhUS37NzB+Oso80dBBG/Z2uwu1zz3eHGMZAYyOWFVhel9rO GX/l070w9eHCuVQEXv1U/IfuJfpsc0kQZVcbbfr7p7EuLQ+u4UFkXKGBqR+1qRy7IXU8 3gbyuHNcatJCoYALPiXQbk4qRdYdSAC6sNPU1nk5j1hIL4iGkAGgMaubJ9ax2WJ37p8+ UJhMLXV6nBy1aim82qjpVHZZEfQV382bxPNwdm3Q7Cbghh7/WUUlu5oRr/+r/Cf7CN+b PlFQ== X-Forwarded-Encrypted: i=1; AJvYcCV61nr0n6D3w7ysqrM5V4jNzN/ooq5jnjwYdwx3VrrTikpbEAFpUVM75zMM1v+UMvJvWxhH7lZkps1gbSCP@lists.postgresql.org X-Gm-Message-State: AOJu0YyPHZBVd6mrRxGe6zJbhuH45SACb+NjupwAEwehqC8nSqAKNzkX sqZeYGU1vbsCGlXvQKRYWn3z4ssMu/FDr12DGR1uAeuiZxmbhw+GItG1M29C3AExdHu5nzrEfGz KCKen20ezeOY8cTgrKg6A541SMFttuwfIbUVVL/UB X-Gm-Gg: AZuq6aJ4NTsZDgnRxeloVlzZyC9eJhnZGvpI58Q56SM8FOhEczeCjvAzgTiCSmhtCEv fiD546B7UzYsm9fGJa0etMwWdqlMdI2/pdw3Wa9DsevP0wZWqkNEmfbcfeXOLc/voPfaDaj0ZqL BkASf5F6QnFdJr6qVlQcCY5MHN13yJpRxoJqvxpAToVhFp6Cq0LN5fBrKFgFe/OGrbZriimXgg1 5JOBzmze7bL6fxnvyXLmryjq2sjzJiSlVN+y3AwJQkr/ISmAZA8G5Ev1EEUtgaQlflHh+9/Zdq8 USWuxCTEsYML75Wdgw== X-Received: by 2002:a05:6820:4dee:b0:657:48ac:99f4 with SMTP id 006d021491bc7-662f208c42bmr2909906eaf.1.1769585534773; Tue, 27 Jan 2026 23:32:14 -0800 (PST) MIME-Version: 1.0 References: <729685.1769572320@sss.pgh.pa.us> <731539.1769573201@sss.pgh.pa.us> In-Reply-To: <731539.1769573201@sss.pgh.pa.us> From: Olivier Gautherot Date: Wed, 28 Jan 2026 08:32:03 +0100 X-Gm-Features: AZwV_Qj6x7ZW81dqc3F-Flr1sbWzIuNpPQ9bdvpphCcZKU1eraQiZCe_1vZFF3Q Message-ID: Subject: Re: Attempting to delete excess rows from table with BATCH DELETE To: Tom Lane Cc: Ron Johnson , "David G. Johnston" , Gus Spier , pgsql-general Content-Type: multipart/alternative; boundary="000000000000333cec06496dbd27" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000333cec06496dbd27 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Gus! This reminds me of a costly mistake I made and you want to avoid: it was a mission critical database (say physical safety, real people) and the vacuum froze the DB for 24 hours, until I finally took it offline. If you can take it offline (and you have a couple of hours) - disconnect the DB - drop indexes (that's the killer) - remove unnecessary data - vaccuum manually (or better, copy the relevant data to a new table and rename it - this will save the DELETE above and will defragment the table) - rebuild indexes - connect the DB The better solution would be partitioning: - choose a metrics (for instance a timestamp) - create partition tables for the period you want to keep - copy the relevant data to the partitions and create partial indexes - take the DB off line - update the last partition with the latest data (should be a fast update) - truncate the original table - connect partitions - connect the DB In the future, deleting historic data will be a simple DROP TABLE. Hope it helps -- Olivier Gautherot Tel: +33 6 02 71 92 23 El mi=C3=A9, 28 de ene de 2026, 5:06=E2=80=AFa.m., Tom Lane escribi=C3=B3: > Ron Johnson writes: > > Hmm. Must have been START TRANSACTION which I remember causing issues > in DO > > blocks. > > Too lazy to test, but I think we might reject that. The normal rule > in a procedure is that the next command after a COMMIT automatically > starts a new transaction, so you don't need an explicit START. > > regards, tom lane > > > --000000000000333cec06496dbd27 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Gus!

This reminds me of a costly mistake I made and you want to avoi= d: it was a mission critical database (say physical safety, real people) an= d the vacuum froze the DB for 24 hours, until I finally took it offline.

If you can take it offline= (and you have a couple of hours)
- disconnect the D= B
- drop indexes (that's the killer)
- remove unnecessary data
- vaccuum manu= ally (or better, copy the relevant data to a new table and rename it - this= will save the DELETE above and will defragment the table)
- rebuild indexes
- connect the DB

The better solution would be parti= tioning:
- choose a metrics (for instance a timestam= p)
- create partition tables for the period you want= to keep
- copy the relevant data to the partitions = and create partial indexes
- take the DB off line
- update the last partition with the latest data (shou= ld be a fast update)
- truncate the original table
- connect partitions
- connect= the DB

In the future, d= eleting historic data will be a simple DROP TABLE.
<= br>
Hope it helps
--<= /div>
Olivier Gautherot
Tel:=C2=A0+33= 6 02 71 92 23=C2=A0

=
El mi= =C3=A9, 28 de ene de 2026, 5:06=E2=80=AFa.m., Tom Lane <tgl@sss.pgh.pa.us= > escribi=C3=B3:
Ron Johnson= <ronljohnsonjr@gmail.com> writes:
> Hmm.=C2=A0 Must have been START TRANSACTION which I remember causing i= ssues in DO
>=C2=A0 blocks.

Too lazy to test, but I think we might reject that.=C2=A0 The normal rule in a procedure is that the next command after a COMMIT automatically
starts a new transaction, so you don't need an explicit START.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane


--000000000000333cec06496dbd27--