Re: DELETE takes too much memory

From: Kouber Saparev <kouber(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: DELETE takes too much memory
Date: 2016-07-05 21:03:30
Message-ID: CAN4RuQtDxv0tAs=bY-6RyhSfUxPRc=XJV-6iLrP+yyE9snJDQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Well, basically there are only INSERTs going on there (it is a table
holding audit records for each DML statement). I do not see how a DELETE
statement could block an INSERT?

You are correct that rebuilding the table will be faster, but then, there
is a chance that some INSERT's will be blocked and eventually will fail
(depending on the duration of the rebuilding, the exact moment I run it,
and the involved operations on the other tables).

Could such a memory consumption be related to a GET DIAGNOSTICS plpgsql
block? The delete itself is within a stored procedure, and then I return
the amount of the deleted rows from the function:

DELETE FROM
audits.audits
WHERE
id <= last_synced_audits_id;

GET DIAGNOSTICS counter = ROW_COUNT;

RETURN counter;

2016-07-05 21:51 GMT+03:00 Josh Berkus <josh(at)agliodbs(dot)com>:

> On 07/04/2016 10:10 AM, Kouber Saparev wrote:
> > No. There are AFTER triggers on other tables that write to this one
> > though. It is an audits table, so I omitted all the foreign keys on
> purpose.
>
> Is it possible that the DELETE blocked many of those triggers due to
> locking the same rows?
>
> Incidentally, any time I get into deleting large numbers of rows, I
> generally find it faster to rebuild the table instead ...
>
> --
> --
> Josh Berkus
> Red Hat OSAS
> (any opinions are my own)
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Torsten Zuehlsdorff 2016-07-06 08:35:51 Re: less than 2 sec for response - possible?
Previous Message Mkrtchyan, Tigran 2016-07-05 19:17:33 Re: Tuning guidelines for server with 256GB of RAM and SSDs?