Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 834106328C2 for ; Mon, 30 Nov 2009 05:01:09 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87397-04 for ; Mon, 30 Nov 2009 09:00:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id EBE9B632618 for ; Mon, 30 Nov 2009 05:00:39 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id A35EA1E0440; Mon, 30 Nov 2009 17:00:36 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QDwAjpEEQ2cl; Mon, 30 Nov 2009 17:00:32 +0800 (WST) Received: from [10.1.1.6] (203-206-43-189.dyn.iinet.net.au [203.206.43.189]) (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 6882E1E043F; Mon, 30 Nov 2009 17:00:32 +0800 (WST) Message-ID: <4B1389AE.2060305@postnewspapers.com.au> Date: Mon, 30 Nov 2009 17:00:30 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091121 Thunderbird/3.0 MIME-Version: 1.0 To: aymen marouani CC: pgsql-sql@postgresql.org Subject: Re: Profiling tool for postgres under win32 References: <4B0E6F03.4060902@postnewspapers.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/79 X-Sequence-Number: 33430 On 30/11/2009 4:42 PM, aymen marouani wrote: > Hi, > I'm sorry and thanks for the help, concerning your question : > > "Out of interest, how are you talking to PostgreSQL? Hand-written SQL via > JDBC? Hibernate / TopLink / some other ORM (possibly via JPA)?" > > I'm using JPA/Toplink to talk to the PostgresSQL, and I asked my > question about profiling because of a slow simple query > > "SELECT i FROM Item i" > > which takes 4s to execute. > > Cordially and best regards. In my off-list reply, where I suggested that you follow up on the list instead, I pointed you to the EXPLAIN command. Also, the initial reply I made pointed you to the logging options like log_min_duration. You might want to use those tools to see what's going on. Start with: EXPLAIN ANALYZE SELECT i FROM Item i; ... but I'd expect to see just a normal sequential scan of a table with lots of entries. If that's the case, options to make it faster include: - don't do it if you don't have to, it's always going to be expensive - Make sure your tables aren't bloated. See: http://www.postgresql.org/docs/8.3/interactive/routine-vacuuming.html http://wiki.postgresql.org/wiki/Introduction_to_VACUUM%2C_ANALYZE%2C_EXPLAIN%2C_and_COUNT ... and use proper autovacuuming. - Don't have tables that are too "wide", ie with too many fields. While they're supported fine, they can be slower to scan because there's just more data there. If you need crazy-fast sequential scans of the whole table for just a few points of data, consider splitting the table into two tables with a one-to-one relationship - but understand that that'll slow other things down. A materialized view is another alternative. - Write your app to deal with the latency. Sometimes queries are slow, especially over slow links. Do your work in a background worker thread, and keep the UI responsive. (Doesn't make sense for web apps, but is important for normal GUI apps). - Get faster disks, more RAM for caching, etc. -- Craig Ringer