Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 85D359FBB41 for ; Thu, 22 Mar 2007 11:52:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 30755-06 for ; Thu, 22 Mar 2007 11:52:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exprod6og55.obsmtp.com (exprod6og55.obsmtp.com [64.18.1.191]) by postgresql.org (Postfix) with SMTP id CD8B59FBB16 for ; Thu, 22 Mar 2007 11:52:31 -0300 (ADT) Received: from source ([63.240.6.47]) (using TLSv1) by exprod6ob55.postini.com ([64.18.5.12]) with SMTP; Thu, 22 Mar 2007 07:52:26 PDT Received: from 172.16.1.239 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Thu, 22 Mar 2007 10:46:29 -0400 X-Server-Uuid: 0764DD54-627B-4C45-B37D-789FBDEDA467 Received: from MI8NYCMAIL08.Mi8.com ([172.16.1.165]) by d01smtp06.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 22 Mar 2007 10:46:27 -0400 Received: from 24.23.197.133 ([24.23.197.133]) by MI8NYCMAIL08.Mi8.com ( [172.16.1.190]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Thu, 22 Mar 2007 14:46:26 +0000 User-Agent: Microsoft-Entourage/11.3.3.061214 Date: Thu, 22 Mar 2007 07:46:26 -0700 Subject: Re: Performance of count(*) From: "Luke Lonergan" To: "Andreas Tille" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Performance of count(*) Thread-Index: AcdskN4PHFbQKNiEEdujTgAX8s8Cag== In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 22 Mar 2007 14:46:27.0198 (UTC) FILETIME=[DEC659E0:01C76C90] X-WSS-ID: 6A1C49383ZW10549865-20-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/325 X-Sequence-Number: 23730 Andreas, On 3/22/07 4:48 AM, "Andreas Tille" wrote: > Well, to be honest I'm not really interested in the performance of > count(*). I was just discussing general performance issues on the > phone line and when my colleague asked me about the size of the > database he just wonderd why this takes so long for a job his > MS-SQL server is much faster. So in principle I was just asking > a first question that is easy to ask. Perhaps I come up with > more difficult optimisation questions. This may be the clue you needed - in Postgres SELECT COUNT(*) is an approximate way to measure the speed of your disk setup (up to about 1,200MB/s). Given that you are having performance problems, it may be that your disk layout is either: - slow by design - malfunctioning If this is the case, then any of your queries that require a full table scan will be affected. You should check your sequential disk performance using the following: time bash -c "dd if=/dev/zero of=/your_file_system/bigfile bs=8k count=(your_memory_size_in_KB*2/8) && sync" time dd if=/your_file_system/bigfile of=/dev/null bs=8k Report those times here and we can help you with it. - Luke