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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux