Re: PL/PgSQL for counting all rows in all tables.

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: "Ian FREISLICH" <if(at)hetzner(dot)co(dot)za>, "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/PgSQL for counting all rows in all tables.
Date: 2004-10-05 09:09:47
Message-ID: E7F85A1B5FF8D44C8A1AF6885BC9A0E43068F1@ratbert.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> -----Original Message-----
> From: pgsql-hackers-owner(at)postgresql(dot)org
> [mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Ian FREISLICH
> Sent: 05 October 2004 09:57
> To: Greg Sabino Mullane
> Cc: pgsql-hackers(at)postgresql(dot)org
> Subject: Re: [HACKERS] PL/PgSQL for counting all rows in all tables.
>
> "Greg Sabino Mullane" wrote:
> > ANALYZE;
> >
> > SELECT n.nspname, relname, reltuples
> > FROM pg_class c, pg_namespace n
> > WHERE c.relnamespace=n.oid
> > AND relkind='r'
> > AND NOT n.nspname ~ '^pg_'
> > ORDER BY 1,2;
>
> Maybe this gem should be passed onto the pgadmin folks. When
> you click on a table name in the interface it does what I can
> only presume is a count(*) from relation, which takes forever
> on enormous relations. It then claims this to be a row
> estimate anyway, so they could probably drop the analyze.

The 'Rows (counted)' value is taken from a count(*), but only if the
'Rows (estimated)' value (which comes from pg_class.reltuples, as above,
but without the costly analyze) is less than the cut-off value set in
the options dialogue. So, if you never want to wait for the exact row
count, just set the appropriate option to zero.

Regards Dave

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jason Tishler 2004-10-05 11:04:48 Re: cygwin test package available
Previous Message Ian FREISLICH 2004-10-05 08:57:26 Re: PL/PgSQL for counting all rows in all tables.