Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 03A33133740B for ; Wed, 13 Oct 2010 10:49:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65463-05 for ; Wed, 13 Oct 2010 13:49:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id D4A5C1337B69 for ; Wed, 13 Oct 2010 10:49:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o9DDnCVH024769; Wed, 13 Oct 2010 09:49:12 -0400 (EDT) To: Neil Whelchel cc: pgsql-performance@postgresql.org Subject: Re: Slow count(*) again... In-reply-to: <201010122347.20542.neil.whelchel@gmail.com> References: <201010091626.18636.neil.whelchel@gmail.com> <4CB2410C.6010603@postnewspapers.com.au> <201010102115.58729.neil.whelchel@gmail.com> <201010122347.20542.neil.whelchel@gmail.com> Comments: In-reply-to Neil Whelchel message dated "Tue, 12 Oct 2010 23:47:19 -0700" Date: Wed, 13 Oct 2010 09:49:12 -0400 Message-ID: <24768.1286977752@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/212 X-Sequence-Number: 40631 Neil Whelchel writes: > Insert the data into one table: > crash:~# time psql -U test test -q < log.sql > real 679m43.678s > user 1m4.948s > sys 13m1.893s > crash:~# echo 3 > /proc/sys/vm/drop_caches > crash:~# time psql -U test test -c "SELECT count(*) FROM log;" > count > ---------- > 10050886 > (1 row) > real 0m11.812s > user 0m0.000s > sys 0m0.004s > crash:~# time psql -U test test -c "SELECT count(*) FROM log;" > count > ---------- > 10050886 > (1 row) > real 0m3.737s > user 0m0.000s > sys 0m0.000s > As can be seen here, the cache helps.. That's probably got little to do with caching and everything to do with setting hint bits on the first SELECT pass. I concur with Mark's question about whether your UPDATE pushed the table size across the limit of what would fit in RAM. regards, tom lane