Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D96E61F34DC5 for ; Wed, 16 Nov 2011 19:28:19 -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 97036-04 for ; Wed, 16 Nov 2011 23:28:14 +0000 (UTC) Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 104551F34DC4 for ; Wed, 16 Nov 2011 19:28:13 -0400 (AST) Received: from zeus.simkin.ca ([72.51.27.124]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQoto-0002rv-B4 for pgsql-performance@postgresql.org; Wed, 16 Nov 2011 23:28:13 +0000 Received: from pc-1072.reinvent.com (vpn.reinvent.com [72.51.27.50]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by zeus.simkin.ca (Postfix) with ESMTPSA id 7086227070C for ; Wed, 16 Nov 2011 15:27:58 -0800 (PST) From: Alan Hodgson Organization: Simkin Network Consulting To: pgsql-performance@postgresql.org Subject: Re: Performance question 83 GB Table 150 million rows, distinct select Date: Wed, 16 Nov 2011 15:27:57 -0800 User-Agent: KMail/1.13.6 (Linux/2.6.38-12-generic; KDE/4.6.5; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201111161527.57443.ahodgson@simkin.ca> 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/200 X-Sequence-Number: 45711 On November 16, 2011 02:53:17 PM Tory M Blue wrote: > 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' > > Just not sure if this is what to expect, however there are many other > DB's out there bigger than ours, so I'm curious what can I do? That query should use an index on log_date if one exists. Unless the planner thinks it would need to look at too much of the table. Also, the normal approach to making large statistics tables more manageable is to partition them by date range.