SELECT USERNAME,SID, LOCKWAIT, STATUS, MACHINE, PROGRAM FROM v$session WHERE sid IN (SELECT session_id FROM v$locked_object);
SELECT sess.SID, sess.SERIAL#, lo.ORACLE_USERNAME, lo.OS_USER_NAME, lo.LOCKED_MODE, ao.OBJECT_NAME FROM V$LOCKED_OBJECT lo, v$session sess, dba_objects ao WHERE lo.SESSION_ID = sess.SID AND ao.OBJECT_ID = lo.OBJECT_ID;
SELECT sql_text FROM v$sql WHERE hash_value IN (SELECT sql_hash_value FROM v$session WHERE sid='XXXXXXXX');
SELECT sql_text FROM v$sql WHERE hash_value IN (SELECT sql_hash_value FROM v$session WHERE sid IN (SELECT session_id FROM v$locked_object));
造成死锁的sql事务都必定是未提交的
SELECT s.SID, s.USERNAME, s.OSUSER, s.PROGRAM, TO_CHAR(s.LOGON_TIME, 'yyyy-mm-dd hh24:mi:ss') AS LOGON_TIME, TO_CHAR(t.START_DATE, 'yyyy-mm-dd hh24:mi:ss') AS START_DATE, s.STATUS, (SELECT q.SQL_TEXT FROM v$sql q WHERE q.LAST_ACTIVE_TIME = t.START_DATE AND rownum <= 1) AS SQL_TEXT FROM v$session s, v$transaction t WHERE s.SADDR = t.SES_ADDR;
ALTER SYSTEM KILL SESSION 'sess.sid, sess.serial#';