Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 151A2632F5F for ; Fri, 7 May 2010 10:44:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 73623-03 for ; Fri, 7 May 2010 13:44:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx3.uci.cu (ns3.uci.cu [200.55.140.180]) by mail.postgresql.org (Postfix) with SMTP id 4E98B63372C for ; Fri, 7 May 2010 10:44:15 -0300 (ADT) Received: (qmail 21777 invoked by uid 507); 7 May 2010 13:44:04 -0000 Received: from 10.0.0.184 by ns3.uci.cu (envelope-from , uid 501) with qmail-scanner-2.01st (avp: 5.0.2.0. spamassassin: 3.0.6. perlscan: 2.01st. Clear:RC:1(10.0.0.184):. Processed in 0.688769 secs); 07 May 2010 13:44:04 -0000 Received: from unknown (HELO ucimail3.uci.cu) (10.0.0.184) by 0 with SMTP; 7 May 2010 13:44:03 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by ucimail3.uci.cu (Postfix) with ESMTP id AB088B497A8; Fri, 7 May 2010 09:44:03 -0400 (CDT) X-Virus-Scanned: amavisd-new at uci.cu Received: from ucimail3.uci.cu ([127.0.0.1]) by localhost (ucimail3.uci.cu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z3sMFd8eeZ4H; Fri, 7 May 2010 09:44:02 -0400 (CDT) Received: from [127.0.0.1] (unknown [10.34.17.16]) by ucimail3.uci.cu (Postfix) with ESMTP id C6A90B4978B; Fri, 7 May 2010 09:44:02 -0400 (CDT) Message-ID: <4BE3C4C9.60601@uci.cu> Date: Fri, 07 May 2010 09:44:09 +0200 From: Marcos Ortiz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Mark Stosberg CC: pgsql-performance@postgresql.org Subject: Re: debugging handle exhaustion and 15 min/ 5mil row delete References: <20100507093742.20c715b1@summersault.com> In-Reply-To: <20100507093742.20c715b1@summersault.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.318 tagged_above=-10 required=5 tests=BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/21 X-Sequence-Number: 38605 El 07/05/2010 15:37, Mark Stosberg escribió: > 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? > > - 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: > > delete from table where pk in > (select pk from table where delete_condition limit X); > > Partitions seems attractive here, but aren't easy to use Slony. Perhaps > once we migrate to PostgreSQL 9.0 and the hot standby feature we can > consider that. > > Thanks for your help! > > Mark > > . . . . . . . . . . . . . . . . . . . . . . . . . . . > Mark Stosberg Principal Developer > mark@summersault.com Summersault, LLC > 765-939-9301 ext 202 database driven websites > . . . . . http://www.summersault.com/ . . . . . . . . > > > > You can use TRUNCATE instead DELETE. TRUNCATE is more efficient and faster that DELETE. Now, we need more information about your system to give you a certain solution: Are you using a RAID controller for you data? Do you have separated the xlog directory from the data directory? Which is your Operating System? Which is you architecture? Regards