如何在 postgresql 数据库中获取正在运行的查询的状态 [英] How to get a status of a running query in postgresql database

查看:63
本文介绍了如何在 postgresql 数据库中获取正在运行的查询的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行很长时间的选择查询.我将如何获得该查询的状态,例如它将运行多长时间?是否访问表中的数据.

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.

注意:根据 pg_stat_activity 查询状态显示为活动状态而不是等待状态.就像在 Oracle 中一样,我们可以看到查询的源/目标和处理状态 - postgresql 中是否有类似的东西?

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?

推荐答案

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

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;

这篇关于如何在 postgresql 数据库中获取正在运行的查询的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