Re: Really really slow select count(*)

From: Kenneth Marshall <ktm(at)rice(dot)edu>
To: felix <crucialfelix(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Really really slow select count(*)
Date: 2011-02-04 16:27:02
Message-ID: 20110204162702.GE1261@aart.is.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Feb 04, 2011 at 05:20:27PM +0100, felix wrote:
> reply was meant for the list
>
> ---------- Forwarded message ----------
> From: felix <crucialfelix(at)gmail(dot)com>
> Date: Fri, Feb 4, 2011 at 4:39 PM
> Subject: Re: [PERFORM] Really really slow select count(*)
> To: Greg Smith <greg(at)2ndquadrant(dot)com>
>
>
>
>
> On Fri, Feb 4, 2011 at 3:56 PM, Greg Smith <greg(at)2ndquadrant(dot)com> wrote:
>
> > PostgreSQL version? If you're running on 8.3 or earlier, I would be
> > suspicous that your Free Space Map has been overrun.
> >
>
> 8.3
>
>
>
> >
> > What you are seeing is that the table itself is much larger on disk than
> > it's supposed to be.
> >
>
> which part of the explain told you that ?
>
> > shaun thomas
>
> SELECT relpages*8/1024 FROM pg_class
> WHERE relname='fastadder_fastadderstatus';
>
> 458MB
>
> way too big. build_cache is text between 500-1k chars
>

As has been suggested, you really need to CLUSTER the table
to remove dead rows. VACUUM will not do that, VACUUM FULL will
but will take a full table lock and then you would need to
REINDEX to fix index bloat. CLUSTER will do this in one shot.
You almost certainly have your free space map way too small,
which is how you bloated in the first place.

Cheers,
Ken

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Shaun Thomas 2011-02-04 16:34:57 Re: Really really slow select count(*)
Previous Message felix 2011-02-04 16:20:27 Really really slow select count(*)