Oracle數據庫失效對象處理


近期對數據庫進行巡檢,發現數據庫業務用戶(非 SYS/Public)下存在失效對象。對失效對象進行分析,主要包括失效的視圖、物化視圖、函數、包、觸發器等。

思考:

基於以下原因,建議對失效對象進行處理:

1、通過失效的對象,可能能夠反推發現業務軟件問題(業務系統功能太多,可能存在測試不充分的問題);

2、如果失效對象太多,業務又頻繁調用的話,擔心影響數據庫性能(未進行測試,個人想法,如有錯誤請大家指正);

處理方式:

1、先搜索發現失效對象(在sys用戶下執行)

select owner, object_name, object_type, status  from dba_objects t  where status='INVALID'  order by t.owner,t.object_type;

2、對失效對象自動生成重編譯語句,進行重編譯

下面是為視圖、函數、物化視圖、包、觸發器的生成語句。

--自動生成視圖重新編譯語句
select owner, object_name, object_type, status  ,'alter view ' || t.owner||'.' || object_name || ' compile'||';'
from dba_objects t  
where status='INVALID' and t.object_type='VIEW'  order by t.owner,t.object_type;
--自動生成函數重新編譯語句
select owner, object_name, object_type, status  ,'alter FUNCTION ' || t.owner||'.' || object_name || ' compile'||';'
from dba_objects t  
where status='INVALID' and t.object_type='FUNCTION'  order by t.owner,t.object_type;
--自動生成視物化圖重新編譯語句
select owner, object_name, object_type, status  ,'alter MATERIALIZED VIEW ' || t.owner||'.' || object_name || ' compile'||';'
from dba_objects t  
where status='INVALID' and t.object_type='MATERIALIZED VIEW'  order by t.owner,t.object_type;
--自動生成包重新編譯語句
select owner, object_name, object_type, status  ,'alter PACKAGE ' || t.owner||'.' || object_name || ' compile'||';'
from dba_objects t  
where status='INVALID' and t.object_type='PACKAGE BODY'  order by t.owner,t.object_type;
--自動生成觸發器重新編譯語句
select owner, object_name, object_type, status  ,'alter TRIGGER ' || t.owner||'.' || object_name || ' compile'||';'
from dba_objects t  
where status='INVALID' and t.object_type='TRIGGER'  order by t.owner,t.object_type;

生成語句后復制處理批量執行即可。

3、重新編譯應該會解決掉一部分的失效對象,但是仍然會有部分對象無法通過重新編譯解決。對於這部分對象,需要進行人工的逐個分析,現場可以確認的進行確認處理(有用則修改,無用則刪除),現場不能確認的可以和研發確認,最終完成對失效對象處理的目的。

如果最終仍有部分無人可以確認,建議先暫時保留即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM