Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bK7Pa-0003Bx-Hx for pgsql-performance@arkaria.postgresql.org; Mon, 04 Jul 2016 17:11:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bK7PZ-0002Tg-SN for pgsql-performance@arkaria.postgresql.org; Mon, 04 Jul 2016 17:11:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bK7Nt-0008KT-8P for pgsql-performance@postgresql.org; Mon, 04 Jul 2016 17:10:13 +0000 Received: from mail-oi0-x236.google.com ([2607:f8b0:4003:c06::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bK7Nq-0003hD-FC for pgsql-performance@postgresql.org; Mon, 04 Jul 2016 17:10:12 +0000 Received: by mail-oi0-x236.google.com with SMTP id f189so201086776oig.3 for ; Mon, 04 Jul 2016 10:10:10 -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=0/Kkqz2U8JKND7HSlBk8D8cAeDLDb62BXo0mjZRWwco=; b=s6h1PupVFImpsJXIZir0vJPIvzFWZXYL8r0i7E95s+cRVsE3E4ZVVuZHdbD6bjOmn/ 9e1notVUERleXyrivoRdnqidPJy6HJjluBupOgV/JUZOY++OuoEsxNQwqJKn+XmKi1yC UMO5SN98u9ZiXDlKVBRhXEJU+L7nilOaEao3Hp4fVubtfFriTH6OwtDFmLBF6JKZI+7C D/xM3kyvJQpmAigc3AtnsNf4o9aGYjEFYVJLBWywZuVFEJiCTGieK9r+h2xlXl77hAeA I94cDJuNemPX8eaud+5MgsSVPxq7aS7yYxO7V2hTGC1ATjW84JVlPANeHqATgabZc2t4 BOXg== 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=0/Kkqz2U8JKND7HSlBk8D8cAeDLDb62BXo0mjZRWwco=; b=GLvUeWFi3nCociJu63F1+8G/yv4qja3yCy2MgddCc2LbfqU+Emw7kn2pBSwGVphrLH Jba/sx9pMouNvsmlD/3VkF9rhjcRswlVqmpp44++UvoiEv3Q0px1d79Qh20krw0Z+9XK epNu7OxkiK2naP8Pvwvqi574xKLV5g5nzT/HZUHTthTKd7xPIoHrn4etAEifNrwZvE8O U0mgU08/CVx8pA4Mz4jOE8b8bo0FzdLKrz2SgHf9SjnIGp5OXCg4S+1kBmwD9vkHMZlK LvByfy9HHMpVuAq0jrGXfhB/MQslUYFsZnfpnZhYrKZWHDQLgcwXOwNSzIyL7w0k6dy0 99XA== X-Gm-Message-State: ALyK8tL7/Tt4NfdtiR0qdJGoIZOuBZCnSBkXbnWjzuVGgzu+b/bQxBsjiBvVb9XQQa7y4u00BNtbxzGkWQVGGQ== X-Received: by 10.202.244.4 with SMTP id s4mr7617997oih.123.1467652209827; Mon, 04 Jul 2016 10:10:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.245.234 with HTTP; Mon, 4 Jul 2016 10:10:09 -0700 (PDT) In-Reply-To: <20160704170458.GA425951@alvherre.pgsql> References: <20160704170458.GA425951@alvherre.pgsql> From: Kouber Saparev Date: Mon, 4 Jul 2016 20:10:09 +0300 Message-ID: Subject: Re: DELETE takes too much memory To: Alvaro Herrera Cc: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=001a1134f8ac9ee3ad0536d26805 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 --001a1134f8ac9ee3ad0536d26805 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. 2016-07-04 20:04 GMT+03:00 Alvaro Herrera : > Kouber Saparev wrote: > > I tried to DELETE about 7 million rows at once, and the query went up t= o > > 15% of the RAM (120 GB in total), which pushed some indexes out and the > > server load went up to 250, so I had to kill the query. > > > > The involved table does not have neither foreign keys referring to othe= r > > tables, nor other tables refer to it. The size of the table itself is 1= 9 > GB > > (15% of 120 GB). So why the DELETE tried to put the entire table in > memory, > > or what did it do to take so much memory? > > Are there triggers in the table? Deferred triggers in particular can > use memory. > > -- > =C3=81lvaro Herrera http://www.2ndQuadrant.com/ > PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services > --001a1134f8ac9ee3ad0536d26805 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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.

= 2016-07-04 20:04 GMT+03:00 Alvaro Herrera <alvherre@2ndquadrant.com= >:
Kouber = Saparev wrote:
> I tried to DELETE about 7 million rows at once, and the query went up = to
> 15% of the RAM (120 GB in total), which pushed some indexes out and th= e
> server load went up to 250, so I had to kill the query.
>
> The involved table does not have neither foreign keys referring to oth= er
> tables, nor other tables refer to it. The size of the table itself is = 19 GB
> (15% of 120 GB). So why the DELETE tried to put the entire table in me= mory,
> or what did it do to take so much memory?

Are there triggers in the table?=C2=A0 Deferred triggers in particul= ar can
use memory.

--
=C3=81lvaro Herrera=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--001a1134f8ac9ee3ad0536d26805--