Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B08C49FB1CC for ; Mon, 27 Nov 2006 04:44:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 55023-03 for ; Mon, 27 Nov 2006 04:44:27 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id DD7AA9FA23F for ; Mon, 27 Nov 2006 04:44:29 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so920723ugf for ; Mon, 27 Nov 2006 00:44:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=EdSOPU/XihVpBFBjUHhlGGWqWFwah90DDYe2phinjSl4JsnnHOO2F8fAJxIY/OaGTJlIZwFs10ug5QOSDsxvrsglEfahDuKPog4GiyTMrvA4kDCcCGkWY1ikTUjQkPUHitnU0tIDWHJ2S8acBKy683fwjgVSmTk+Wd+yH390Q80= Received: by 10.78.41.3 with SMTP id o3mr12989793huo.1164617068393; Mon, 27 Nov 2006 00:44:28 -0800 (PST) Received: by 10.78.45.3 with HTTP; Mon, 27 Nov 2006 00:44:28 -0800 (PST) Message-ID: Date: Mon, 27 Nov 2006 14:14:28 +0530 From: "Merlin Moncure" To: arnaulist@andromeiberica.com Subject: Re: Massive delete of rows, how to proceed? Cc: pgsql-performance@postgresql.org In-Reply-To: <45673D56.10707@andromeiberica.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45673D56.10707@andromeiberica.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/240 X-Sequence-Number: 22010 On 11/25/06, Arnau wrote: > Hi all, > > I have a table with statistics with more than 15 million rows. I'd > like to delete the oldest statistics and this can be about 7 million > rows. Which method would you recommend me to do this? I'd be also > interested in calculate some kind of statistics about these deleted > rows, like how many rows have been deleted for date. I was thinking in > creating a function, any recommendations? a function, like an sql statement, operates in a single transaction and you are locking quite a few records in this operation. merlin's 3rd rule: long running transactions are (usually) evil. my gut says moving the keeper records to a swap table, dropping the main table, and swapping the tables back might be better. However, this kind of stuff can cause problems with logged in sessions because of plan issues, beware. do not write a function to delete records row by row unless you have exhausted all other courses of action. merlin