Re: Performance question 83 GB Table 150 million rows, distinct select

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Alan Hodgson <ahodgson(at)simkin(dot)ca>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance question 83 GB Table 150 million rows, distinct select
Date: 2011-11-16 23:32:09
Message-ID: CAOR=d=3OLUfQgoTrMMAoAo-Hq2z13TpzTP7VuXcq6pvHFpKsCg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Nov 16, 2011 at 4:27 PM, Alan Hodgson <ahodgson(at)simkin(dot)ca> wrote:
> 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.

Agreed. We'd need to know how selective that where clause is. Seeing
some forced index usage versus regular explain analyze would be
useful. i.e.

set enable_seqscan=off;
explain analyze select ...

> Also, the normal approach to making large statistics tables more manageable is
> to partition them by date range.

If the OP's considering partitioning, they should really consider
upgrading to 9.1 which has much better performance of things like
aggregates against partition tables.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Samuel Gendler 2011-11-16 23:52:35 Re: Performance question 83 GB Table 150 million rows, distinct select
Previous Message Alan Hodgson 2011-11-16 23:27:57 Re: Performance question 83 GB Table 150 million rows, distinct select