避免在编译 Oracle 包时挂起

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31045604/
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-19 02:55:46  来源:igfitidea点击:

Avoid hanging while compiling Oracle package

sqloracleplsqloracle11g

提问by Data-Base

we have a situation where the compiling of a package takes for ever! if we compile the package with a new name then it works!

我们有一种情况,包的编译需要永远!如果我们用新名称编译包,那么它就可以工作了!

what I understood, Compiling hangs because of locks on the package!

据我了解,由于包上的锁,编译挂起!

something like this might help identify the problem!

这样的事情可能有助于确定问题!

    SELECT s.sid,
       l.lock_type,
       l.mode_held,
       l.mode_requested,
       l.lock_id1,
    FROM   dba_lock_internal l,
       v$session s
    WHERE s.sid = l.session_id
    AND UPPER(l.lock_id1) LIKE '%PROCEDURE_NAME%'
    AND l.lock_type = 'Body Definition Lock';

also this

还有这个

select 
   x.sid 
from 
   v$session x, v$sqltext y
where 
   x.sql_address = y.address
and 
   y.sql_text like '%PROCEDURE_NAME%';

is it only 'body Definition Lock'that prevent the compiling? is there any other lock types that prevent the compiling?

只有'body Definition Lock'会阻止编译吗?是否有任何其他锁定类型阻止编译?

how to avoid the locks and do the compiling? by killing the sessions only? is there something else?

如何避免锁定并进行编译?仅通过杀死会话?还有别的吗?

回答by HAL 9000

You might want to look into Edition-based Redefinitionwhich will let you create a new revision, compile new versions without being blocked by other sessions currently using the packages and enable the new revision later on.

您可能想要研究基于版本的重新定义,它可以让您创建新修订、编译新版本而不会被当前使用包的其他会话阻止,并在以后启用新修订。

回答by Vishal

Basically, if someone or something else (any other scheduled job) is executing the package, then you won't be able to perform the recompile. To get around this, you need to identify the locking session and kill it. Killing session is that option we have, dbms_lock is only useful on locks created by dbms_lock You cannot just "unlock" some object - the lock is there for an extremely relevant reason.

基本上,如果有人或其他东西(任何其他预定作业)正在执行包,那么您将无法执行重新编译。为了解决这个问题,您需要识别锁定会话并终止它。终止会话是我们拥有的选项,dbms_lock 仅对由 dbms_lock 创建的锁有用。您不能只是“解锁”某个对象——该锁的存在是出于极其相关的原因。

Other lock you may come across is Dependency Lock: Consider Procedure-1 from Package A contains a call to Procedure-2 from Package B. procedure-1 from Package A is running. Then you may get lock while compiling Package-B

您可能会遇到的其他锁是Dependency Lock:请考虑包 A 中的过程 1 包含对包 B 中的过程 2 的调用。包 A 中的过程 1 正在运行。那么你在编译 Package-B 时可能会被锁定