如何在 postgresql 数据库中获取正在运行的查询的状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12641676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:45:33  来源:igfitidea点击:

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

postgresqlpostgresql-8.4

提问by Arun Padule

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_activitythe query is running as active. Not in a waiting state. Like in Oracle, we can see the source/target and prcessing status of a query - is there something like this in postgresql?

注意:根据pg_stat_activity查询正在运行。不处于等待状态。就像在 Oracle 中一样,我们可以看到查询的源/目标和处理状态 - postgresql 中是否有类似的东西?

回答by Mircea Vutcovici

Based on @Anshu answer I am using:

基于@Anshu 的回答,我正在使用:

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;

回答by supyo

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

这还不能完成,但在TODO 上

回答by Himanshu sharma

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

我们可以在 postgres 中找到关于数据库的查询日志。

select *
from pg_stat_activity
where datname = 'yourdatabasename'

This will give active query log of database .

这将提供数据库的活动查询日志。