Re: I/O on select count(*)

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-performance(at)postgresql(dot)org>,"Doug Eck" <deck1(at)yahoo(dot)com>
Subject: Re: I/O on select count(*)
Date: 2008-05-14 22:11:21
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

>>> Doug Eck <deck1(at)yahoo(dot)com> wrote:

> I am attempting to run a query to determine the number of rows for a
> day using something like "select count(*) from tbl1 where ts between

> '2008-05-12 00:00:00.000' and '2008-05-12 23:59:59.999'". Explain
tells me
> that the query will be done using an index scan (as I would expect),
and I
> realize that it is going to take a while. My question concerns some
> I/O activity on the box (SUSE) when I run the query.
> For the first couple of minutes I see reads only. After that vmstat
> mixed reads and writes in a ratio of about 1 block read to 5 blocks

> Any thoughts into what could be going on? Thanks in advance for your

Odd as it may seem, a SELECT can cause a page to be rewritten.

If this is the first time that the rows are being read since they were
inserted (or since the database was loaded, including from backup), it
may be rewriting the rows to set hint bits, which can make subsequent
access faster.

The best solution may be to vacuum more often.


In response to


Browse pgsql-performance by date

  From Date Subject
Next Message Subbiah Stalin-XCGF84 2008-05-14 22:31:30 Update performance degrades over time
Previous Message Doug Eck 2008-05-14 21:23:49 Re: I/O on select count(*)