Re: Need an idea to operate massive delete operation on big size table.

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Gambhir Singh <gambhir(dot)singh05(at)gmail(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Need an idea to operate massive delete operation on big size table.
Date: 2025-01-15 21:02:14
Message-ID: 82cbc03d6bae358db66430f5518abd6b1a683571.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, 2025-01-15 at 20:23 +0530, Gambhir Singh wrote:
> I received a request from a client to delete duplicate records from a table which is very large in size. 
>
> Delete queries (~2 Billion) are provided via file, and we have to execute that file in DB.
> Last time it lasted for two days. I feel there must be another way to delete records in an efficient manner
>
> This kind of activity they do every month.

I don't think there is a better way - except perhaps to create a new copy of
the table and copy the surviving rows to the new table. Than may win if you
delete a majority of the rows.

For the future, you could consider not adding the duplicate rows rather than
deleting them. Perhaps a constraint that prevents the duplicates can help.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Alex Balashov 2025-01-15 21:24:53 Re: Need an idea to operate massive delete operation on big size table.
Previous Message Mohit Mishra 2025-01-15 19:34:03 Re: Move datapath