Re: Determine query run-time from pg_* tables

From: Erik Jones <erik(at)myemma(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Determine query run-time from pg_* tables
Date: 2007-10-23 14:28:39
Message-ID: 306CF14D-2831-4E23-8412-5F543FCD88F5@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Oct 23, 2007, at 8:43 AM, Alvaro Herrera wrote:

> Ow Mun Heng wrote:
>> Hi,
>>
>> Is there a method to obtain the query's runtime from any of the pg_*
>> tables?
>
> No. You can use log_durations and log_statement for that. We don't
> store that info in tables.
>
>> Right now, I'm only seeing the backend_start_time (from
>> pg_stat_activity) (and I'm also not sure how to interpret this.
>
> This is the time that the session was started. Nothing to do with the
> query itself.

query_start does, however, give you the time that the query started.
I use something like

SELECT procpid, client_addr, to_char(now() - query_start, 'DD
HH24:MI:SS') as query_time, current_query
FROM pg_stat_activity
ORDER BY query_time DESC;

To get a snapshot view of what's currently running in our databases.

Erik Jones

Software Developer | Emma®
erik(at)myemma(dot)com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-10-23 14:57:53 Re: autovacuum and locks
Previous Message Tom Lane 2007-10-23 14:22:12 Re: Bitmap Heap scan 8.1/8.2