重編譯 invalid 物件(轉)
DBA在一些場合下,要對無效的資料庫物件進行重新編譯.如果只是對all_objects等檢視中選出來的無效物件進行重新編譯,可能需要很多次:因為各個物件之間有依賴性的.這樣並不是一個很好的辦法.Raymond 在Recompiling invalid objects提到了如何有效地重新編譯無效物件.提到了三種比較有效地方法(
- 利用$ORACLE_HOME/rdbms/admin下的utlrp.sql指令碼編譯.一般都是在遷移或者升級之後執行該指令碼.Raymond說該方法的不足之處在於這個指令碼是對整個資料庫中的物件進行重新編譯的,所以不可取.有網友指出utlrp.sql 實際上是呼叫utlrcmp.sql的這樣就可以用utl_recomp包來做嘍(這樣就是比較好的方法).
- 用DBMS_UTILITY包來進行編譯.但是也有一定的侷限性.
- Raymond提到了自己的解決辦法: 不過也立刻有人指出來,這樣對 View 的重新編譯是無能為力的(ALTER_COMPILE只能處理:PACKAGE, PACKAGE BODY, PROCEDURE, FUNCTION, TRIGGER).參見下面的指令碼
CREATE OR REPLACE PROCEDURE RECOMPILE_SCHEMA IS v_Type USER_OBJECTS.OBJECT_TYPE%TYPE; v_Name USER_OBJECTS.OBJECT_NAME%TYPE; v_Stat USER_OBJECTS.STATUS%TYPE; CURSOR c_Obj IS SELECT BASE FROM (SELECT A.OBJECT_ID BASE , B.OBJECT_ID REL FROM USER_OBJECTS A , USER_OBJECTS B , SYS.DEPENDENCY$ C WHERE A.OBJECT_ID = C.D_OBJ# AND B.OBJECT_ID = C.P_OBJ# AND A.OBJECT_TYPE IN ('PACKAGE', 'PROCEDURE', 'FUNCTION', 'PACKAGE BODY', -- 'VIEW', 'TRIGGER') AND B.OBJECT_TYPE IN ('PACKAGE', 'PROCEDURE', 'FUNCTION', 'PACKAGE BODY', -- 'VIEW', 'TRIGGER') AND NOT A.OBJECT_NAME = B.OBJECT_NAME) OBJECTS CONNECT BY BASE = PRIOR REL GROUP BY BASE ORDER BY MAX(LEVEL) DESC; BEGIN -- loop through all objects in order of dependancy. FOR c_Row IN c_Obj LOOP -- select the objects attributes (type, name & status). SELECT OBJECT_TYPE , OBJECT_NAME , STATUS INTO v_Type , v_Name , v_Stat FROM USER_OBJECTS WHERE OBJECT_ID = c_Row.BASE; -- if the OBJECT is INVALID, recompile it. IF v_Stat = 'INVALID' THEN DBMS_DDL.ALTER_COMPILE(v_Type, USER, v_Name); END IF; END LOOP; -- Recompile all remaining INVALID OBJECTS (all those without dependencies). FOR c_Row IN ( SELECT OBJECT_TYPE , OBJECT_NAME FROM USER_OBJECTS WHERE STATUS = 'INVALID' AND OBJECT_TYPE IN ('PACKAGE', 'PROCEDURE', 'FUNCTION', 'TRIGGER', 'PACKAGE BODY', -- 'VIEW', 'TRIGGER') ) LOOP DBMS_DDL.ALTER_COMPILE(c_Row.OBJECT_TYPE, USER, c_Row.OBJECT_NAME); END LOOP; END RECOMPILE_SCHEMA;
呼叫 utl_recomp 包是比較好的做法.需要 sys 許可權.Rem EXAMPLES Rem 1. Recompile all objects sequentially: Rem execute utl_recomp.recomp_serial(); Rem Rem 2. Recompile objects in schema SCOTT sequentially: Rem execute utl_recomp.recomp_serial('SCOTT'); Rem Rem 3. Recompile all objects using 4 parallel threads: Rem execute utl_recomp.recomp_parallel(4); Rem Rem 4. Recompile objects in schema JOE using the number of threads Rem specified in the paramter JOB_QUEUE_PROCESSES: Rem execute utl_recomp.recomp_parallel(NULL, 'JOE'); Rem Rem 5. Recompile all objects using 2 parallel threads, but allow Rem other applications to use the job queue concurrently: Rem execute utl_recomp.recomp_parallel(2, NULL, Rem utl_recomp.share_job_queue); Rem Rem 6. Restore the job queue after a failure in recomp_parallel: Rem execute utl_recomp.restore_job_queue();
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242209/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mingw GCC 編譯OpenCV報錯: Project files may be invalidGC編譯OpenCVProject
- C++物件模型:編譯分析C++物件模型編譯
- ORACLE編譯失效物件小結Oracle編譯物件
- mingw編譯jsoncpp 轉載編譯JSON
- 高峰期謹慎編譯業務物件編譯物件
- 【轉】MySQL原始碼編譯安裝MySql原始碼編譯
- react知識(二)重寫JSX編譯原理ReactJS編譯原理
- [轉]:xmake編譯配置過程詳解編譯
- GraphJin:GraphQL自動編譯轉為SQL編譯SQL
- Java編譯與反編譯Java編譯
- libusb android ndk編譯--編譯mipsAndroid編譯
- hadoop編譯—+2.x編譯Hadoop編譯
- N1064編譯鏈編譯編譯
- JS json字串轉物件、物件轉字串JSON字串物件
- PHP MySQL (二)物件導向 增刪查改 (預編譯方式)PHPMySql物件編譯
- 編譯編譯
- 將HTML字串編譯為虛擬DOM物件的基礎實現HTML字串編譯物件
- 程式碼線上編譯器(上)- 編輯及編譯編譯
- hi3520d核心編譯編譯方法編譯
- Make編譯之編譯32bit ffmpeg編譯
- 開源編譯工具和編譯軟體編譯
- 【閱讀筆記】Taro轉小程式編譯原始碼解析筆記編譯原始碼
- 編譯原理: Thompson 構造法(正規表示式 轉 NFA)編譯原理
- 編譯VIM編譯
- 編譯版本編譯
- 交叉編譯編譯
- 編譯googletest編譯Go
- 編譯宏編譯
- 編譯 ncurses編譯
- freeswitch 編譯編譯
- 編譯原理編譯原理
- 編譯 zsh編譯
- 編譯 git編譯Git
- openXLSX編譯編譯
- webrtc編譯Web編譯
- acl 編譯編譯
- 物件轉型物件
- GCC編譯過程(預處理->編譯->彙編->連結)GC編譯