GBase 8a 自定义存储过程 sp_cluster_processlist 查看集群任务SQL状态

GBase 8a提供了show processlist命令查看本机的SQL运行状态,也提供了COORDINATORS_TASK_INFORMATION元数据表来查看集群所有调度节点的SQL运行状态。本文提供一个自定义存储过程,来简化运维人员的使用难度。

参考

GBase8a 显示集群正在跑的SQL进程show [full | detail] processlist
GBase 8a集群查看所有节点正在运行的SQL

存储过程

用到的executeSQL通用动态SQL,请参考 GBase 8a集群存储过程样例,动态存储过程

sp_cluster_processlist

参数1 showSize:显示SQL的字符数量
参数2 topN:显示执行时间最长的SQL数量。

drop procedure if exists sp_cluster_processlist;
delimiter //
create procedure sp_cluster_processlist(showSize int,topN int)
begin
  set @sql=concat('select COORDINATOR_NAME, ID, user, host, command, start_time, time, state, substring(info,0,'
    ,showSize
    ,') info from information_schema.COORDINATORS_TASK_INFORMATION where command=\'query\' and info is not null and info not like \'%information_schema.processlist%\' order by time desc limit '
    ,topN);
  call executeSQL(@sql);
end
//
delimiter ;

调用

call sp_cluster_processlist(100,10);