Re: How can retrieve total query run-time with out using explain

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Radhya sahal <rad_cs_2006(at)yahoo(dot)com>
Cc: pgsql-performance group <pgsql-performance(at)postgresql(dot)org>
Subject: Re: How can retrieve total query run-time with out using explain
Date: 2011-07-03 06:09:18
Message-ID: 4E10078E.6000101@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Magnus Hagander 2011-07-03 11:21:09 Re: Infinite Cache
Previous Message Radhya sahal 2011-07-03 04:13:54 How can retrieve total query run-time with out using explain