Re: Why Select Count(*) from table - took over 20 minutes?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Ozz Nixon <ozznixon(at)gmail(dot)com>
Cc: Diego Schulz <dschulz(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why Select Count(*) from table - took over 20 minutes?
Date: 2010-10-28 16:04:50
Message-ID: AANLkTin+XdaRAd+D-3D3Uvj5Kd0gr8TfYn2oTfOHcpiT@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 28, 2010 at 11:36 AM, Ozz Nixon <ozznixon(at)gmail(dot)com> wrote:
> How/where do I query this?
>
> My script does not need a 100% accurate count - just a recently valid count - so I can verify the web crawlers are still crawling :-)

you can do this:
select reltuples from pg_class where relname = 'your_table' and relkind = 'r';

that will give you accurate count as of the last analyze, which is
going to be driven by table usage and/or manual analyze. Probably
much better in your particular case is to do this:

select * from pg_stat_all_tables where relname = 'your_table';

and look at the n_tup_ins, del, etc. and make sure they are changing
(those numbers are reset when server resets, fyi).

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Verite 2010-10-28 16:04:54 Re: Should PQconsumeInput/PQisBusy be expensive to use?
Previous Message ludwig 2010-10-28 15:52:53 Re: PostGIS return multiple points