Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 730DC2E004A for ; Wed, 14 May 2008 17:38:36 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30344-02 for ; Wed, 14 May 2008 17:38:24 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.155]) by developer.postgresql.org (Postfix) with ESMTP id 8FFD52E0086 for ; Wed, 14 May 2008 17:38:25 -0300 (ADT) Received: by fg-out-1718.google.com with SMTP id 16so87504fgg.23 for ; Wed, 14 May 2008 13:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=H2AkeNdtIzCm38N6D1XUEXMddHGHWZVNl6gMvW4mHsM=; b=IUbshcvneiQvnfHlGSdBqKy5dZ8pdv1UZGKEmMTmkc0IpoaihXHSutPZc8xKQAu5uW0CegUDsTcihRLivS9qUpwS3Hxg3O5VPRnBwW/CNud3rAcNW56VQwl99c7WTrkV+Gb5kVlSJzJPrj83C6RtZEpwrJxgxspq8R0e54x5yBk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ifM1lGiL4Sk0iPuzBko+WLYV4zuFqOrNDlPhyjSqWW/oDbuuhe0QZMo6TSzUGijiBiLxxW0KvNO1rWjQiMXBxAUYit1uwHMvDnyAgg2wIq9A6AJEh/t/F2C2P0IpzCLWaQxtnPJN06urWARQIIh8p+HKOOrI6Z58/sTGSUnW3H8= Received: by 10.82.127.14 with SMTP id z14mr236722buc.67.1210797503772; Wed, 14 May 2008 13:38:23 -0700 (PDT) Received: by 10.82.145.1 with HTTP; Wed, 14 May 2008 13:38:23 -0700 (PDT) Message-ID: Date: Wed, 14 May 2008 16:38:23 -0400 From: "Merlin Moncure" To: "Doug Eck" Subject: Re: I/O on select count(*) Cc: pgsql-performance@postgresql.org In-Reply-To: <920841.71690.qm@web44808.mail.sp1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <920841.71690.qm@web44808.mail.sp1.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/184 X-Sequence-Number: 30152 On Wed, May 14, 2008 at 4:09 PM, Doug Eck wrote: > I have a large table (~ 2B rows) that contains an indexed timestamp column. > I am attempting to run a query to determine the number of rows for a given > 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 unusual > 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 shows > mixed reads and writes in a ratio of about 1 block read to 5 blocks > written. We have determined that files in our data and log partitions are > being hit, but the file system itself is not growing during this time (it > appears to be writing over the same chunk of space over and over again). > Memory on the box is not being swapped while all of this is happening. I > would have guessed that a "select count(*)" would not require a bunch of > writes, and I can't begin to figure out why the number of blocks written are > so much higher than the blocks read. If I modify the where clause to only > count the rows for a given minute or two, I see the reads but I never see > the unusual write behavior. > > Any thoughts into what could be going on? Thanks in advance for your help. can you post the exact output of explain analyze? (or, at least, explain if the query takes too long) merlin