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 1vl7dU-007OF4-03 for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 15:39:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vl7dT-0024wb-0G for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 15:39: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.96) (envelope-from ) id 1vl7dS-0024wT-1z for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 15:39:15 +0000 Received: from mail-yw1-x112b.google.com ([2607:f8b0:4864:20::112b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vl7dQ-002kzA-0L for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 15:39:13 +0000 Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-78c66bdf675so70050217b3.2 for ; Wed, 28 Jan 2026 07:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769614752; cv=none; d=google.com; s=arc-20240605; b=dSDg390muMP9NvDEiFDTk0/AkYquxREY266+BrQSLWeiUobX7r4xA937rEBi23EZjs v4Oyg27h2T73NfUF8w1Iq4DrzXboAJV9R4TrZz0r7S4qANJajwxbTXzt6+bn9iXC+wgX tpJi3LsmD8kpSB2/yo4X6t0KhGwzIV8NVUM5MVGXsrWwc6Irqg/JAdvcuYlpjVDaP7Yv I3aJIp0A0TyMkWbbIX8phlbNxmXNufKfDimDDU/++swMg2n/9BAsFVvx2abBuJpfbhn9 bmjE/FkwDjxP97WtT20lvJQI94OWk/P7e4F1qS+MADYsWg/I9f9Un1aX/QgoeZRvzb16 Wx8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qZ60kStXSp2ozZ5XkWmUuZDUUxrxf3sjmqLXNexJCfs=; fh=K7sgFVWtDOIc4H48yQIxXQzpWZSuU5a70IeCp/g6eUA=; b=cyXvXXWJPklMeN6+12JvpEGKBN3ev0lLgTDnTgxvBLzIh6pbLyBAO5G99Jr9wz8lBZ 0pqPncXkizHpuEdN6S6xgIKDVtUEf5n332tKMhxUCwJI2bCCJ83rLxYfd2BsJYUx1DUS P9iAp5D9lbyzX0SVvrWkm0FbYdWWQQtZLbHY9niEvEmhnn/ebLSJW7hecdHdbEJNyswC zslEaNfu+puynu7TPGHsmdBbN9/kUpm/DBst3P36VFW2Sxsez4Bfud6jCwLg+DBSHtYA +4ka0UFzfQUfigDNBGXaQIVL2z/CMnTKvD7kAX7c3EFzpUstRRRuSdi2H3TiI1QmA/EK EiUQ==; 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=1769614752; x=1770219552; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qZ60kStXSp2ozZ5XkWmUuZDUUxrxf3sjmqLXNexJCfs=; b=TvL3m7I+nTdm4UVJCrcbldeDSbbdeLoXORpV60Vx6/6myUOG52hUkyRkK2fcEvtRhu O7F2ilBbnddWWlkBK6j+wLEqFuqO2QkQuvPZd5QePJvDOjBEVou/hRYqKo5paR9xpJZ8 WnvlEm3BweySBleuxz41cEEr0NiiQ58r4Uzjzfa/VxnCI3hDgD2Na7Qvg1LRx756pCxh 3o6f23+9zzgJvQfw9ZaRCoDMj7JsBjrNcltghqCic8DbEnQlRuZITubUqTAO9jmrRgsG 9wnX1oqvnl4O2t/TIIf7OBqr7uOiDn2QfpqijIEMAS6lMdcS8mROtpVNhfYPG0WZnQMb s1MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769614752; x=1770219552; h=content-transfer-encoding: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=qZ60kStXSp2ozZ5XkWmUuZDUUxrxf3sjmqLXNexJCfs=; b=HPVjKX3QgmOAeWY6ienH/LNKsPIbagFlRc9LFjQ70Yj+WTNh0ExG1gvy5iRbcjq29P aKJofinSzq/z/X7nIvXzFK2SC+jpJ+9Yr/AEdH7bhK/Gm3QkXS7SnA8iIJPuMAvRKVOg sDTtLehl8k7qY7WaAh+l0xjtpVJ9uWX+rw98q/by0eNRWZ8u+NQBFYgMOJsC5YpnIf6N NPwhEcgnwbCSyVneAP7Wbkwa+esx0SGmjhi8X+ylburWB+hO3S2vzfIBTswRpk6JS2iF jXOyLmDumsYB/DgNB1r0JvAWI2tDll3I5Ij5EvyAAIoybMeb1SW9jENd0qXFBp1lCU9h 4qdQ== X-Forwarded-Encrypted: i=1; AJvYcCWWnHkqLFiOf3xom5HsuoN1e2/3Gjf7TDFy5d+1zIgKURNAvkdRQGPDD2yzIVblm8zvfOaBV+3lUiFB34uP@lists.postgresql.org X-Gm-Message-State: AOJu0YxQql1vgSZF2nSANniW3VcNjmpFsSuZiv1nzR1WbwSZA4JksHf+ c8AcLXK9POvE8Fa3XTXOA/Aww7XP3g0BmEBXhA6DGgumHm2UQ6SaKAZ3ksSLUrVjx69KOt0OArv AEpPe1PiBztzYndT2/s+G6cec4tXatBc= X-Gm-Gg: AZuq6aI/lYOnpHxKKoIl4JhLCQ5X9Q1KXf25RNuEN8e6GPzmzZYALdphF4jR+XWiXiA s4cDYGWGKR2eqiQ4FPVSFZVqcklRe6YHdsixGWwEBhc6Gjik4b261mtsiZWdZA1de3roCwxO2y9 USc0FYR5csbJ3PaRu2X+qFUkmmH3/Y4QKfDlRQhX/Bxa1yOquuRJs4+kxQSZVh+ma2a07wYq3FJ 7LgyDFb4zveNVgkM6gkyMZwGm8rn2OgVkl/h9kqOpBiA3Xsv0aIOOilIG9vHyDAdol//cE= X-Received: by 2002:a05:690e:150c:b0:641:f5fa:e9be with SMTP id 956f58d0204a3-6498fc0678bmr4225182d50.34.1769614751802; Wed, 28 Jan 2026 07:39:11 -0800 (PST) MIME-Version: 1.0 References: <729685.1769572320@sss.pgh.pa.us> <731539.1769573201@sss.pgh.pa.us> In-Reply-To: From: Gus Spier Date: Wed, 28 Jan 2026 10:39:00 -0500 X-Gm-Features: AZwV_QjGSlNf6zBQgW6dCuDhFrovh9quGRyjBJK3je2H8pFHQCbIQWJ72K9UFmE Message-ID: Subject: Re: Attempting to delete excess rows from table with BATCH DELETE To: Ron Johnson Cc: Olivier Gautherot , Tom Lane , "David G. Johnston" , pgsql-general Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Good thoughts. Thanks, Ron! On Wed, Jan 28, 2026 at 10:02=E2=80=AFAM Ron Johnson wrote: > > More thoughts: > 1. In cases where records are huge (bytea storing images) I added an inne= r hourly loop. > 2. Disable autovaccum on the table you're purging, then run pg_repack on = it and re-enable autovacuum. > 3. pg_repack --no-order is a lot faster than having it order by the PK. = (You might want it ordered by an indexed date field, though.) > > On Wed, Jan 28, 2026 at 5:57=E2=80=AFAM Gus Spier w= rote: >> >> Thanks to all. >> >> I'll give the bash loop method a try and let you know how it works out. >> >> Regards to all, >> Gus >> >> >> On Wed, Jan 28, 2026 at 2:32=E2=80=AFAM Olivier Gautherot >> wrote: >> > >> > Hi Gus! >> > >> > This reminds me of a costly mistake I made and you want to avoid: it w= as a mission critical database (say physical safety, real people) and the v= acuum 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 a= nd rename it - this will save the DELETE above and will defragment the tabl= e) >> > - 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 upd= ate) >> > - 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 iss= ues 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 >> >> >> >> > > > > -- > Death to , and butter sauce. > Don't boil me, I'm still alive. > lobster!