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

狂风中的少年 提交于 2021-02-05 19:23:01

问题


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?


回答1:


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;



回答2:


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




回答3:


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 .



来源:https://stackoverflow.com/questions/12641676/how-to-get-a-status-of-a-running-query-in-postgresql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!