您好,登錄后才能下訂單哦!
這篇文章主要介紹“Oracle自動收集統計信息怎么實現”,在日常操作中,相信很多人在Oracle自動收集統計信息怎么實現問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Oracle自動收集統計信息怎么實現”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
在Oracle的11g版本中提供了統計數據自動收集的功能。在部署安裝11g Oracle軟件過程中,其中有一個步驟便是提示是否啟動這個功能(默認是啟用這個功能)。
一、查看自動收集統計信息的任務及狀態:
SQL> select client_name,status from dba_autotask_client;
CLIENT_NAME STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection ENABLED
auto space advisor ENABLED
sql tuning advisor DISABLED
SQL>
二、禁止自動收集統計信息的任務
SQL> exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto optimizer stats collection',operation => NULL,window_name => NULL);
PL/SQL procedure successfully completed.
SQL> select client_name,status from dba_autotask_client;
CLIENT_NAME STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection DISABLED
auto space advisor ENABLED
sql tuning advisor DISABLED
三、啟用自動收集統計信息的任務
SQL> exec DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'auto optimizer stats collection',operation => NULL,window_name => NULL);
PL/SQL procedure successfully completed.
SQL> select client_name,status from dba_autotask_client;
CLIENT_NAME STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection ENABLED
auto space advisor ENABLED
sql tuning advisor DISABLED
四、獲得當前自動收集統計信息的執行時間:
SQL> col WINDOW_NAME format a20
SQL> col REPEAT_INTERVAL format a70
SQL> col DURATION format a20
SQL> set line 180
SQL> select t1.window_name,t1.repeat_interval,t1.duration
from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2
where t1.window_name=t2.window_name and t2.window_group_name in ('MAINTENANCE_WINDOW_GROUP','BSLN_MAINTAIN_STATS_SCHED');
WINDOW_NAME REPEAT_INTERVAL DURATION
-------------------- ---------------------------------------------------------------------- --------------------
WEDNESDAY_WINDOW freq=daily;byday=WED;byhour=22;byminute=0; bysecond=0 +000 04:00:00
SATURDAY_WINDOW freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0 +000 20:00:00
THURSDAY_WINDOW freq=daily;byday=THU;byhour=22;byminute=0; bysecond=0 +000 04:00:00
TUESDAY_WINDOW freq=daily;byday=TUE;byhour=22;byminute=0; bysecond=0 +000 04:00:00
SUNDAY_WINDOW freq=daily;byday=SUN;byhour=6;byminute=0; bysecond=0 +000 20:00:00
MONDAY_WINDOW freq=daily;byday=MON;byhour=22;byminute=0; bysecond=0 +000 04:00:00
FRIDAY_WINDOW freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0 +000 04:00:00
7 rows selected.
其中:WINDOW_NAME:任務名 REPEAT_INTERVAL:任務重復間隔時間 DURATION:持續時間
五.修改統計信息執行的時間:
1.停止任務:
SQL> BEGIN
DBMS_SCHEDULER.DISABLE(
name => '"SYS"."THURSDAY_WINDOW"',
force => TRUE); --停止任務是true
END;
/
SQL>
2.修改任務的持續時間,單位是分鐘:
SQL> BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => '"SYS"."THURSDAY_WINDOW"',
attribute => 'DURATION',
value => numtodsinterval(60,'minute'));
END;
/
3.開始執行時間,BYHOUR=2,表示2點開始執行:
SQL> BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => '"SYS"."THURSDAY_WINDOW"',
attribute => 'REPEAT_INTERVAL',
value => 'freq=daily;byday=THU;byhour=10;byminute=40;bysecond=0');
END;
/
4.開啟任務:
SQL> BEGIN
DBMS_SCHEDULER.ENABLE(
name => '"SYS"."THURSDAY_WINDOW"');
END;
/
5.查看修改后的情況:
SQL> select t1.window_name,t1.repeat_interval,t1.duration
from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2
where t1.window_name=t2.window_name and t2.window_group_name in ('MAINTENANCE_WINDOW_GROUP','BSLN_MAINTAIN_STATS_SCHED');
WINDOW_NAME REPEAT_INTERVAL DURATION
-------------------- ---------------------------------------------------------------------- --------------------
WEDNESDAY_WINDOW freq=daily;byday=WED;byhour=22;byminute=0; bysecond=0 +000 04:00:00
SATURDAY_WINDOW freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0 +000 20:00:00
THURSDAY_WINDOW freq=daily;byday=THU;byhour=10;byminute=40;bysecond=0 +000 01:00:00
TUESDAY_WINDOW freq=daily;byday=TUE;byhour=22;byminute=0; bysecond=0 +000 04:00:00
SUNDAY_WINDOW freq=daily;byday=SUN;byhour=6;byminute=0; bysecond=0 +000 20:00:00
MONDAY_WINDOW freq=daily;byday=MON;byhour=22;byminute=0; bysecond=0 +000 04:00:00
FRIDAY_WINDOW freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0 +000 04:00:00
六.查看統計信息執行的歷史記錄
--維護窗口組
select * from dba_scheduler_window_groups;
--維護窗口組對應窗口
select * from dba_scheduler_wingroup_members
--維護窗口歷史信息
select* from dba_scheduler_windows
--查詢自動收集任務正在執行的job
select * from DBA_AUTOTASK_CLIENT_JOB;
--查詢自動收集任務歷史執行狀態
select * from DBA_AUTOTASK_JOB_HISTORY;
select * from DBA_AUTOTASK_CLIENT_HISTORY;
到此,關于“Oracle自動收集統計信息怎么實現”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。