X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9DE359FA5BE for ; Thu, 15 Jun 2006 14:18:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 23319-02 for ; Thu, 15 Jun 2006 14:18:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 6F9409FA13E for ; Thu, 15 Jun 2006 14:18:07 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k5FHHk901846; Thu, 15 Jun 2006 13:17:46 -0400 (EDT) From: Bruce Momjian Message-Id: <200606151717.k5FHHk901846@candle.pha.pa.us> Subject: Re: Postgres consuming way too much memory??? In-Reply-To: <28419.1150386248@sss.pgh.pa.us> To: Tom Lane Date: Thu, 15 Jun 2006 13:17:46 -0400 (EDT) CC: jody brownell , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/315 X-Sequence-Number: 19672 Added to TODO: > o Fix memory leak from exceptions > > http://archives.postgresql.org/pgsql-performance/2006-06/msg0$ --------------------------------------------------------------------------- Tom Lane wrote: > "jody brownell" writes: > > BEGIN > > INSERT into attacker_target_link (attacker_id, target_id) values (p_attacker, v_target); > > v_returns_size := v_returns_size + 1; > > v_returns[v_returns_size] := v_target; > > > EXCEPTION WHEN unique_violation THEN > > -- do nothing... app cache may be out of date. > > END; > > Hmm. There is a known problem that plpgsql leaks some memory when > catching an exception: > http://archives.postgresql.org/pgsql-hackers/2006-02/msg00885.php > > So if your problem case involves a whole lot of duplicates then that > could explain the initial bloat. However, AFAIK that leakage is in > a transaction-local memory context, so the space ought to be freed at > transaction end. And Linux's malloc does know about giving space back > to the kernel (unlike some platforms). So I'm not sure why you're > seeing persistent bloat. > > Can you rewrite the function to not use an EXCEPTION block (perhaps > a separate SELECT probe for each row --- note this won't be reliable > if there are concurrent processes making insertions)? If so, does > that fix the problem? > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > -- Bruce Momjian http://candle.pha.pa.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +