【ORA-02049】超时分布式事务处理等待锁 解决方法

1、以sys用户登录数据库查询死锁

SELECT
	USERNAME,
	LOCKWAIT,
	STATUS,
	MACHINE,
	PROGRAM
FROM
	V$SESSION
WHERE
	SID IN (
		SELECT
			SESSION_ID
		FROM
			V$LOCKED_OBJECT
	);

2、使用以下语句查询被死锁的语句

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
			)
	);

3、使用以下语句查找被死锁的进程

SELECT
	S.USERNAME,
	L.OBJECT_ID,
	L.SESSION_ID,
	S.SERIAL#,
	L.ORACLE_USERNAME,
	L.OS_USER_NAME,
	L. PROCESS
FROM
	V$LOCKED_OBJECT L,
	V$SESSION S
WHERE
	L.SESSION_ID = S. SID;

4、使用以下语句kill死锁的进程

ALTER SYSTEM KILL SESSION 'sid,serial#';
--(其中sid=l.session_id)
--如:SQL> alter system kill session '24,37522'