Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 74269B5DBC1 for ; Sun, 3 Jul 2011 03:09:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 33942-06 for ; Sun, 3 Jul 2011 06:09:30 +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 D0024B5D80A for ; Sun, 3 Jul 2011 03:09:29 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id D7DD83E; Sun, 3 Jul 2011 02:09:27 -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 kWRqZkykm2j2; Sun, 3 Jul 2011 02:09:27 -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 AC14727; Sun, 3 Jul 2011 02:09:26 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 0C931AF32A; Sun, 3 Jul 2011 14:09:25 +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 nvHhGoDu-zJP; Sun, 3 Jul 2011 14:09:20 +0800 (WST) Received: from [10.1.1.7] (124-169-57-156.dyn.iinet.net.au [124.169.57.156]) (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 31A73AF328; Sun, 3 Jul 2011 14:09:20 +0800 (WST) Message-ID: <4E10078E.6000101@postnewspapers.com.au> Date: Sun, 03 Jul 2011 14:09:18 +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: Radhya sahal CC: pgsql-performance group Subject: Re: How can retrieve total query run-time with out using explain References: <1309666434.43400.YahooMailClassic@web38605.mail.mud.yahoo.com> In-Reply-To: <1309666434.43400.YahooMailClassic@web38605.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/9 X-Sequence-Number: 44221 On 3/07/2011 12:13 PM, Radhya sahal wrote: > Dear all, > How can retrieve total query run-time when i run any query with out > using explain EXPLAIN doesn't tell you the query runtime. EXPLAIN ANALYZE does, but it doesn't return the query results, returning plan and timing information instead. > for example when i run any query such as > select * from tablel1; > Total query runtime: 443 ms. in psql, use: \timing on > i want a function can return "runtime: 443 ms" with out using explain > i want this command to call it from java source code Record the system time before you run the query using System.currentTimeMillis() or System.nanoTime(). Record the system time after you run the query. Subtract and convert the difference to a java.util.Date so you can format it prettily for display, or just print the difference in milliseconds. If you want more flexible date/time handling, see JodaTime. This gives you the time the query took including how long it took to retrieve the initial resultset. If you want the time the query took to execute on the server, not counting fetch time, this may not be what you want. I don't know how to get query execution time *not* counting resultset retrieval time from the client. Anyone know if it's even possible? -- Craig Ringer