重新编译 Oracle Packages 安全吗
你好 我们有一个基于 Oracle 的第三方应用程序,附带预编译的二进制(包装)包。 但是当我在 Oracle SQL Developer 中编译它们时(右键单击 -> 全部编译),它们变得无效。
重新编译是一个安全的操作,没有副作用吗?
Hi
We have a third party oracle based application, that ships with precompiled binary(wrapped) packages.
But when I compile them in Oracle SQL Developer (right click -> compile all), they get invalidated.
Is recompiling a safe operation with no side effects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
主要的副作用是,如果您编译另一个包所依赖的包,则您可能会面临使任何现有会话的依赖包无效的风险 - 即使编译没有错误。这对于会话寿命较短的应用程序来说很好,但对于会话寿命较长的应用程序来说这是一个问题。如果您在 JDBC 中使用连接池,则缓存的会话将长期存在并且可能会失效。您必须刷新缓存的会话以避免错误。
您要查找的错误是“ORA-04068:包的现有状态已被丢弃”。
有关详细信息,请参阅此处。
特别是对于 SQL Developer - 它不能很好地处理包装包的重新编译。如果您要重新编译它们,请尝试其他工具,例如 TOAD 或 PL/SQL Developer,或使用 SQL Plus 命令行中的“alter package”命令。
The major side effect is that if you compile a package which another package is dependant upon you risk invalidating the dependant package for any existing sessions - even if the compile has no errors. This is fine for applications where sessions are short-lived but for applications where sessions are long-lived this is a problem. If you're using connection pools in JDBC the cached sessions will be long lived and likely invalidated. You have to flush the cached sessions to avoid the error.
The error you're looking for is "ORA-04068: existing state of packages has been discarded".
See here for more info.
Specifically with regards to SQL Developer - it does not handle recompilation of wrapped packages well. If you are going to recompile them try another tool like TOAD or PL/SQL Developer or use the "alter package" command in the SQL Plus command line.
就我个人而言,我会避免“重新编译全部”(在 SQL Developer 或 TOAD 中)——尤其是在任何从其他用户或软件打开数据库连接的环境中。
在大多数情况下,您可能只想重新编译无效对象。
如果您使用的是 Oracle 10 或更高版本,则有两个内置包可以执行此操作(尽管您的角色可能无法在不与 DBA 交谈的情况下访问它们)。
UTL_RECOMP 是新的首选方法。 DBMS_UTILITY 存在于 Oracle 的早期版本中,但总是会编译所有内容 -compile_all 是一个新的可选标志,它让我们告诉它只编译无效的项目。
如果您使用的是 10 之前的版本,我建议滚动您自己的编译无效过程 - 我发现将其编写为可以通过 DBMS_JOB 提交的作业,然后通过 DBMS_SMTP(Ora 10 中的 DBMS_MAIL)通过电子邮件返回进度是很有用的。
我的工作使用以下 SQL 递归地尝试编译所有依赖项均有效的 INVALID 对象,直到迭代之间没有任何更改。
Personally, I'd avoid 'Recompile All' (in SQL Developer or TOAD) - especially in any environment where you have open database connections from other users or software.
In most situations you probably just want to recompile Invalid objects.
If you're on Oracle 10 or above, there are two in-built packages that will do this (although they may not be accessible to your role without speaking to your DBA).
UTL_RECOMP is the new preferred way to do it. DBMS_UTILITY exists on earlier versions of Oracle, but would always compile everything - compile_all is a new optional flag, that lets us tell it to compile only invalid items.
If you are on an earlier version than 10, I'd suggest rolling your own compile invalid procedure - I found it useful to write this as a job that can be submitted via DBMS_JOB and then emails back progress via DBMS_SMTP (DBMS_MAIL in Ora 10).
My job recursively tries to compile INVALID objects where all dependencies are VALID, using the following SQL, until there are no changes between iterations.
大多数第三方应用程序建议您不要编辑/编译其对象,除非他们的支持告诉您这样做。
由于您不知道所有依赖对象,我建议您在修改第三方应用程序的对象之前先联系第三方应用程序的支持团队。如果它是捆绑应用程序,则简单地重新编译 oracle 对象可能会使其他层中的依赖应用程序/服务无效。
Most third party applications advice you against editing/compiling their objects unless of course their support tells you to do so.
Since you do not know all the dependent objects, I would suggest you contact the third-part application's support team first before modifying their objects. If it is a bundled application, simply recompiling oracle objects may leave dependent applications/services in other tiers invalid.
如果您的软件包无效,那么它们实际上是无效的,因为它们将不再工作吗?
尝试使用 sqlplus 重新编译无效的包体。
如果您收到消息“编译时有错误”,
这将提供有关错误的一些信息。
一般来说,重新编译打包的包就可以了。应该不是问题。
If your packages get invalid are they actually invalid in the sense that they won't work anymore?
Try to recompile an invalid package body using sqlplus.
If you get the message "compiled with errors"
This will give some information about the error.
Generally speaking it is fine to recompile wrapped packages. Should not be a problem.