GBase 8a集群查看所有节点正在运行的SQL

注意:该功能在某些V95的早期版本里被去掉了,如果你的版本不支持,请升级集群,或者人工连接各个节点查询show processlist等进行查看。

1.1.1.    作用

查看集群当前正在运行的所有任务,特别是运行时间最长的任务。

1.1.2.    使用方法

管理节点

select * from information_schema.COORDINATORS_TASK_INFORMATION;

排除一些不重要的字段,可以追加如下条件.

select COORDINATOR_NAME, ID, user, host, command, start_time, time, state, substring(info,0,100) info from information_schema.COORDINATORS_TASK_INFORMATION where info is not null and info not like '%information_schema.processlist%' order by time desc;

计算节点

select * from information_schema.GNODE_TASK_INFORMATION;

select NODE_NAME, ID, user, host, command, start_time, time, state, substring(info,0,100) info from information_schema.GNODES_TASK_INFORMATION where info is not null and info not like '%information_schema.processlist%' order by time desc;

如下管理节点表,绿色部分是重点关注的内容,其余白色背景的请忽略。

字段类型作用
COORDINATOR_NAMEvarchar(64)管理节点名字
IDbigint(4)进程ID
TASKIDbigint(4)数据库内部任务号,每个命令执行时都会增加
SUBTASKIDbigint(4)未见使用
THREADIDbigint(4)数据库内线程号,一般在一个session内是不会变动的
USERvarchar(16)登录用户
HOSTvarchar(64)连接的客户端主机
DBvarchar(64)默认连接的数据库
COMMANDvarchar(16)命令类型
START_TIMEtimestamp开始时间
TIMEint(7)执行时间
STATEvarchar(64)状态
RESOURCE_POOL_NAMEvarchar(64)
RESOURCE_POOL_IDbigint(21)unsigned
RESOURCE_POOl_PRIORITYbigint(21)unsigned
WAITING_TIMEbigint(21)unsigned等待时间
RUNNING_TIMEbigint(21)unsigned运行时间
LOCKlongtext已经拿到的锁
WAITlongtext等待的锁
INFOlongtext执行的SQL
TRACElongtext

计算节点

字段类型作用
NODE_NAMEvarchar(64)计算节点名字
IDbigint(4)进程ID
TASKIDbigint(4)数据库内部任务号
SUBTASKIDbigint(4)数据库内部子任务号
THREADIDbigint(4)数据库内线程号
USERvarchar(16)登录用户
HOSTvarchar(64)连接的客户端主机
DBvarchar(64)默认连接的数据库
COMMANDvarchar(16)命令类型
START_TIMEtimestamp开始时间
TIMEint(7)执行时间
STATEvarchar(64)状态
RESOURCE_POOL_NAMEvarchar(64)
RESOURCE_POOL_IDbigint(21)unsigned
RESOURCE_POOl_PRIORITYbigint(21)unsigned
WAITING_TIMEbigint(21)unsigned
RUNNING_TIMEbigint(21)unsigned运行时间
PARALLEL_DEGREEbigint(21)unsigned并行线程数
CPU_USAGEbigint(21)unsigned
MEM_USAGEbigint(21)unsigned
TEMP_DISKSPACE_SORTbigint(21)unsigned
TEMP_DISKSPACE_JOINbigint(21)unsigned
TEMP_DISKSPACE_AGGRbigint(21)unsigned
INFOlongtext执行的SQL
TRACElongtext

其中CPU等信息,需要开启资源管控功能。

1.1.3.    使用样例

图中为了方便,使用了\G格式,否则在一行里不方便看。

如下提供一个连续运行的脚本;其中将substring(info,0,100)去掉了,显示全部的info为后续排查方便,而sleep 10秒,请根据实际情况修改, 问题排查可以考虑减少到5秒。 日常跟踪,建议增加到30-60秒,也就是更关注执行时间长的SQL。

[root@gbase101 ~]# cat gbase_monit_sql.sh
#!/bin/sh
#死循环
while [ 2 -gt 1 ];
do
  # current datetime
  date
  # get current running sql in whole gbase 8a cluster
  gccli -h127.0.0.1 -ugbase -pgbase20110531 -vvv -e"select COORDINATOR_NAME, ID, user, host, command, start_time, time, state, info from information_schema.COORDINATORS_TASK_INFORMATION where info is not null and info not like '%information_schema.processlist%' order by time desc"
  # Delay 10 second
  sleep 10
done

然后用 nohup 在后台运行

nohup sh gbase_monit_sql.sh &