Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2C5256327FF for ; Mon, 26 Jul 2010 06:15:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 51683-01 for ; Mon, 26 Jul 2010 09:15:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id CB92A6327BE for ; Mon, 26 Jul 2010 06:15:22 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 8D3279F93; Mon, 26 Jul 2010 17:15:17 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 072EEAE400; Mon, 26 Jul 2010 17:15:13 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lKPp+nqWBUtd; Mon, 26 Jul 2010 17:15:07 +0800 (WST) Received: from [10.1.1.6] (124-168-255-56.dyn.iinet.net.au [124.168.255.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 7F101AFACF; Mon, 26 Jul 2010 17:15:07 +0800 (WST) Message-ID: <4C4D5220.9010101@postnewspapers.com.au> Date: Mon, 26 Jul 2010 17:15:12 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: =?UTF-8?B?UGlvdHIgR2FzaWTFgm8=?= CC: pgsql-performance@postgresql.org Subject: Re: Big difference in time returned by EXPLAIN ANALYZE SELECT ... AND SELECT ... References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 201007/372 X-Sequence-Number: 39761 On 26/07/10 16:35, Piotr Gasidło wrote: > Hello, > > I've found strange problem in my database (8.4.4, but also 9.0beta3, > default postgresql.conf, shared_buffers raised to 256MB). > > EXPLAIN ANALYZE SELECT ... > Total runtime: 4.782 ms > Time: 25,970 ms > > SELECT ... > ... > (21 rows) > > Time: 23,042 ms > > Test done in psql connected by socket to server (same host, using > \timing to get runtime). > > Does big difference in "Total runtime" and "Time" is normal? Given that EXPLAIN ANALYZE doesn't transfer large rowsets to the client, it can't really be time taken to transfer the data, which is the usual difference between 'explain analyze' timings and psql client-side timings. Given that, I'm wondering if the difference in this case is planning time. I can't really imagine the query planner taking 20 seconds (!!) to run, though, no matter how horrifyingly complicated the query and table structure were, unless there was something going wrong. Another possibility, then, is that for some reason queries are being delayed from starting or delayed before results are being returned, so the server completes them in a short amount of time but it takes a while for psql to find out they're finished. In your position, at this point I'd be doing things like hooking a debugger up to the postgres backend and interrupting its execution periodically to see what it's up to while this query runs. I'd also be using wireshark to look at network activity to see if there were any clues there. I'd be using "top", "vmstat" and "iostat" to examine system-level load if it was practical to leave the system otherwise idle, so I could see if CPU/memory/disk were in demand, and for how long. -- Craig Ringer