錯誤原因:使用了分布式事務,造成這個問題的原因很多時候都是由于網絡問題造成的
解決辦法:
1.找到TRAN_ID
Select 'Rollback force '''||LOCAL_TRAN_ID||'''' from sys.pending_trans$;
2.將其COMMIT或ROLLBACK:
rollback force LOCAL_TRAN_ID;
commit force LOCAL_TRAN_ID;
3.如果執行失敗,則強行從資料字典中删除該交易記錄:
set transaction use rollback segment system;
delete from dba_2pc_pending where local_tran_id = LOCAL_TRAN_ID;
delete from pending_sessions$ where local_tran_id = LOCAL_TRAN_ID;
delete from pending_sub_sessions$ where local_tran_id = LOCAL_TRAN_ID;
commit;
生成批量語句:
begin
for r in (select local_tran_id
from dba_2pc_pending t
where t.state = 'collecting') loop
--dbms_output.put_line('commit force '''||r.local_tran_id||''';');
dbms_output.put_line('delete from dba_2pc_pending where local_tran_id = '''||r.local_tran_id||''';');
dbms_output.put_line('delete from pending_sessions$ where local_tran_id = '''||r.local_tran_id||''';');
dbms_output.put_line('delete from pending_sub_sessions$ where local_tran_id = '''||r.local_tran_id||''';');
end loop;
dbms_output.put_line('commit;');
end;
4.執行失敗,還一種情況可以嘗試下重起一下Oracle服務,這種情況我遇到過一次,重新啟動後該鎖自動解除(因為對删除資料字典比較擔心,是以胡亂試了一次重新開機資料庫,前提是執行了commit force LOCAL_TRAN_ID;失敗之後重新啟動)