counting rows

From: pgboy(at)guthrie(dot)charm(dot)net
To: pgsql-admin(at)postgresql(dot)org
Subject: counting rows
Date: 2003-08-06 13:25:18
Message-ID: Pine.LNX.4.50.0308060920070.7263-100000@guthrie.charm.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

i need to get a row count on a large table. it appears that
select count(*) from <table>;
always does a table scan, whether i have an index or not, and that is too
slow.

so i found this:
select reltuples from pg_class where relname = '<table>';

this is nice and fast, but not all that accurate at any given time. but, i
*did* notice that it is pretty accurate if i run analyze just before.

so, i am wondering if analyze also does a table scan, in which case i am
back to where i started. it *seems* to run fairly quickly, even on a large
table, but i am just wall-clocking all of this.

or any other ideas on counting rows are welcome.

thanks.
pg

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Andreas Schmitz 2003-08-06 13:50:52 Re: Postgresql slow on XEON 2.4ghz/1gb ram
Previous Message Wilson A. Galafassi Jr. 2003-08-06 13:20:34 Postgresql slow on XEON 2.4ghz/1gb ram