Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id F0B83F497BC for ; Mon, 27 Feb 2012 10:54:33 -0400 (AST) Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S21y7-000701-Kx for pgsql-performance@postgresql.org; Mon, 27 Feb 2012 14:54:32 +0000 X-Originating-IP: 217.70.178.129 Received: from mfilter12-d.gandi.net (mfilter12-d.gandi.net [217.70.178.129]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 24A241720AB; Mon, 27 Feb 2012 15:54:04 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter12-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter12-d.gandi.net (mfilter12-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id nkxnMu8kUEe4; Mon, 27 Feb 2012 15:54:02 +0100 (CET) X-Originating-IP: 98.27.54.176 Received: from [192.168.10.146] (cpe-098-027-054-176.nc.res.rr.com [98.27.54.176]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id F2EC617209C; Mon, 27 Feb 2012 15:54:01 +0100 (CET) Message-ID: <4F4B9907.60008@dunslane.net> Date: Mon, 27 Feb 2012 09:53:59 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0 MIME-Version: 1.0 To: sthomas@peak6.com CC: "Reuven M. Lerner" , pgsql-performance@postgresql.org Subject: Re: Very long deletion time on a 200 GB database References: <4F45FB55.1020600@lerner.co.il> <4F47C6C4.6030102@pinpointresearch.com> <4F4B39EF.2080004@lerner.co.il> <4F4B9721.6050808@peak6.com> In-Reply-To: <4F4B9721.6050808@peak6.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/229 X-Sequence-Number: 46401 On 02/27/2012 09:45 AM, Shaun Thomas wrote: > On 02/27/2012 02:08 AM, Reuven M. Lerner wrote: > >> In the end, it was agreed that we could execute the deletes over >> time, deleting items in the background, or in parallel with the >> application's work. After all, if the disk is filling up at the rate >> of 2 GB/day, then so long as we delete 4 GB/day (which is pretty easy >> to do), we should be fine. > > Please tell me you understand deleting rows from a PostgreSQL database > doesn't work like this. :) The MVCC storage system means you'll > basically just be marking all those deleted rows as reusable, so your > database will stop growing, but you'll eventually want to purge all > the accumulated dead rows. > > One way to see how many there are is to use the pgstattuple contrib > module. You can just call it on the table name in question: > > SELECT * FROM pgstattuple('my_table'); > > You may find that after your deletes are done, you'll have a free_pct > of 80+%. In order to get rid of all that, you'll need to either run > CLUSTER on your table(s) or use the select->truncate->insert method > anyway. > If he has autovacuum on he could well be just fine with his proposed strategy. Or he could have tables partitioned by time and do the delete by just dropping partitions. There are numerous way he could get this to work. cheers andrew