以下的文章主要向大家描述的是在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腳本的介紹,望你能有所收獲。