Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3835DB5DBC4 for ; Sun, 10 Jul 2011 19:54:20 -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 30729-02 for ; Sun, 10 Jul 2011 22:54:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id BDFCAB5D803 for ; Sun, 10 Jul 2011 19:54:09 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 92984EB for ; Sun, 10 Jul 2011 18:54:09 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3F2urPu7hWSX for ; Sun, 10 Jul 2011 18:54:08 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 38C6F27 for ; Sun, 10 Jul 2011 18:54:08 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 7A302AF7E5 for ; Mon, 11 Jul 2011 06:54:06 +0800 (WST) X-Amavis-Modified: Mail body modified (using disclaimer) - mail.postnewspapers.com.au 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 dGEQfpByLZHy for ; Mon, 11 Jul 2011 06:54:01 +0800 (WST) Received: from [10.1.1.8] (58-7-210-8.dyn.iinet.net.au [58.7.210.8]) (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 0EE35AF7E4 for ; Mon, 11 Jul 2011 06:54:00 +0800 (WST) Message-ID: <4E1A2D88.5040902@postnewspapers.com.au> Date: Mon, 11 Jul 2011 06:54:00 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Fw: query total time im milliseconds References: <1310298105.48876.YahooMailRC@web38605.mail.mud.yahoo.com> <1310322371.24647.YahooMailRC@web38604.mail.mud.yahoo.com> In-Reply-To: <1310322371.24647.YahooMailRC@web38604.mail.mud.yahoo.com> 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=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201107/91 X-Sequence-Number: 44303 On 11/07/2011 2:26 AM, Radhya sahal wrote: > long startTime = System.currentTimeMillis(); > //execute query > long executionTime = System.currentTimeMillis() - startTime; > > this executionTime is not an actual time for query , > it includes time for access to postgresql server > using JDBC The pg_stat_statements contrib module in PostgreSQL 8.4 and above might be able to do what you want. See the documentation here: http://www.postgresql.org/docs/9.0/static/pgstatstatements.html I don't think the core PostgreSQL server currently retains information about how long the last query executed ran for. I thought the PL/PgSQL "GET DIAGNOSTICS" statement might be able to find out how long the last query run within that PL/PgSQL function took, but it can't. So I think you're out of luck for now. PostgreSQL *CAN* log query durations to the server log, it just doesn't (AFAIK) offer any way to find out how long the last query took from SQL and doesn't keep that information after the statement finishes. -- Craig Ringer POST Newspapers 276 Onslow Rd, Shenton Park Ph: 08 9381 3088 Fax: 08 9388 2258 ABN: 50 008 917 717 http://www.postnewspapers.com.au/