列出对象锁(lock)信息及其被杀的会话(sid,serial#)信息
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,check_lock.sql脚本 列出对象锁(lock)信息及其被杀的会话(sid,serial#)信息set linesize 132 pagesize 66 break on Kill on us
千家信息网最后更新 2026年11月03日列出对象锁(lock)信息及其被杀的会话(sid,serial#)信息
check_lock.sql脚本 列出对象锁(lock)信息及其被杀的会话(sid,serial#)信息set linesize 132 pagesize 66 break on Kill on username on terminal column Kill heading 'Kill String' format a13 column res heading 'Resource Type' format 999 column id1 format 9999990 column id2 format 9999990 column lmode heading 'Lock Held' format a20 column request heading 'Lock Requested' format a20 column serial# format 99999 column username format a10 heading "Username" column terminal heading Term format a6 column tab format a35 heading "Table Name" column owner format a9 column Address format a18 column ctime heading "Seconds"select nvl(S.USERNAME,'Internal') username, nvl(S.TERMINAL,'None') terminal, L.SID||','||S.SERIAL# Kill, U1.NAME||'.'||substr(T1.NAME,1,20) tab, decode(L.LMODE,1,'No Lock', 2,'Row Share', 3,'Row Exclusive', 4,'Share', 5,'Share Row Exclusive', 6,'Exclusive',null) lmode, decode(L.REQUEST,1,'No Lock', 2,'Row Share', 3,'Row Exclusive', 4,'Share', 5,'Share Row Exclusive', 6,'Exclusive',null) request, l.ctimefrom V$LOCK L, V$SESSION S, SYS.USER$ U1, SYS.OBJ$ T1 where L.SID = S.SID and T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2) and U1.USER# = T1.OWNER# and S.TYPE != 'BACKGROUND' order by 1,2,5 / 会话1:以scott用户登录创建一个表t1[root@Oel_10G ~]# su - oracle[oracle@Oel_10G ~]$ sqlplus scott/oracleSQL> create table t1 (i int); Table created.SQL> insert into t1 values(1);1 row created.SQL> commit;Commit complete.在会话1中给t1加一个锁SQL> select * from t1 for update; I---------- 1会话 2:在会话2中更新t1表的一行, 由于t1表中有Row Exclusive锁,此时会话2获取不到锁暂时为挂起状态[root@Oel_10G ~]# su - oracle[oracle@Oel_10G ~]$ sqlplus scott/oracleSQL> update t1 set i=3 where i=1;会话 3:在会话3中更新t1表的一行, 由于t1表中有Row Exclusive锁,此时会话3获取不到锁暂时为挂起状态[root@Oel_10G ~]# su - oracle[oracle@Oel_10G ~]$ sqlplus scott/oracleSQL> update t1 set i=5 where i=1;会话 4:新开一个会话,以sys登陆,执行lock_check.sql查看相关对象锁信息[root@Oel_10G ~]# su - oracle[oracle@Oel_10G ~]$ sqlplus / as sysdbaSQL>@check_lock.sqlUsername Term Kill String Table Name Lock Held Lock Requested Seconds---------- ------ ------------- ----------------------------------- -------------------- -------------------- ----------SCOTT pts/1 525,891 PUBLIC.V$SQLAREA_PLAN_HASH Exclusive 108 SCOTT.T1 Row Exclusive 108SCOTT pts/2 544,8727 SCOTT.T1 Row Exclusive 72 PUBLIC.V$SQLAREA_PLAN_HASH Exclusive 72SCOTT pts/3 522,5542 SCOTT.T1 Row Exclusive 6 PUBLIC.V$SQLAREA_PLAN_HASH Exclusive 66 rows selected.执行脚本后,结果列出表t1相关对象及锁信息,会话1持有t1的行独占锁,会话2与会话3都在请求Exclusive锁现在我们kill掉scott用户下sid,serial#为(522,5542)的会话SQL> alter system kill session '522,5542';System altered在会话3中可以看到(sid,serial#)(522,5542)被杀掉SQL> update t1 set i=5 where i=1;update t1 set i=5 where i=1 *ERROR at line 1:ORA-00028: your session has been killed在会话4中继续执行check_lock.sqlSQL>@check_lock.sqlUsername Term Kill String Table Name Lock Held Lock Requested Seconds---------- ------ ------------- ----------------------------------- -------------------- -------------------- ----------SCOTT pts/1 525,891 PUBLIC.V$SQLAREA_PLAN_HASH Exclusive 388 SCOTT.T1 Row Exclusive 388SCOTT pts/2 544,8727 SCOTT.T1 Row Exclusive 352 PUBLIC.V$SQLAREA_PLAN_HASH Exclusive 352此时,会话3已被***
信息
对象
一行
状态
用户
脚本
更新
结果
新开
登录
登陆
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
什么是科技互联网
上海喔噻互联网科技有限公司
博彦科技互联网金融
上海卓越科技互联网
互联网最新的科技有限公司
腾讯阿里互联网科技
互联网金融 科技
平安科技 互联网
互联网科技媒体
互联网科技革命
无锡溥仪互联网科技有限公司
科技与互联网的利与弊
栖莱科技互联网股份有限公司
受益于互联网科技的高速发展
长沙茂晟互联网科技有限公司
2021互联网科技公司排名
上海乐五互联网科技有限公司
珠海东科互联网科技有限公司
福建互联网展示科技馆设计
互联网对科技影响
狮子座互联网科技有限公司
科技互联网公司logo
齐家互联网科技有限公司
互联网金融科技委员会
甘肃拓世互联网科技有限公司
互联网时代科技改变生活
浙南科技城互联网大厦建设工程
西安小鹰速贷互联网科技有限公司
皮皮虾互联网科技有限公司
北京互联网科技类企业分布