shell + 达梦 :实现数据库查询,根据返回结果查询系统pstack信息

-- 定义变量
HOST_NAME='192.168.153.10'
USER_NAME='SYSDBA'
PASSWD='SYSDBA'
DB_PORT='5236' 
DATETIME=$(date "+%Y%m%d%H%M%S")
LOG_PATH=/home/dmdba

DM_CON="disql $USER_NAME/$PASSWD@$HOST_NAME:$DB_PORT -e"

DM_SELECT_SQL="select sum(temp_cnt) from (
select case when count(1)>0 then 1 else 0 end temp_cnt from (
SELECT datediff(ss,last_recv_time,sysdate) Y_EXETIME
FROM V$SESSIONS WHERE STATE='ACTIVE')
where Y_EXETIME>=1 union all
select case when count(1)>500 then 2 else 0 end temp_cnt from v$sessions where state = 'ACTIVE')"
 
result=$($DM_CON "${DM_SELECT_SQL}")

rt=`echo ${result: -1}`
echo "rt="$rt
#echo "|"$result"|"

	if rt=1 ; then
	pstack 1377 > $LOG_PATH"/pstack_dmserver_"$DATETIME"_1.log"
	elif rt=2; then  
	pstack 1377 > $LOG_PATH"/pstack_dmserver_"$DATETIME"_2.log"
	elif rt=3; then  
	pstack 1377 > $LOG_PATH"/pstack_dmserver_"$DATETIME"_3.log"
	else 
	$pstack0
	fi

说明:

 此处的1377指的是数据库进程号,获取方式如下:

这个sql的查询结果理论上会有0,1,2,3这四个值,所以输出的时候需要根据结果使用条件判断输出接到到指定的日志中。

select sum(temp_cnt) from (
select case when count(1)>0 then 1 else 0 end temp_cnt from (
SELECT datediff(ss,last_recv_time,sysdate) Y_EXETIME
 FROM V$SESSIONS WHERE STATE='ACTIVE')
 where Y_EXETIME>=1 union all
 select case when count(1)>500 then 2 else 0 end temp_cnt from v$sessions where state = 'ACTIVE');

更多内容,请访问达梦社区地址:https:eco.dameng.com

猜你喜欢

转载自blog.csdn.net/Penrosee/article/details/125662963