Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKXWy-0005Ug-Fg for pgsql-performance@arkaria.postgresql.org; Tue, 05 Jul 2016 21:05:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bKXWx-000810-H8 for pgsql-performance@arkaria.postgresql.org; Tue, 05 Jul 2016 21:05:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bKXVI-00066k-Dn for pgsql-performance@postgresql.org; Tue, 05 Jul 2016 21:03:36 +0000 Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bKXVF-0000y4-1C for pgsql-performance@postgresql.org; Tue, 05 Jul 2016 21:03:35 +0000 Received: by mail-oi0-x22b.google.com with SMTP id u201so246110982oie.0 for ; Tue, 05 Jul 2016 14:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Csj6NyKri/rAUJR+mdzOcp4Rn6l9l9o3kKoMLizJ+EQ=; b=BrfV3rKQvtGxIBqQ293Z6zvrm+WwekClqgwKNqjNYTrOztaln+eZ7B/vS52e5U8x9X TZy75tEu6iM2+wr13DCc0MaljAynzqS+MdyBys4p351VOh6Wz6sceuFcqdcDCMkQivEU GhXi1EXNOo1xzv31fMhYPsPoQjnyMvJCl3G/0es4BaHCDpeeMzQnkne97py2BxyRTqm1 pHmN2FZ+9AORCoZt63vCV1qAWCenIteCKm0mYjSvLLo/G5XfiSd9t/ULEQCXZrrXVhzc 8LkjcCpSYMuIAnhd8CmFXvxAn1ZnyEvdGyfuZ87QSL0jbwdSIWhqSU64NTzW4w2+YeNR BifA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Csj6NyKri/rAUJR+mdzOcp4Rn6l9l9o3kKoMLizJ+EQ=; b=NsEsaGBlQixxSgR5fOlLgJYlHj9sUfG7+dophYdyTX9Md4O/L+SpinbNeTO6H15wUl vzbp0v9QpYDsIqaY2bfVNVMPIOlPikrNybrJ3qWtHTpUrbBlQIX+mmqxx9ywTA3zNZnc Y2o4L6Y+yD88p3FSyq9bbMpoI6k38ka05OW/K/ANr7bUybxTN4AxzMKk6euxWaeaUrhq swbLVTe0xwl/kacdOyqeOzlQ8c5M7e/zA8gdaSPc5FEecgN2qnKUrxlo8/0wpARCSb6m 8NZ1dHeOMhpGMqWNzFFmonG0szYwHItexnHZbCC+e2rcQXlboLGZaiaoDvdvr9WYTK71 5pmg== X-Gm-Message-State: ALyK8tIkUKNEoOt8eqS4WD4By+cgRFF4UZGSyD8TD0SWiyG5sf8V7NYxFPeIKhteAhfDVXk7ASzV+7oqJIXsrg== X-Received: by 10.202.79.66 with SMTP id d63mr10893095oib.5.1467752610663; Tue, 05 Jul 2016 14:03:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.245.234 with HTTP; Tue, 5 Jul 2016 14:03:30 -0700 (PDT) In-Reply-To: <577C01CA.6080208@agliodbs.com> References: <20160704170458.GA425951@alvherre.pgsql> <577C01CA.6080208@agliodbs.com> From: Kouber Saparev Date: Wed, 6 Jul 2016 00:03:30 +0300 Message-ID: Subject: Re: DELETE takes too much memory To: Josh Berkus Cc: Alvaro Herrera , pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=001a113d72b6fa12e00536e9c892 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --001a113d72b6fa12e00536e9c892 Content-Type: text/plain; charset=UTF-8 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 : > 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) > --001a113d72b6fa12e00536e9c892 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 correc= t that rebuilding the table will be faster, but then, there is a chance tha= t 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 mem= ory consumption be related to a GET DIAGNOSTICS plpgsql block? The delete i= tself is within a stored procedure, and then I return the amount of the del= eted rows from the function:

DELETE FROM
=C2=A0 audits.audits
WHERE
=C2=A0 id <=3D last= _synced_audits_id;

GET DIAGNOSTICS counter =3D ROW= _COUNT;

RETURN counter;

=

2016-07-05 = 21:51 GMT+03:00 Josh Berkus <josh@agliodbs.com>:
On 07/04/2016 10:10 AM, Kouber Sapa= rev 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 pu= rpose.

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)

--001a113d72b6fa12e00536e9c892--