2009年03月13日

oracle 9i stats 操作

oracle_9i_dbms_stats_操作oracle 9i stats 操作
目地: 保存 table 的 status ,可在做了 analyze 後,產生的 plan 效能異常低落時可還原之前的 status

oracle_9i_dbms_stats_操作建立保存 status
exec dbms_stats.create_stat_table('BNQUSER','STATS_TABLE');
desc stats_table;
note :
BNQUSER : schema name
STATS_TABLE : 自定的存放 status 的 table

exec DBMS_STATS.GATHER_TABLE_STATS('BNQUSER','ALERT',cascade=>true,estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE,stattab=>'STATS_TABLE',statid=>'bin_test1');
note: 把 bnquser 下面的 alert 這個 table 做 analyze 動作,並把 staus 存放於 stata_table 這個 table 裏,並給於他一個 id,以方便日後重新匯入時較好找

select * from stats_table;
note:這時裏面應該會有幾筆資料

select last_analyzed from user_tables where table_name ='ALERT';
note : 查看一下剛才做的 analyze 是否真的有生效

---- 測試開始 ----
exec DBMS_STATS.DELETE_TABLE_STATS('BNQUSER','ALERT');
note : 刪除 status

select last_analyzed from user_tables where table_name ='ALERT';
note : 應該要為 null ,如有值的話,那就是有問題,請回頭檢查

exec DBMS_STATS.GATHER_TABLE_STATS('BNQUSER','ALERT',cascade=>true,estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE,stattab=>'STATS_TABLE',statid=>'bin_test2');
note : 重新 analyze 並給他另一個新的 statid

select last_analyzed from user_tables where table_name ='ALERT';
note : 再次查看最後 analyze 的時間正確

exec DBMS_STATS.IMPORT_TABLE_STATS('BNQUSER','ALERT',STATTAB=>'STATS_TABLE',STATID=>'BIN_TEST1');
note : 匯入之前做過的 status ,我前面做過的是  bin_test1

select last_analyzed from user_tables where table_name ='ALERT';
note : 查看時間應該要為  bin_test1 所做的時間點才對 


Posted by my_work at 樂多Roodo! │15:00 │回應(0)引用(0)DB
樂多分類:網路/3C 共同主題:Oracle 工具:編輯本文
標籤:Oracle
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/8493785