电脑技术学习

按照顺序或依赖关系重新编译失效的对象

dn001
许多情况下,由于数据库的变更或迁移,会导致数据库中的对象失效。由于对象之间可能存在复杂的倚赖关系,所以手工编译通常无法顺利通过。 本文将详细将详细介绍Oracle提供的一个用于按照顺序/依赖关系重新编译失效对象的脚本。

脚本:

$ORACLE_HOME/rdbms/admin/utlrp.sql

其中会调用:

$ORACLE_HOME/rdbms/admin/utlrcmp.sql

在utlrp.sql脚本中,Oracle的注释:

Rem utlrp.sql - UTiLity script Recompile invalid Pl/sql modules

Rem

Rem DESCRIPTION

Rem This is a fairly general script that can be used at any time to

Rem recompile all existing invalid PL/SQL modules in a database.

Rem

Rem If run as one of the last steps during migration/upgrade/downgrade

Rem (see the README notes for your current release and the Oracle

Rem Migration book), this script will validate all PL/SQL modules

Rem (procedures, functions, packages, triggers, types, views, libraries)

Rem during the migration step itself.

Rem

Rem Although invalid PL/SQL modules get automatically recompiled on use,

Rem it is useful to run this script ahead of time (e.g. as one of the last

Rem steps in your migration), since this will either eliminate or

Rem minimize subsequent latencies caused due to on-demand automatic

Rem recompilation at runtime.

Rem

Rem Oracle highly recommends running this script towards the end of

Rem of any migration/upgrade/downgrade.

注:上面这个示例是一个通用脚本,可以在任意时候运行以重新编译数据库失效对象。通常我们会在Oracle的升级指导中看到这个脚本,Oracle强烈推荐在migration/upgrade/downgrade之后,通过运行此脚本编译失效对象。 但是注意,Oracle提醒,此脚本需要用SQLPLUS以SYSDBA身份运行,并且当时数据库中最好不要有活动事物或DDL操作,否则极容易导致死锁的出现(这是很容易理解的)。 只要仔细阅读一下utlrcmp.sql脚本,大家就会知道Oracle的具体操作方式了。