Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5BD0E133655C for ; Tue, 29 Mar 2011 13:33:12 -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 86471-01 for ; Tue, 29 Mar 2011 16:33:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from polaris.pinpointresearch.com (cerberus.pinpointresearch.com [66.7.238.130]) by mail.postgresql.org (Postfix) with ESMTP id 3B9C31337B47 for ; Tue, 29 Mar 2011 13:33:04 -0300 (ADT) Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 0D119E00EC82; Tue, 29 Mar 2011 09:33:03 -0700 (PDT) Message-ID: <4D9209BF.4010104@pinpointresearch.com> Date: Tue, 29 Mar 2011 09:33:03 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: "Plugge, Joe R." CC: Nic Chidu , "pgsql-admin@postgresql.org" Subject: Re: full vacuum of a very large table References: <1301414165.2351.1435136873@webmail.messagingengine.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/261 X-Sequence-Number: 37133 On 03/29/2011 09:04 AM, Plugge, Joe R. wrote: > Personally, provided you have the room, I would build a new table off to the side and then migrate what you need to keep to the new table, when done, and satisfied that you have all of the candidate rows, ranem the original to table to "x_tablename" and rename the newly created table into place to take over.... if all is good .. simply drop the x_tablename table. This looks attractive but can cause issues if there are views, foreign-keys, etc. that depend on this table. > -----Original Message----- > From: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org] On Behalf Of Nic Chidu > Sent: Tuesday, March 29, 2011 10:56 AM > To: pgsql-admin@postgresql.org > Subject: [ADMIN] full vacuum of a very large table > > Got a situation where a 130 mil rows (137GB) table needs to be brought down in size to 10 mil records (most recent) with the least amount of downtime. > > Doing a full vacuum would be faster on: > - 120 mil rows deleted and 10 mil active (delete most of them then full vacuum) > - 10 mil deleted and 120 mil active. (delete small batches and full vacuum after each delete). > > Any other suggestions? > The phrase "most recent" leads me to believe this is time-based data. This might be a good time to partition your table to avoid this issue in the future. If you are clever about it (and try it out on a test environment), you might be able to create inherited tables off your main table and then move the "live" data from the parent to the child in unobtrusive sized chunks. When no live data remains in the parent table, truncate the parent table (only). Moving forward, set up your application/processes to put the data in to the appropriately sized (day?, week?, month? year?) child table. When the time comes, just archive and drop the child. Cheers, Steve