Re: Psql command for rowcount

From: Chander Ganesan <chander(at)otg-nc(dot)com>
To: David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>
Cc: "Markova, Nina" <nmarkova(at)nrcan(dot)gc(dot)ca>, pgsql-general(at)postgresql(dot)org
Subject: Re: Psql command for rowcount
Date: 2008-09-11 21:47:02
Message-ID: 48C991D6.6070708@otg-nc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Wilson wrote:
> On Thu, Sep 11, 2008 at 3:19 PM, Markova, Nina <nmarkova(at)nrcan(dot)gc(dot)ca> wrote:
>
>> Is there a psql or other command that I can use to list tables and their
>> rows? All I found is this:
>> http://archives.postgresql.org/pgsql-hackers/2004-09/msg00876.php
>>
>
> select tablename,reltuples from pg_class inner join pg_tables on
> tablename=relname where tablename !~* 'pg_*' and tablename !~*
> 'sql_*';
>
> Remember that the reltuples count is an *estimate* and won't be 100%
> an accurate- only a count(*) will get you that.
>
And it may not be accurate at all unless you or autovacuum has done a
recent ANALYZE ... Also keep in mind that in PostgreSQL, a count(*)
will actually do a table scan, and could be time (and I/O) consuming if
you are looking at a large table.

--
Chander Ganesan
Open Technology Group, Inc.
One Copley Parkway, Suite 210
Morrisville, NC 27560
919-463-0999/877-258-8987
http://www.otg-nc.com
Ask me about Expert PostgreSQL and PostGIS training - delivered worldwide.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bill Todd 2008-09-11 22:09:27 Re: Windows ODBC Driver
Previous Message Scott Marlowe 2008-09-11 21:35:10 Re: connection timeouts and "killing" users