Re: How can retrieve total query run-time with out using explain - Mailing list pgsql-performance

From Craig Ringer
Subject Re: How can retrieve total query run-time with out using explain
Date
Msg-id 4E10078E.6000101@postnewspapers.com.au
Whole thread Raw
In response to How can retrieve total query run-time with out using explain  (Radhya sahal <rad_cs_2006@yahoo.com>)
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Radhya sahal
Date:
Subject: How can retrieve total query run-time with out using explain
Next
From: Magnus Hagander
Date:
Subject: Re: Infinite Cache