counting rows - Mailing list pgsql-admin

From pgboy@guthrie.charm.net
Subject counting rows
Date
Msg-id Pine.LNX.4.50.0308060920070.7263-100000@guthrie.charm.net
Whole thread Raw
Responses Re: counting rows  (greg@turnstep.com)
Re: counting rows  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-admin by date:

Previous
From: "Borgoglio, Francesco"
Date:
Subject: Blobs in database
Next
From: "Wilson A. Galafassi Jr."
Date:
Subject: Postgresql slow on XEON 2.4ghz/1gb ram