Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4D8FB1857D28 for ; Wed, 16 Nov 2011 22:11:42 -0400 (AST) 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 67556-05 for ; Thu, 17 Nov 2011 02:11:36 +0000 (UTC) Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 5FE851857D27 for ; Wed, 16 Nov 2011 22:11:34 -0400 (AST) Received: from 97-64-237-59.client.mchsi.com ([97.64.237.59] helo=marajade.localdomain) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQrRt-0005pH-SF for pgsql-performance@postgresql.org; Thu, 17 Nov 2011 02:11:34 +0000 Received: from [192.168.1.116] (50-83-220-125.client.mchsi.com [50.83.220.125]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id F07284699B; Wed, 16 Nov 2011 20:11:19 -0600 (CST) Message-ID: <4EC46D46.5050608@squeakycode.net> Date: Wed, 16 Nov 2011 20:11:18 -0600 From: Andy Colson User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110903 Lightning/1.0b2 Thunderbird/3.1.13 MIME-Version: 1.0 To: Tory M Blue CC: pgsql-performance@postgresql.org Subject: Re: Performance question 83 GB Table 150 million rows, distinct select References: 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.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/207 X-Sequence-Number: 45718 On 11/16/2011 04:53 PM, Tory M Blue wrote: > Linux F12 64bit > Postgres 8.4.4 > 16 proc / 32GB > 8 disk 15KRPM SAS/Raid 5 (I know!) > > > shared_buffers = 6000MB > #temp_buffers = 8MB > max_prepared_transactions = 0 > work_mem = 250MB > maintenance_work_mem = 1000MB > > > > > > We now have about 180mill records in that table. The database size is > about 580GB and the userstats table which is the biggest one and the > one we query the most is 83GB. > > Just a basic query takes 4 minutes: > > For e.g. select count(distinct uid) from userstats where log_date>'11/7/2011' > How'd you feel about keeping a monthly summary table? Update it daily, with only a days worth of stats, then you could query the summary table much faster. That's what I do for my website stats. I log details for a month, then summarize everything into a summary table, and blow away the details. You wouldn't have to delete the details if you wanted them, just keeping the summary table updated would be enough. -Andy