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

前端 未结 3 1316
一个人的身影
一个人的身影 2021-02-01 13:10

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.

N

相关标签:
3条回答
  • 2021-02-01 13:40

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

    0 讨论(0)
  • 2021-02-01 13:42

    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 .

    0 讨论(0)
  • 2021-02-01 13:51

    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;
    
    0 讨论(0)
提交回复
热议问题