在Oracle数据库操作中遇到了ORA-01591的错误,经过分析得知错误的原因是使用了分布式事务,造成这个问题的原因很多时候都是由于网络问题造成的。
解决办法如下:
1.找到TRAN_ID
class="dp-xml">
- 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;失败之后重新启动)。