How to get a status of a running query in postgresql database

PostgresqlPostgresql 8.4

Postgresql Problem Overview


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?

Postgresql Solutions


Solution 1 - Postgresql

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;

Solution 2 - Postgresql

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

Solution 3 - Postgresql

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 .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArun PaduleView Question on Stackoverflow
Solution 1 - PostgresqlMircea VutcoviciView Answer on Stackoverflow
Solution 2 - PostgresqlsupyoView Answer on Stackoverflow
Solution 3 - PostgresqlHimanshu sharmaView Answer on Stackoverflow