ORACLE故障排除--注意事項

 
1.       在系統良好運作時, 進行一次Statspack! 並將結果文件保存作爲以後的判斷標準.
2.       ORACLE中建立一張存放有執行計劃的表
腳本如下:
 
--建立一張計劃表
create table plan_hashes
( sql_text           varchar2(1000),
 hash_value         number,
 plan_hash_value    number,
 constraint plan_hashes_pk
 primary key(hash_value,sql_text,plan_hash_value)
)
organization index;
 
--將shared_pool中的語句插入計劃表
insert into plan_hashes( sql_text, hash_value, plan_hash_value )
select distinct sql_text,
       hash_value,
       plan_hash_value
 from v$sql
 where command_type in (
 /* DELETE */ 7,    /* INSERT */ 2,
 /* MERGE */ 189, /* SELECT */ 3,
 /* UPDATE */ 6 )
   and parsing_user_id <> 0
   and parsing_schema_id <> 0;
 
--查看當前shared pool中的執行計劃與計劃表的差異
select distinct sql_text,
       hash_value,
       plan_hash_value,
       decode( (select 1
                  from plan_hashes
                 where plan_hashes.hash_value = v$sql.hash_value
                   and plan_hashes.sql_text = v$sql.sql_text
                   and rownum = 1), 1, 'Changed', 'New' ) status
 from v$sql
 where (sql_text, hash_value, plan_hash_value)
not in (select sql_text, hash_value, plan_hash_value
           from plan_hashes)
   and command_type in (
 /* DELETE */ 7,    /* INSERT */ 2,
 /* MERGE */ 189, /* SELECT */ 3,
 /* UPDATE */ 6 )
   and parsing_user_id <> 0
   and parsing_schema_id <> 0
/
 
--shared_pool中新的執行計劃存入計劃表
insert into plan_hashes( sql_text, hash_value, plan_hash_value )
select distinct sql_text,
       hash_value,
       plan_hash_value
 from v$sql
 where (sql_text, hash_value, plan_hash_value)
not in (select sql_text, hash_value, plan_hash_value
           from plan_hashes)
   and command_type in (
 /* DELETE */ 7,    /* INSERT */ 2,
 /* MERGE */ 189, /* SELECT */ 3,
 /* UPDATE */ 6 )
   and parsing_user_id <> 0
   and parsing_schema_id <> 0
/
 
3.       找出差異
收集了之前的歷史資料,我們就能通過比對找出兩者之間的差別
 
4.       每次只更改一個問題
不要多個人同時更改多個問題,也不要一個人更改多個問題,這樣就無法確定到底是哪個變動解決了問題所在
 
5.       確認是否需要修改這個問題
改動一個問題之前要先確定目標,並且經過驗證(小規模的基準測試是必要的)之後才能動手
 
6.       做好備份
任何改動之前都需要進行備份,使系統能夠回退到改動前的狀態時必須的
 
7.       建立小型的測試用例
由於系統可能會很龐大,運行起來相當複雜耗時,所以需要儘可能多的剝離不需要的代碼,使用簡單,明瞭的測試用例重現錯誤!
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章