Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 84C0E1337B47 for ; Tue, 29 Mar 2011 13:38:40 -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 11492-04 for ; Tue, 29 Mar 2011 16:38:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from web39705.mail.mud.yahoo.com (web39705.mail.mud.yahoo.com [209.191.106.51]) by mail.postgresql.org (Postfix) with SMTP id 59954133655C for ; Tue, 29 Mar 2011 13:38:21 -0300 (ADT) Received: (qmail 38207 invoked by uid 60001); 29 Mar 2011 16:38:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1301416700; bh=1rjNqi4DDBAsVRXAoTSWx/DqnhcoRaR6boByNapZHnM=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=DHivpApe9WEPtMmM9jhG6RRV456xc9bkpOEQzhazyU/aDafJfQSmyOotkAHymTliEnPIKpmOnbzADxyRt7el/pBprVDTcWc/v8yOjNftGCt8Zkb+gTuiIixQBwCSAh88W27nY4xiKKeLvqnf5U63UzTF8wOInIi6EDn/6yocn8E= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=D+pZJ479y//tb8V4hKRcst1C4QO56wB5IXnxXTQUE6gtLjGpR6gTQdETWYz9jU+Oljp/UnYV1S1nr0johQ99eqIM1DlhSyV3bQcoANQJUvTUQWvqv54QgYhK5Ea9sxqx07pUuR1GnTqsqiFpBVTUURXbWIRD/nwYGOvWplMqDGg=; Message-ID: <967268.12623.qm@web39705.mail.mud.yahoo.com> X-YMail-OSG: qtKEozsVM1kBI712OW3bdmC6vG9uD.h78gqBi1dL9WCT4Ol sAdscb376D1ww1a9Tsz0ZRzG7Q68_PActbAg.F7ugEHG9GiUUe.yvUtQfF7. mb5hnotzuv.4j1CMAhlswT4rwyhj_GX9kOXyO.ShqzwhfZX1ewDsK7aX72UE kcOg5Tkj4uQmY9GQmWs0l.E7LKZXGN0qosq.4ULq0EookKp9zgK_ItZkNeZz QT6KkOwziLg2ybtilipdTlu11OSU3mb0po4UdYXZ1fLvZiraik74tRVygEXE wg4SVgnog5L9wM2dyGji7YtQosjg4h374FbLXcxfmYHAQkLJYTX3BKgfzuGC Fo51GlL6kX7tBW77.bC5_q7PA9q_17IT57YgUfhfTTeqnCUNF6AJvJuE- Received: from [64.126.29.122] by web39705.mail.mud.yahoo.com via HTTP; Tue, 29 Mar 2011 09:38:20 PDT X-Mailer: YahooMailClassic/12.0.2 YahooMailWebService/0.8.109.295617 Date: Tue, 29 Mar 2011 09:38:20 -0700 (PDT) From: Bob Lunney Subject: Re: full vacuum of a very large table To: pgsql-admin@postgresql.org, Nic Chidu In-Reply-To: <1301414165.2351.1435136873@webmail.messagingengine.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.908 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RFC_ABUSE_POST=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/262 X-Sequence-Number: 37134 =0A--- On Tue, 3/29/11, Nic Chidu wrote:=0A=0A> From: Nic C= hidu =0A> Subject: [ADMIN] full vacuum of a very large table= =0A> To: pgsql-admin@postgresql.org=0A> Date: Tuesday, March 29, 2011, 11:5= 6 AM=0A> Got a situation where a 130 mil rows=0A> (137GB) table needs to be= brought down in size to=A0 10=0A> mil records (most recent)=0A> with the l= east amount of downtime. =0A> =0A> Doing a full vacuum would be faster on:= =0A> - 120 mil rows deleted and 10 mil active (delete most of=0A> them the= n full vacuum)=0A> - 10 mil deleted and 120 mil active. (delete small batc= hes=0A> and full vacuum after each delete). =0A> =0A> Any other suggestions= ?=0A> =0A> Thanks,=0A> =0A> Nic=0A> =0A> -- =0A=0ANic,=0A=0ASince you know = the where clause to delete the 120 mil rows why not use the converse of tha= t to select the 10 mil rows to retain into another table, then drop the ori= ginal table? No vacuum required!=0A=0ABe sure to use the "create table as = select..." syntax to avoid WAL during creation of the new table, and use a = transaction to drop the original table and rename the new one. That way us= ers will be querying the original table right up until the switch over, whe= n they will start using the new table. =0A=0AForeign keys and other constr= aints may complicate things a bit, so check those out first. Also, don't f= orget to index and analyze the new table before the switch over.=0A=0AGood = luck!=0A=0ABob Lunney=0A=0A=0A