Re: select count(*) performance - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: select count(*) performance
Date
Msg-id b42b73150708100444x76d8881fkca87772272859d8a@mail.gmail.com
Whole thread Raw
In response to select count(*) performance  (runic <runic@gmx.de>)
List pgsql-performance
On 8/8/07, runic <runic@gmx.de> wrote:
> Hello Group,
>
> I'm new in PostgreSQL Business, therefore please forgive me a "newbie"
> Question. I have a table with ca. 1.250.000 Records. When I execute
> a "select count (*) from table" (with pgAdmin III)  it takes about 40
> secs.
> I think that takes much to long. Can you please give me hints, where
> I can search for Improvements?

This is a FAQ.  This operation is optimized in some other database
engines but not in PostgreSQL due to way the locking engine works.
There are many workarounds, maybe the easiest is to get an approximate
count using
select reltuples from pg_class where relname = 'your_table' and relkind = 'r';

merlin

pgsql-performance by date:

Previous
From: "Merlin Moncure"
Date:
Subject: Re: Dell Hardware Recommendations
Next
From: Brian Hurt
Date:
Subject: Re: select count(*) performance