66

I have a select query running very long. How will I get a status of that query, like how long will it be running? Whether it is accessing a data from the tables or not.

Note : As per pg_stat_activity the query state is shown as active and not in a waiting state. Like in Oracle, we can see the source/target and processing status of a query - is there something like this in postgresql?

Nikunj Kakadiya
  • 2,689
  • 2
  • 20
  • 35
Arun Padule
  • 681
  • 1
  • 6
  • 7
  • I need a completion time of a query in the above question. pg_stat_activity view gives only the active queries, database, user detail. pg_stat_activity do not contains the completion time of a running query. – Arun Padule Oct 01 '12 at 06:06

3 Answers3

57

Based on @Anshu answer I am using:

SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age 
FROM pg_stat_activity
WHERE state <> 'idle' 
    AND query NOT LIKE '% FROM pg_stat_activity %' 
ORDER BY age;
Jonathan
  • 8,453
  • 9
  • 51
  • 74
Mircea Vutcovici
  • 1,894
  • 19
  • 27
9

This can't be done yet, but is on the TODO.

tshepang
  • 12,111
  • 21
  • 91
  • 136
supyo
  • 3,017
  • 2
  • 20
  • 35
9

we can find the query log with respect to the database in postgres .

select *
from pg_stat_activity
where datname = 'yourdatabasename'

This will give active query log of database .

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75