oracle 消除死锁而不终止会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1812086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:32:13  来源:igfitidea点击:

Remove deadlock without killing session

oraclesessiondeadlock

提问by P Sharma

Is there any workaround to remove deadlock without killing the session?

是否有任何解决方法可以在不终止会话的情况下消除死锁?

回答by Vincent Malgrat

From the Concepts Guide:

概念指南

Oracle automatically detects deadlock situations and resolves them by rolling back one of the statements involved in the deadlock, thereby releasing one set of the conflicting row locks.

Oracle 自动检测死锁情况并通过回滚死锁中涉及的语句之一来解决它们,从而释放一组冲突的行锁。

You don't have to do anything to remove a deadlock, Oracle takes care of it automatically. The session is not killed, it is rolled back to a point just before the trigger statement. The other session is unaffected (i-e it still waits for the lock until the rolled back session either commits or rolls back its transaction).

您无需执行任何操作即可消除死锁,Oracle 会自动处理它。会话不会被终止,它会回滚到触发器语句之前的某个点。另一个会话不受影响(即它仍然等待锁定,直到回滚的会话提交或回滚其事务)。

In most situations deadlocks should be exceptionally rare. You can prevent all deadlocks by using FOR UPDATE NOWAIT statements instead of FOR UPDATE.

在大多数情况下,死锁应该是非常罕见的。您可以通过使用 FOR UPDATE NOWAIT 语句而不是 FOR UPDATE 来防止所有死锁。

See also

也可以看看

Discussion about removing deadlock on AskTom

关于在 AskTom 上解除死锁的讨论

回答by Egor Rogov

Deadlocks are automatically cleared in Oracle by cancelling one of the locked statements. You need not do it manually. One of the sessions will get "ORA-00060" and it should decide whether to retry or roll back.

在 Oracle 中通过取消锁定语句之一自动清除死锁。您无需手动执行此操作。其中一个会话将得到“ORA-00060”,它应该决定是重试还是回滚。

But from you description it looks like you have a block, not deadlock.

但是从您的描述来看,您似乎遇到了阻塞,而不是死锁。

Anyway, blocking session should somehow release its lock -- by commiting or rolling back its transaction. You can just wait for it (possibly for a long time). If you can change code of your application -- you probably can rewrite it to release lock or avoid it. Otherwise, you have to kill session to immediately unlock resources.

无论如何,阻塞会话应该以某种方式释放它的锁——通过提交或回滚它的事务。你可以等待它(可能很长时间)。如果您可以更改应用程序的代码 - 您可能可以重写它以释放锁定或避免锁定。否则,您必须终止会话以立即解锁资源。

回答by bhoot

No, Oracle 10g does not seem to resolve deadlocks automatically in practice. We did have dealocks and we had to clear the sessions manually.

不,Oracle 10g 在实践中似乎不会自动解决死锁。我们确实有dealocks,我们不得不手动清除会话。

This page can help in identifying if you have deadlocks Identifying and Resolving Oracle ITL Deadlock

此页面可以帮助确定您是否有死锁 识别和解决 Oracle ITL 死锁