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 1vl3Ej-006FPU-12 for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 10:57:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vl3Eh-000on5-0H for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 10:57:23 +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 1vl3Eg-000omx-1s for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 10:57:22 +0000 Received: from mail-yx1-xb12c.google.com ([2607:f8b0:4864:20::b12c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vl3Ed-002imi-2k for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 10:57:21 +0000 Received: by mail-yx1-xb12c.google.com with SMTP id 956f58d0204a3-649523de905so1241736d50.1 for ; Wed, 28 Jan 2026 02:57:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769597840; cv=none; d=google.com; s=arc-20240605; b=V2RSfI+mElqRSFy1G7oXZuZ4vzXPiUCsQ6Am7AcNDpEljmuRFf4BN0QAAMJ2e5hS3I SCHkJSIBcCuWMlEUnX0BfzFGhBqpcO70VzLSyRojAhzwPim/b7kmvYPXyYurvqfgudny kwzvwlP1r6or4tSwv2c0pRfs2EYT0wduITUz1P13A4mVWAcKrko5i1Zwv2Drg9wDf0L0 OyEYtzZskzvVdodknzgxQEleQn00xz3OllW9ZnSXAFnKE9Y90FxXSg7Goxy/dvqUEYac vTFkclFAjskj+3jeYElMMV3AqAPY7GVhyxko77rbgrb6VvIlK4W5A0EmsovU1j2K4/Yb BscA== 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=0GW2xvQD28fkIktCMAOKN2Mq+OXOMQZ9WCd9k8dHu90=; fh=BxHDr6fW3b5OLIPm2aIu2fUE58mqJf26d4WD1+xlPJ4=; b=ZU4CTy3Vdn0ER0iffEFblM5Xz4KOI9rFuDOGwnWMLFcWD8l2xxNQV07FwRJNTAVHYi t+KyZiyUZ1sPV/o73G9FOhREyoqSCYcxBiploH4LKohAqgGhoARgEAyLBlZm0ANcupCL ON+6Nw9UJnZ7/7OlBGNAV0mlytxv2FX+8IWAcibmKIR5u7phZ25Zy+rriKYFHwWBQzb2 5+wm2bhrN+0kzrM6QC/0NDZMDNFXgelpuzhhV8ye/ZhlBZ62wNIYiLWnGIqVpFaz69IQ arpkqXf3W/DJtcqW4Zdv963anVcNkg+9WTDYCZNjnkxOZBWvQ6UCaP/ys+wKIgZVFvZ1 AOfg==; 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=1769597840; x=1770202640; 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=0GW2xvQD28fkIktCMAOKN2Mq+OXOMQZ9WCd9k8dHu90=; b=MdN71sJillv7Ys4K9/PUrMNNXEW8FgLmC27vv8bh0DHsHDdCUSU9P7P4vrTMOd2vAY bvKF1iH2DtbCtwBXxo2w8aWh7ffX9QL3ORUXFtJb3MxTlcH8vr3oP9bjqKAmsuoWHBRd Egf6jB0M1B9R60GCghfUsl5Ac88FMCnrnIOwlnTJXmb4Ogv0f95DipKDFS8YiW9hSlNG koCImnYRYh9DrKx5Si16ikbJEVaO++w+cLr9qv0uIRvjyhmhisdgZol4+0UogW/dorv7 1ZTX3lQBbO5U53aPV74JuWKpSAiGwBT5blPp+PUMkRbKGinok6yZge/axdob2sTRHQUg BCLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769597840; x=1770202640; 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=0GW2xvQD28fkIktCMAOKN2Mq+OXOMQZ9WCd9k8dHu90=; b=MefY9z/D0fv/6DNHD7cbXVWEJ0VN1Or3DN54gJ4qvEOdgnkH0gt2xLi53j4qdVGQFp kiB8RDobqMslKzXpfXf3sg4i4JoIVmenC5KkrmsT8voS2/tlr8vF8Dm6gA6PghGdhpdq EqRwBZ7b/SSnFLI1F7+9ucgeujswq3WFnsb/tEpbCdpvy+lh93u1t1rWQOa8P+PZfxys gSjKVIE70KllM1ow3AJh7PxOaj9DIPw/+iIWv/RjrT7ZS41Biq0hIOm4ezAHhb3Ow8x0 0JG4909WNTonoAY2teL4chL8lM7Ef5KBwygxZLksRX5TSteJm/rTrr2WloVfPtIHoEkO ILlQ== X-Forwarded-Encrypted: i=1; AJvYcCXIVDzN7JQJ3iO8YNa6xzMwkQh6+dUX88Q4GrzbOm8I/Mlv5aLjo/MaKABrkxHPAJ98m0LwfYTo65jaHmIw@lists.postgresql.org X-Gm-Message-State: AOJu0Yyh4H8srtiBz7Xao16/L/OuTw9XS30k1ZopI3dOjntXnvbYRRfH ng5xFZ/X8BtvYkDUjTMDHVIHjQdREGwZmJ0A/eLyX0ScQQ8D1Nnf6inwLdQkGrXvsIYPjFZ6/XZ J1/ZOv+0wAgd8hec/yGZCbXiQKoe5/TU= X-Gm-Gg: AZuq6aIxf5+1w7YjY4HFJnTEgvpZrgNECQBM9bRLkOv9QxCDTXCyknhWFOoZ2s9Y822 9qyxgOYPNjyGC9nrJFZo2Qum2E9RkEXerKC5CfOMPiAyAskMLvjXmsqkhi/kbZarVwzvxhVAO/I UCzJYppSHxLPTyeNfMBQ5EUvt7RmyzZfLZ6CMwuLBGEL3WHPQ8oPcr5PFzMN51oKUlYEXwn/MCo IUY9BV4X9BL/61fdDA/agpJ1rwli+rHvG7FyRsTS9KdOpLJUfX3bnMQGOX+r8lnmtgHtC72Q0Ho jpZX3n06E7xFtwwAJmhOWACy6Go= X-Received: by 2002:a05:690e:1c05:b0:644:75a4:d68a with SMTP id 956f58d0204a3-6498fb1a1d4mr3340421d50.37.1769597839851; Wed, 28 Jan 2026 02:57:19 -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 05:57:09 -0500 X-Gm-Features: AZwV_QhTZGVfXzIwgnaiMVUll6b6Kp3AS-62Pjtk8ZcUEDacLcInwwznU0sjJLc Message-ID: Subject: Re: Attempting to delete excess rows from table with BATCH DELETE To: Olivier Gautherot Cc: Tom Lane , Ron Johnson , "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 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 was = a mission critical database (say physical safety, real people) and the vacu= um 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 >> >>