Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C158F633267 for ; Fri, 7 May 2010 10:42:27 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 18394-02 for ; Fri, 7 May 2010 13:42:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh4.mail.rice.edu (mh4.mail.rice.edu [128.42.199.11]) by mail.postgresql.org (Postfix) with ESMTP id 9FC70632F5F for ; Fri, 7 May 2010 10:42:20 -0300 (ADT) Received: from mh4.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh4.mail.rice.edu (Postfix) with ESMTP id BE9BF37001D; Fri, 7 May 2010 08:42:17 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.0 at mh4.mail.rice.edu Received: from mh4.mail.rice.edu ([127.0.0.1]) by mh4.mail.rice.edu (mh4.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qFPH0rpQFhBk; Fri, 7 May 2010 08:42:16 -0500 (CDT) Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh4.mail.rice.edu (Postfix) with ESMTP id 9EEBA37000A; Fri, 7 May 2010 08:42:16 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 763642D5AB; Fri, 7 May 2010 08:42:16 -0500 (CDT) Date: Fri, 7 May 2010 08:42:15 -0500 From: Kenneth Marshall To: Mark Stosberg Cc: pgsql-performance@postgresql.org Subject: Re: debugging handle exhaustion and 15 min/ 5mil row delete Message-ID: <20100507134215.GD18848@aart.is.rice.edu> References: <20100507093742.20c715b1@summersault.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100507093742.20c715b1@summersault.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/20 X-Sequence-Number: 38604 On Fri, May 07, 2010 at 09:37:42AM -0400, Mark Stosberg wrote: > > Hello, > > We've been a satified user of PostgreSQL for several years, and use it > to power a national pet adoption website: http://www.adoptapet.com/ > > Recently we've had a regularly-timed middle-of-the-night problem where > database handles are exhausted for a very brief period. > > In tracking it down, I have found that the event seems to correspond to > a time when a cron script is deleting from a large logging table, but > I'm not certain if this is the cause or a correlation. > > We are deleting about 5 million rows from a time-based logging table > that is replicated by Slony. We are currently using a single delete > statement, which takes about 15 minutes to run. There is no RI on the > table, but the use of Slony means that a trigger call and action is made > for every row deleted, which causes a corresponding insertion in another > table so the deletion can be replicated to the slave. > > My questions: > > - Could this kind of activity lead to an upward spiral in database > handle usage? Yes. > > - Would it be advisable to use several small DELETE statements instead, > to delete rows in batches of 1,000. We could use the recipe for this > that was posted earlier to this list: Yes, that is the method we use in several cases to avoid this behavior. Deletion is a more intensive process in PostgreSQL, so batching it will keep from dragging down other queries which results in your out-of-handles error. Regards, Ken