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 1vkw8b-004iGH-1C for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 03:22:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkw8Z-00Gv30-1Q for pgsql-general@arkaria.postgresql.org; Wed, 28 Jan 2026 03:22:35 +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 1vkw8Z-00Gv2s-08 for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 03:22:35 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vkw8X-00000000oNX-0HCC for pgsql-general@lists.postgresql.org; Wed, 28 Jan 2026 03:22:35 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-64969550a1aso3633358d50.1 for ; Tue, 27 Jan 2026 19:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769570551; cv=none; d=google.com; s=arc-20240605; b=JIRx6JHsxrFgib5WiD7dQerOLKzHiJ6SKaJC2hqyMnu9HGPXOKdGcGqqiplHztZTVl xtRpCWn1pgVih9orfdsVrI/WcfxgZvkqQurvb6BsKZr0vxA7AoW3tB+It0wu+aN4D/fZ 5PrP2Jp8IRr941w9gsYZwMMjqZwACXW6AgUFFsDVttDF1Co2kJdPFtSisO9aGlBnE7FD E0+fr0sliVp8A3MUWjI1dbfQu9w8T8E2dDYYzTSSGYvSvkBeAANQEfHDJUO9U19hi2qg u+V6ahYg7a7mFlDiqcDBgOVKOUaJ81Wc2aTS5lOi77eNMbFYrfCjUDUAibmz3Dw/5ho6 EROg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=2lw5SkI5E043t+xFw8HGtMLSBzdpTCHVpZr4K62kD4E=; fh=U9Vkrj/8YXu+wNKP4ImG87p6jlJYRxuB/zicT9qNons=; b=GOfbwY2w/OSDWFZEgSiH+vbxGmW43aMYY0/CNKc/3OvwiHvqgZFiuF6smIzN1DR2vH vw7OP1+cEFxPoxDyIkGHF59pvl3AIz2X9fdp3oWZbylxtOwg2kDQTp1CBdpOKH94soKX Z1Zbpywf51kYRLUdkh/MtgWhRLYbQRydL7OdLNils4E4e2SFQPp5PNeajn6iQ/xR5ImR K6Z5bElLZyrhkp498S8SLJsZYyD9YXGfmAVmjoTv4re2EWH2zRLClpA2YxKcBQF0Li0j dZErw65kdem3cxQg9o2K6fJzEWUpxfohrd9KtxRXOVMuYWQUCU1AytrDvy9XTjOfLcNL /yqw==; 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=1769570551; x=1770175351; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=2lw5SkI5E043t+xFw8HGtMLSBzdpTCHVpZr4K62kD4E=; b=a0lld0lujj4AN0eLo/PchL0JsalQC3HI82/iBKqmVGKYwiEv9xjyQmZr4WnjE74CKf cT339n8A3EQ0/ldnjbOjHsEX6hOW1gD1LQxfBN2KYtgVRiY3y1aWwRS5fQsU9DDOfFt/ WCdZZNgpKqpM27hUMGVGyhx32f9mcb1cjNnPlAUYQ7fb9gasoolN/vwqMqkd5repFfm+ TxTTfkiyNg/zs2h0K7eWAxeVOdV5BWSRGphOi/LygwXu3enQaMD9r+hkUHRDlpS+Yrt7 Mu9UgABs8Mxo7PlEhbCub4mwX3Fgud5pXVkZpUb3vczNAVE+W6lwD0QEQk+mXUPfYscC 8bxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769570551; x=1770175351; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2lw5SkI5E043t+xFw8HGtMLSBzdpTCHVpZr4K62kD4E=; b=q2lHsq0SgD59LNu47xat3QVTFVnmvJW+jjD0htEK80+OMcIAFtDkRMH7Q0Ku3v+bgM ZEXVChGNt2s88Rr4OMTbjrSagKxehfoY2ueKvvPdxxHvzgSxBkCqNw05ImtVtQ4b3AtE KsBmCQF9r3qySFq0im6U7LMVDqq/TG0VBx0Ewi5n0DJJkx5qaxqH28YqD+CKl3eeEq6R ZdcEv4MAhxFPejmbd2L6OLG8HFkU2p+YFdIxhwotMgbVNPal0k2rOWfTsrQJxj7rHDlW ATXX1X74FUjNy/OyV8fMKSs8CQj4Plw8efN8Tk8XPumfoiHoFO6ny+9dLiQ3VJcUysoz Riog== X-Gm-Message-State: AOJu0YxvEtnOxpa1ibykcNt1PFJsk3LJanA4lf1fpzhK28IzaIz1is77 QO5cGwoFylOeoUZGWHxsuFdGew4QK2fkf/+xKr1D9CmwSggyDv9btIThJvoQhMm1PVsWCm7iuxE MaeGp7YTRlndtLe5z4ceEyZTtnUeco5Wh9u1E X-Gm-Gg: AZuq6aLQU3HDo5bGjWQlPxX8uiqHq9U8mIZmbU6qEjcbVfnb/I/Wzps4l+Gtc5BAyp3 B6btzsMmaFe1VD0LAiNMQ66gEOdRGqwDE9eAo2+EUZC5uYuEAQW9XQmZVB1bTds3rYhQ8bXWJCx GbN+fxyqNcltjnikOUwIAad+4ghySoycki7LvcvirjdpUiKBvmjzCO73EyGxFFuyY1cCsimII7h ehTsKC9paJDxBTIMWUZtgyknoGzRnddhw6iFhJpqPhfX/r1QzyojIOB09HR52QY/XkS+fYaBGJN XmBVKwI2HBQf4mfnX0tk/ImeW8Y= X-Received: by 2002:a05:690e:1c1c:b0:649:443f:ab2a with SMTP id 956f58d0204a3-6498fbf8a0cmr2728618d50.37.1769570550975; Tue, 27 Jan 2026 19:22:30 -0800 (PST) MIME-Version: 1.0 From: Gus Spier Date: Tue, 27 Jan 2026 22:22:20 -0500 X-Gm-Features: AZwV_QhO5s0A2TnAo8hntREIPWcZZYlDmtyDm1SlMbKf6ytzJBGqYcndgFuplDA Message-ID: Subject: Attempting to delete excess rows from table with BATCH DELETE To: pgsql-general Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Environment: AWS RDS Aurora for PostgreSQL 15 hosting tables that support scientific research. The development environment predominantly uses JPA with Hibernate. Years of neglect have allowed mission tables to accumulate hundreds of millions of rows of excess data. The developers and the customer decided we must delete all rows older than 75 days. Table partitioning was briefly considered but discarded because of the effort needed to refactor the codebase. I proposed the straight-forward course of action: delete by batches from the victim tables. The solution seemed obvious: For candidate tables: - Determine timestamp column iwith the most relevant value and call it the Discriminator. - Delete any row whose Discriminator value is 60 days older than the Discriminator, with a LIMIT of 50000, - Get the results of the batch by querying GET DIAGNOSTICS. That value held aside for later use. - COMMIT the delete transaction - Loop to the top and continue deleting batches until there are no more rows older than 60 days. - Before running a test, I ensure that the Discriminator column is indexed I write a procedure to accomplish all this work but it persists in returning a error to the effect that a COMMIT is not valid in a block tht tries to DELETE data. Has anybody seen this before? Is there a solution? Thanks in advance for any help you may be able to offer. Regards, Gus Spier