【转】查看oracle死锁进程并结束死锁

--查看锁表进程SQL语句1:

select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode

from v$locked_object lo, dba_objects ao, v$session sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid;

--查看锁表进程SQL语句2:

select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID;

--杀掉锁表进程:

--如有記錄則表示有lock,記錄下SID和serial# ,將記錄的ID替換下面的738,1429,即可解除LOCK

alter system kill session ‘738,1429‘;

--用这个可以查(可以查看哪台机器哪个用户锁了记录, 其中command是用来杀掉锁住记录的session ):

select s.sid,s.machine,o.object_name,l.oracle_username,l.locked_mode, ‘ALTER SYSTEM KILL SESSION ‘‘‘||s.sid||‘, ‘||s.serial#||‘‘‘;‘ Command

from v$locked_object l,v$session s,all_objects o where l.session_id=s.sid and l.object_id=o.object_id;

select V$SESSION.sid,v$session.SERIAL#,v$process.spid,

rtrim(object_type) object_type,rtrim(owner) || ‘.‘ || object_name object_name,

decode(lmode, 0, ‘None‘,

1, ‘Null‘,

2, ‘Row-S‘,

3, ‘Row-X‘,

4, ‘Share‘,

5, ‘S/Row-X‘,

6, ‘Exclusive‘, ‘Unknown‘) LockMode,

decode(request, 0, ‘None‘,

1, ‘Null‘,

2, ‘Row-S‘,

3, ‘Row-X‘,

4, ‘Share‘,

5, ‘S/Row-X‘,

6, ‘Exclusive‘, ‘Unknown‘) RequestMode

,ctime, block b,

v$session.username,MACHINE,MODULE,ACTION,

decode(A.type,

‘MR‘, ‘Media Recovery‘,

‘RT‘,‘Redo Thread‘,

‘UN‘,‘User Name‘,

‘TX‘, ‘Transaction‘,

‘TM‘, ‘DML‘,

‘UL‘, ‘PL/SQL User Lock‘,

‘DX‘, ‘Distributed Xaction‘,

‘CF‘, ‘Control File‘,

‘IS‘, ‘Instance State‘,

‘FS‘, ‘File Set‘,

‘IR‘, ‘Instance Recovery‘,

‘ST‘, ‘Disk Space Transaction‘,

‘TS‘, ‘Temp Segment‘,

‘IV‘, ‘Library Cache Invalida-tion‘,

‘LS‘, ‘Log Start or Switch‘,

‘RW‘, ‘Row Wait‘,

‘SQ‘, ‘Sequence Number‘,

‘TE‘, ‘Extend Table‘,

‘TT‘, ‘Temp Table‘,

‘Unknown‘) LockType

from (SELECT * FROM V$LOCK) A, all_objects, V$SESSION, v$process

where A.sid > 6

and object_name<>‘OBJ$‘

and A.id1 = all_objects.object_id

and A.sid=v$session.sid

and v$process.addr=v$session.paddr;

--同样也是通过写sql从数据字典里查出来。

-- SELECT-SQL1 功能:检查被加锁的对象

select obj.OWNER||‘.‘||obj.OBJECT_NAME as OBJ_NAME, --// 对象名称(已经被锁住)

obj.SUBOBJECT_NAME as SUBOBJ_NAME, --// 子对象名称(已经被锁住)

obj.OBJECT_ID as OBJ_ID, --// 对象ID

obj.OBJECT_TYPE as OBJ_TYPE, --// 对象类型

lock_obj.SESSION_ID as SESSION_ID, --// 会话SESSION_ID

lock_obj.ORACLE_USERNAME as ORA_USERNAME, --// ORACLE系统用户名称

lock_obj.OS_USER_NAME as OS_USERNAME, --// 操作系统用户名称

lock_obj.PROCESS as PROCESS --// 进程编号

from

( select * from all_objects where object_id in (select object_id from v$locked_object)) obj,

v$locked_object lock_obj

where obj.object_id=lock_obj.object_id;

-- SELECT-SQL2 功能:检查被加锁的对象以及加锁的会话信息

-- 如果需要手工解除锁,请对照要解锁的对象,记下SESSION_ID,SERIAL# 项,然后运行下面的ALTER-SQL1

select LOCK_INFO.OWNER||‘.‘||LOCK_INFO.OBJ_NAME as OBJ_NAME, --// 对象名称(已经被锁住)

LOCK_INFO.SUBOBJ_NAME as SUBOBJ_NAME, --// 子对象名称(已经被锁住)

SESS_INFO.MACHINE as MACHINE, --// 机器名称

LOCK_INFO.SESSION_ID as SESSION_ID, --// 会话SESSION_ID

SESS_INFO.SERIAL# as SERIAL#, --// 会话SERIAL#

LOCK_INFO.ORA_USERNAME as ORA_USERNAME, --// ORACLE系统用户名称

LOCK_INFO.OS_USERNAME as OS_USERNAME, --// 操作系统用户名称

LOCK_INFO.PROCESS as PROCESS, --// 进程编号

LOCK_INFO.OBJ_ID as OBJ_ID, --// 对象ID

LOCK_INFO.OBJ_TYPE as OBJ_TYPE, --// 对象类型

SESS_INFO.LOGON_TIME as LOGON_TIME, --// 登录时间

SESS_INFO.PROGRAM as PROGRAM, --// 程序名称

SESS_INFO.STATUS as STATUS, --// 会话状态

SESS_INFO.LOCKWAIT as LOCKWAIT, --// 等待锁

