許多情況下,由于數據庫的變更或遷移,會導致數據庫中的對象失效。由于對象之間可能存在複雜的倚賴關系,所以手工編譯通常無法順利通過。 本文將詳細將詳細介紹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的具體操作方式了。