Re: Long count(*) time

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: David Monarchi <david(dot)e(dot)monarchi(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Long count(*) time
Date: 2007-09-25 21:51:52
Message-ID: 721682.74917.qm@web31809.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

--- David Monarchi <david(dot)e(dot)monarchi(at)gmail(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Phillip Smith 2007-09-25 23:58:13 Re: pg_hba.conf not right
Previous Message Jon Sime 2007-09-25 20:35:30 Re: Long count(*) time