意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

oracle11g自动杀锁脚本怎么编写

来源:恒创科技 编辑:恒创科技编辑部
2023-12-24 13:42:59

今天就跟大家聊聊有关oracle 11g自动杀锁脚本怎么编写,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

最近临近春节,客户的一套11gRAC下午经常会出现锁,开发人员都回家了无法修改逻辑。为了避免过年期间因为这个每天都播vpn处理,所以赶忙写了一个自动杀锁的脚本。
这个脚本有几点需要注意的:
1.针对于linux系统
2.oracle 11g单实例和RAC都可以
3.考虑到了active的锁不能杀
4.有的锁的锁源会是一些系统进程,担心杀掉以后库会直接宕掉,脚本也考虑到了这一点。
5.客户这台服务器上有两套RAC,为了安全起见,sqlplus前我都export了一下环境变量。

可以把这这个脚本发给值班室的兄弟们,出现了锁跑一下,也可以写到crontab里面。


#!/bin/bash
#get lock infomation
export ORACLE_SID=ogg1
sqlplus -s "/as sysdba" <<eof
spool /home/oracle/killholder_tmp.sql
select 'alter system kill session ''' || s.SID || ',' || s.SERIAL# || ',@' ||
       s.INST_ID || ''' immediate;' killsql
  from gv\$lock l, gv\$session s
where (id1, id2, l.type) in
       (select id1, id2, type from gv\$lock where request > 0)
   and l.sid = s.sid
   and l.inst_id = s.inst_id
   and s.status='INACTIVE'
   and s.type='USER'
   and decode(request, 0, 'Holder:', ' Waiter:') = 'Holder:'
order by id1, ctime desc, request;
spool off
exit
eof

#kill the lock holder
more /home/oracle/killholder_tmp.sql |grep '^a' > /home/oracle/killholder.sql
export ORACLE_SID=ogg1
sqlplus -s "/as sysdba" <<eof
@/home/oracle/killholder.sql
exit
eof

#check lock again
export ORACLE_SID=ogg1
sqlplus -s "/as sysdba" <<eof
spool /home/oracle/event.txt
select inst_id, event#, event,count(*) from gv\$session
where wait_class# <> 6
group by inst_id, event#,event
order by 1,4 desc;
spool off
exit
eof
TXLOCKNUM=$(more /home/oracle/event.txt|grep 'TX'|wc -l)
TMLOCKNUM=$(more /home/oracle/event.txt|grep 'TM'|wc -l)
if [ $TXLOCKNUM -eq 0 ] && [ $TMLOCKNUM -eq 0  ]
then
        echo "there is no lock!"
else
        echo "there is still having lock! "
fi

看完上述内容,你们对oracle 11g自动杀锁脚本怎么编写有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注恒创行业资讯频道,感谢大家的支持。


oracle11g自动杀锁脚本怎么编写

上一篇: 数据库随集群启动该如何设置 下一篇: 有关oracle11.2.0.4补丁问题怎样分析