PostgreSQL实时查看数据库实例正在执行的SQL

PostgreSQL实时查看数据库实例正在执行的SQL

Laughing
2023-07-11 / 0 评论 / 696 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年07月11日,已超过556天没有更新,若内容或图片失效,请留言反馈。
SELECT
    pid,
    datname,
    usename,
    client_addr,
    application_name,
    STATE,
    backend_start,
    xact_start,
    xact_stay,
    query_start,
    query_stay,
    REPLACE ( query, chr( 10 ), ' ' ) AS query
FROM
    (
    SELECT
        pgsa.pid AS pid,
        pgsa.datname AS datname,
        pgsa.usename AS usename,
        pgsa.client_addr client_addr,
        pgsa.application_name AS application_name,
        pgsa.STATE AS STATE,
        pgsa.backend_start AS backend_start,
        pgsa.xact_start AS xact_start,
        EXTRACT ( epoch FROM ( now( ) - pgsa.xact_start ) ) AS xact_stay,
        pgsa.query_start AS query_start,
        EXTRACT ( epoch FROM ( now( ) - pgsa.query_start ) ) AS query_stay,
        pgsa.query AS query
    FROM
        pg_stat_activity AS pgsa
    WHERE
        pgsa.STATE != 'idle'
        AND pgsa.STATE != 'idle in transaction'
        AND pgsa.STATE != 'idle in transaction (aborted)'
    ) idleconnections
ORDER BY
    query_stay DESC
0

评论 (0)

取消