Re: delete taking long time

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: ivo liondov <ivo(dot)liondov(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: delete taking long time
Date: 2016-03-16 01:12:27
Message-ID: 503958962.9182.1458090747344.JavaMail.open-xchange@oxweb01.ims-firmen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


>
> I am trying to delete the connections with date 2016-03-10 by using the
> following:
>
>
> delete from connection where uid in (select uid from connection where ts >
> '2016-03-10 00:30:00');

try to rewrite that to :

delete from connection where ts > '2016-03-10 00:30:00';

It's simpler - and (maybe) faster.

> 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?
>
> Regards.

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?

How large is shared_buffers set?

Can you show us the explain (analyse)?

Regards, Andreas
--
Andreas Kretschmer
http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2016-03-16 01:24:41 Re: delete taking long time
Previous Message ivo liondov 2016-03-16 00:10:35 delete taking long time