SESS_INFO.ACTION as ACTION, --// 动作

SESS_INFO.CLIENT_INFO as CLIENT_INFO --// 客户信息

from

(

select obj.OWNER as OWNER,

obj.OBJECT_NAME as OBJ_NAME,

obj.SUBOBJECT_NAME as SUBOBJ_NAME,

obj.OBJECT_ID as OBJ_ID,

obj.OBJECT_TYPE as OBJ_TYPE,

lock_obj.SESSION_ID as SESSION_ID,

lock_obj.ORACLE_USERNAME as ORA_USERNAME,

lock_obj.OS_USER_NAME as OS_USERNAME,

lock_obj.PROCESS as PROCESS

from

( select * from all_objects where object_id in (select object_id from v$locked_object)) obj,

v$locked_object lock_obj

where obj.object_id=lock_obj.object_id

) LOCK_INFO,

(

select SID,

SERIAL#,

LOCKWAIT,

STATUS,

PROGRAM,

ACTION,

CLIENT_INFO,

LOGON_TIME,

MACHINE

from v$session

) SESS_INFO

where LOCK_INFO.SESSION_ID=SESS_INFO.SID ;

-- 看清楚了 下面就可以 杀死它了。

-- ALTER-SQL1 功能:杀死会话(SESSION_ID,SERIAL#),可以手工解除锁

-- 请手工修改SESSION_ID,SERIAL#为相应值

-- 注意:本功能慎重使用,有一定的破坏性,该SQL可以断开客户机和服务器的连接

ALTER SYSTEM KILL SESSION ‘SESSION_ID,SERIAL#‘;

时间: 2024-10-24 23:12:16

【转】查看oracle死锁进程并结束死锁的相关文章

查看oracle死锁进程并结束死锁

查看锁表进程SQL语句1: select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode from v$locked_object lo, dba_objects ao, v$session sess where ao.object_id = lo.object_id and lo.session_id = sess.sid; 查看锁表进程SQL语句2: sel

【ORACLE】查看死锁进程并结束死锁的脚本

--共享锁:Share:排他锁:Exclusive:行共享锁:Row-S:行排他锁:Row-X select V$SESSION.sid,v$session.SERIAL#,v$process.spid, rtrim(object_type) object_type,rtrim(owner) || '.' || object_name object_name, decode(lmode, 0, 'None', 1, 'Null', 2, 'Row-S', 3, 'Row-X', 4, 'Shar

sql server 查看表的死锁和Kill 死锁进程

查询出来 select        request_session_id spid,       OBJECT_NAME(resource_associated_entity_id) tableName    from        sys.dm_tran_locks   where        resource_type='OBJECT 杀死死锁进程 kill spid 另: exec master.dbo.sp_who_lock --查看当前死锁进程 exec master.dbo.p_

Oracle数据表中的死锁情况解决方法

不知道干了啥,把数据表锁住了,没法update. 百度了各种方法,总结如下. 查看被锁住的表(两句都可以): select * from v$session t1, v$locked_object t2 where t1.sid=t2.SESSION_ID   select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode from v$locked_object

Linux内核调试技术——进程D状态死锁检测

Linux的进程存在多种状态,如TASK_RUNNING的运行态.EXIT_DEAD的停止态和TASK_INTERRUPTIBLE的接收信号的等待状态等等(可在include/linux/sched.h中查看).其中有一种状态等待为TASK_UNINTERRUPTIBLE,称为D状态,该种状态下进程不接收信号,只能通过wake_up唤醒.处于这种状态的情况有很多,例如mutex锁就可能会设置进程于该状态,有时候进程在等待某种IO资源就绪时(wait_event机制)会设置进程进入该状态.一般情况

事务(进程 ID )与另一个进程已被死锁在 lock 资源上,且该事务已被选作死锁牺牲品。请重新运行该事务

其实所有的死锁最深层的原因就是一个:资源竞争 表现一:    一个用户A 访问表A(锁住了表A),然后又访问表B    另一个用户B 访问表B(锁住了表B),然后企图访问表A 这时用户A由于用户B已经锁住表B,它必须等待用户B释放表B,才能继续,好了他老人家就只好老老实实在这等了    同样用户B要等用户A释放表A才能继续这就死锁了解决方法:    这种死锁是由于你的程序的BUG产生的,除了调整你的程序的逻辑别无他法    仔细分析你程序的逻辑,    1:尽量避免同时锁定两个资源    2:

Linux下使用ps命令来查看Oracle相关的进程

Linux下可以使用ps命令来查看Oracle相关的进程 Oracle Listener 这个命令会列出Oracle Net Listener的进程 [[email protected] www.linuxidc.com ~]$ ps -ef | grep tnslsnr oracle    1999 29986  0 09:47 pts/2    00:00:00 grep tnslsnr oracle    3647     1  0 Jul03 ?        00:00:34 /u01

SqlServer 查询死锁,杀死死锁进程

-- 查询死锁 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT' --杀死死锁进程 kill spid

ORACLE如何查看修改连接数,进程数及用户数,三者之间关系

SQL> select count(*) from v$session #连接数SQL> Select count(*) from v$session where status='ACTIVE' #并发连接数SQL> show parameter processes #最大连接 process:这个参数限制了能够连接到SGA的操作系统进程数(或者是Windows 系统中的线程数),这个总数必须足够大,从而能够适用于后台进程与所有的专用服务器进程,此外,共享服务器进程与调度进程的数目也被计