Re: delete taking long time - Mailing list pgsql-sql

From Mike Sofen
Subject Re: delete taking long time
Date
Msg-id 000201d17f26$13eda040$3bc8e0c0$@runbox.com
Whole thread Raw
In response to Re: delete taking long time  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-sql

>>From: David G. Johnston
>>Sent: Tuesday, March 15, 2016 6:25 PM

> There are around 800.000 records matching this rule, and seems to be taking
> an awful lot of time - 4 hours and counting. What could be the reason for
> such a performance hit and how could I optimise this for future cases?

the db has to touch such many rows, and has to write the transaction log. And
update every index. And it has to check the referenced tables for the
constraints. Do you have proper indexes?

 

Given the lack of indexes on the one table that is shown I suspect this is the most likely cause (FK + indexes)

 

David J.

<< 

 

There are SEVEN FKs against that table…I would bet that’s 50% of the duration.  The lack of an index, perhaps an issue, but

With that many FK references plus that many rows…the transaction log could easily blow out and start paging to disk.

 

When deleting more than perhaps 20k rows, I will normally write a delete loop, grabbing roughly 20-50k rows at time (server capacity

dependent), deleting that set, grabbing another set, etc.  That allows the set to commit, releasing pressure on the tran log.

 

You can easily experiment and see how long 10k rows take to delete.  If still long, the FKs are the issue…you may need to script them out,

drop them, run the deletes, then rebuild them.

 

Mike S.

pgsql-sql by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: delete taking long time
Next
From: ivo liondov
Date:
Subject: Re: delete taking long time