Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1E6C81337C13 for ; Fri, 4 Feb 2011 15:18:40 -0400 (AST) 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 40653-02 for ; Fri, 4 Feb 2011 19:18:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.peak6.com (smtp.optionshouse.com [38.98.137.6]) by mail.postgresql.org (Postfix) with ESMTP id 09B5D1337BC8 for ; Fri, 4 Feb 2011 15:14:15 -0400 (AST) X-AuditID: 0a64cb1e-b7c55ae000000bfb-fa-4d4c50079eee Message-ID: <4D4C5006.7030805@peak6.com> Date: Fri, 4 Feb 2011 13:14:14 -0600 From: Shaun Thomas Reply-To: sthomas@peak6.com Organization: Peak6 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100720 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 To: Scott Marlowe CC: Greg Smith , felix , "pgsql-performance@postgresql.org" Subject: Re: Really really slow select count(*) References: <4D4C138C.7010304@2ndquadrant.com> <4D4C1555.40209@peak6.com> <4D4C2AC3.5020804@peak6.com> <4D4C3BCA.5010808@peak6.com> <4D4C478D.9070909@2ndquadrant.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Brightmail-Tracker: AAAAAQAAAZE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/213 X-Sequence-Number: 42351 On 02/04/2011 01:01 PM, Scott Marlowe wrote: > begin; > select * into temporaryholdingtable order by somefield; > truncate oldtable; > insert into oldtables select * from temporaryholdingtable; > commit; That's usually how I do it, except for larger tables, I also throw in a DROP INDEX for all the indexes on the table before the insert, and CREATE INDEX statements afterwards. Which actually brings up a question I've been wondering to myself that I may submit to [HACKERS]: Can we add a a parallel option to the reindexdb command? We added one to pg_restore, so we already know it works. I have a bunch of scripts that get all the indexes in the database and order them by size (so they're distributed evenly), round-robin them into separate REINDEX sql files, and launches them all in parallel depending on how many threads you want, but that's so hacky I feel dirty every time I use it. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email_disclaimer.php for terms and conditions related to this email