Re: Long count(*) time - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: Long count(*) time
Date
Msg-id 721682.74917.qm@web31809.mail.mud.yahoo.com
Whole thread Raw
In response to Long count(*) time  ("David Monarchi" <david.e.monarchi@gmail.com>)
List pgsql-novice
--- David Monarchi <david.e.monarchi@gmail.com> wrote:

> 70 seconds seems to be a long time for this kind of query.  Is this normal?

Do to the nature of PostgreSQL's MVCC system, all Count(*) operations with no where clauses will
trigger a full table scan.  You could possible shave off a some time if you perform a VACUUM FULL
on this table.  Vacuum full will recover all the space from dead tuples.  The end result is that
fewer pages left will require less time to scan.

However, if you have a good auto-vacuum policy implemented you can get a very close estimate of
the number of records in you table in much less time.  This link has a good example of how this is
done:
http://www.commandprompt.com/blogs/joshua_drake/2007/08/how_many_rows_do_i_have_anyway/

Regards,
Richard Broersma Jr.

pgsql-novice by date:

Previous
From: Jon Sime
Date:
Subject: Re: Long count(*) time
Next
From: Phillip Smith
Date:
Subject: Re: pg_hba.conf not right