以下的文章主要向大家描述的是在linux/unix下,DB2数据库解死锁之shell脚本,以下就是对在linux/unix下,DB2数据库解死锁之shell脚本的具体描述,希望在你今后的学习中会有所帮助。
clear;
- DB2 "connect to db user dbuser using dbpass"
- DB2 "update monitor switches using lock on table on"
- tmpf=`echo "$HOME/tmp/""$RANDOM"_"$SECONDS"".lock"`
- DB2 get snapshot for locks on abbs>$tmpf
- handles=`cat $tmpf|awk '{if($2=="handle")print $4}'`
- x=0;
- y=0;
- deadhandles=" "
- for i in $handles
- do
取当前id所在行
- ibeg=`cat $tmpf|awk '{if($2=="handle" && $4=="'$i'")print NR}'`;
- #echo "Line[15]:handle:$i,beg:$ibeg"
取当前行以后的内容
- cat $tmpf|awk '{if(NR-1>'$ibeg')printf("%s\n", $0);}'>$tmpf.$i;
取下一个handle所在行
- hangdleaf=`cat $tmpf.$i|awk '{if($2=="handle")print NR}'`
- #echo Line[20]:$hangdleaf
- if [ -z "$hangdleaf" ];then
- cat $tmpf.$i>$tmpf.$i.aft;
- else
取下一个handle
- itmp="";
- for j in $hangdleaf
- do
- if [ -z "$itmp" ];then
- handlenext=$j;
- itmp="get done!"
- fi
- done
- #echo Line[33]:$handlenext;
- #cat $tmpf.$i|awk '{if(NR<'$handlenext')print $0;}'
- cat $tmpf.$i|awk '{if(NR<'$handlenext')print $0;}'>$tmpf.$i.aft;
- fi
判断本handle相关的锁 是否存在排他锁
- ifx=`cat $tmpf.$i.aft|awk '{if(($1=="Mode" && ($3=="X" || $3=="IX")) ||($2=="mode" && substr($6,2,1)=="X") )print $0;}'`
- #echo Line[39]:handle[$i],$ifx
- if [ -z "$ifx" ];then
- a=1
- else
- deadhandles="$deadhandles"" $i"
- x=`expr $x + 1`;
- echo $i
- fi
- #cat $tmpf.$i.aft|grep X|more
- #echo Line[48]:$deadhandles
- #read yn
- rm -f $tmpf.$i
- rm -f $tmpf.$i.aft
- done
- #echo "死锁$x:$deadhandles";
- #read yn
- clear
- if [ -z "$deadhandles" ] || [ "$deadhandles" = " " ] ;then
- echo "没有死锁,退出......";
- read yn;
- exit 0;
- fi
- echo "锁句柄:$deadhandles,解锁? Y/N\c"
- read yn;
- if [ -z "$yn" ];then
- echo "放弃解锁!"
- exit 0;
- fi
- if [ "$yn" = "Y" ] || [ "$yn" = "y" ];then
- x=0;
- for i in $deadhandles
- do
- echo 解死锁:$i
- DB2 "force applications($i)"
- x=`expr $x + 1`
- done
- echo "解开[$x]个锁...."
- else
- echo "放弃解锁!"
- exit 0;
- fi
- DB2 connect reset;
- DB2 terminate;
- rm -f $tmpf
- echo "解锁终端:">/tmp/tty.tmp
- tty>>/tmp/tty.tmp
- wall </tmp/tty.tmp
- rm -f /tmp/tty.tmp
以上的相关内容就是对linux/unix下DB2数据库解死锁的shell脚本的介绍,望你能有所收获。
【编辑推荐】