From: Craig Ringer <craig@postnewspapers.com.au>
To: Radhya sahal <rad_cs_2006@yahoo.com>
Cc: pgsql-performance group <pgsql-performance@postgresql.org>
Subject: Re: How can retrieve total query run-time with out using explain
Date: Sun, 03 Jul 2011 14:09:18 +0800
Message-ID: <4E10078E.6000101@postnewspapers.com.au> (raw)
In-Reply-To: <1309666434.43400.YahooMailClassic@web38605.mail.mud.yahoo.com>
References: <1309666434.43400.YahooMailClassic@web38605.mail.mud.yahoo.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: craig@postnewspapers.com.au, rad_cs_2006@yahoo.com
Subject: Re: How can retrieve total query run-time with out using explain
In-Reply-To: <4E10078E.6000101@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox