Thread: database row count
Dear Pg experts; I'd like to get a (rough) count of the numbers of rows across all tables in a given database. I understand that I could write a script to run count(*) on each table and then sum the counts. Is there an easier way, has someone already written this script? Much Thanks, Isaac Vetter
Attachment
On 30/01/2008 15:10, Isaac Vetter wrote the following: > Dear Pg experts; > > I'd like to get a (rough) count of the numbers of rows across all tables > in a given database. > > I understand that I could write a script to run count(*) on each table > and then sum the counts. Is there an easier way, has someone already > written this script? > > Much Thanks, > > Isaac Vetter How about SELECT relname, reltuples FROM pg_class WHERE relname IN (...);
On Jan 30, 2008 4:14 PM, Carol Cheung <cacheung@consumercontact.com> wrote: > How about > > SELECT relname, reltuples FROM pg_class WHERE relname IN (...); It should be noted that this will only work if the tables have been analyzed recently. -- Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324 EnterpriseDB Corporation | fax: 732.331.1301 499 Thornall Street, 2nd Floor | jonah.harris@enterprisedb.com Edison, NJ 08837 | http://www.enterprisedb.com/
Jonah H. Harris wrote: > On Jan 30, 2008 4:14 PM, Carol Cheung <cacheung@consumercontact.com> wrote: >> How about >> >> SELECT relname, reltuples FROM pg_class WHERE relname IN (...); > > It should be noted that this will only work if the tables have been > analyzed recently. Carol, Jonah; Much thanks for your answers; Isaac