zoukankan      html  css  js  c++  java
  • 利用pg_stat_activity进行问题排查

    pg_stat_activity是一个非常有用的视图,可以帮助排查pg的一些问题(如连接数目过多问题)。pg_stat_activity每行展示的是一个“process”的相关信息,这里的“process”可以理解为一个DB连接。

    The pg_stat_activity view will have one row per server process, showing information related to the current activity of that process.

    其他参考手册:

     http://www.postgresql.org/docs/9.4/static/monitoring-stats.html

    比较有用的3个字段,翻译如下:
    query_start:active状态的查询开始时间,如果状态不是active的,那么就是最后一次查询开始的时间
    state:运行状态,可以为几种值。active:正在执行查询;idle:等待新的命令;idle in transaction:后端是一个事务,但是尚未执行查询;idle in transaction(aborted):和idle in transaction类似,除了事务执行出错。
    query:执行的查询文本(即SQL)。如果状态是active,那么就是正在执行的SQL;如果是其他状态,则展示最后一次执行的SQL。
    所以可以用:
    select count(*) from pg_stat_activity where state='idle';
    查询闲置连接数。如果数字过大,可以认为是有问题的(如连接忘记关闭)。
    如果想进一步定位到有问题的SQL,可以如下查询:
    select query,count(*) as num from pg_stat_activity where state='idle' group by query order by num desc;

  • 相关阅读:
    oracle数据库导出与导入
    Mysql导入表信息[Err] 1067
    Golang--不定参数类型
    (转)Docker容器的重启策略及docker run的--restart选项详解
    (转)Golang--使用iota(常量计数器)
    Golang--匿名变量
    Golang--Hello World
    Ubuntu Server16.04 配置网卡
    U盘安装ubuntu 16.04 遇到 gfxboot.c32:not a COM32R image boot 的解决方法
    ipfs私链服务
  • 原文地址:https://www.cnblogs.com/space-place/p/5419980.html
Copyright © 2011-2022 走看看