oracle實用sql(2)--segment advisor
segment advisor可以幫助分析表或索引的碎片,行連結問題.透過對問題表或索引收縮,移動或重建後減少儲存空間提高查詢速度.
點選(此處)摺疊或開啟
-
--os:centos 6.6
-
--db:oracle 11.2.0.4
-
-
--建測試表
-
create table scott.t_test01 as select * from dba_objects;
-
--插入資料
-
insert into scott.t_test01 select * from scott.t_test01;
-
commit;
-
insert into scott.t_test01 select * from scott.t_test01;
-
commit;
-
insert into scott.t_test01 select * from scott.t_test01;
-
commit;
-
--刪除一些資料
-
delete from scott.t_test01 where rownum<300000;
-
commit;
-
-
--建立執行scott.T_TEST01的segment advisor task
-
declare
-
v_id number;
-
v_task_name varchar2(100);
-
v_object_owner varchar2(50):='SCOTT';
-
v_object_name varchar2(50):='T_TEST01';
-
v_object_type varchar2(50):='TABLE';
-
begin
-
dbms_advisor.create_task
-
(advisor_name => 'Segment Advisor'
-
,task_id => v_id
-
,task_name => v_task_name
-
,task_desc => v_object_type||' '||v_object_owner||'.'||v_object_name
-
,template => null
-
,is_template => 'FALSE');
-
dbms_output.put_line('task_id:'||v_id);
-
dbms_advisor.create_object
-
(task_name => v_task_name
-
,object_type => v_object_type
-
,attr1 => v_object_owner
-
,attr2 => v_object_name
-
,attr3 => null
-
,attr4 => null
-
,attr5 => null
-
,object_id => v_id);
-
dbms_advisor.set_task_parameter
-
(task_name => v_task_name
-
,parameter => 'RECOMMEND_ALL'
-
,value => 'TRUE');
-
dbms_advisor.set_task_parameter
-
(task_name => v_task_name
-
,parameter => 'MODE'
-
,value => 'COMPREHENSIVE');
-
dbms_advisor.set_task_parameter
-
(task_name => v_task_name
-
,parameter => 'TIME_LIMIT'
-
,value => 'UNLIMITED');
-
dbms_advisor.execute_task
-
(task_name => v_task_name);
-
end;
-
--輸入任務id
-
/*task_id:21*/
-
-
--根據上一步輸出的task_id檢視segment advisor任務資訊
-
SELECT at.task_id, at.task_name, at.description, count(*) object_count, at.status, at.status_message,
-
at.pct_completion_time, at.created, at.last_modified,
-
at.execution_start, at.execution_end, at.owner, at.how_created
-
FROM dba_advisor_tasks at, dba_advisor_objects ao
-
WHERE at.task_id = ao.task_id
-
AND at.task_id=21
-
AND at.owner = ao.owner
-
GROUP BY at.task_id, at.task_name, at.description, at.status, at.status_message,
-
at.pct_completion_time, at.created, at.last_modified,
-
at.execution_start, at.execution_end, at.owner, at.how_created;
-
-
--根據task_id檢視segment advisor
-
SELECT af.owner task_owner, af.task_name, ao.type Object_Type,
-
ao.attr1 object_owner, ao.attr2 object_name,
-
ao.attr3 subobject_name, to_char(ao.attr4) Tablespace_Name,
-
af.message, af.more_info, to_char(ao.task_id) task_id, to_char(ao.object_id) object_id
-
FROM dba_advisor_findings af, dba_advisor_tasks at,
-
dba_advisor_objects ao
-
WHERE af.task_id = at.task_id
-
AND af.task_id=21
-
AND af.owner = at.owner
-
AND af.task_id = ao.task_id
-
AND ao.object_id = af.object_id;
-
-
--根據task_id檢視segment advisor recommendations
-
SELECT aa.task_id, aa.object_id, aa.attr1, aa.attr2, aa.attr3,
-
initcap(ar.annotation_status) status, ar.rec_id
-
FROM dba_advisor_actions aa, dba_advisor_tasks at,
-
dba_advisor_recommendations ar
-
WHERE aa.task_id = at.task_id
-
AND aa.task_id=21
-
AND aa.owner = at.owner
-
AND ar.task_id = at.task_id
- AND ar.rec_id = aa.rec_id;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-2113728/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Segment AdvisorOracle
- oracle實用sql(8)--segment show spaceOracleSQL
- oracle實用sql(4)--undo advisorOracleSQL
- oracle實用sql(3)--sql tuning advisorOracleSQL
- Oracle SQL優化之sql tuning advisorOracleSQL優化
- Oracle SQL優化之sql tuning advisor(STA)OracleSQL優化
- SQL Access Advisor 與SQL Tuning AdvisorSQL
- ORACLE SQL TUNING ADVISOR 使用方法OracleSQL
- Oracle 11 sql tuning advisor sql access advisor關閉以及job檢視與停止OracleSQL
- oracle SQL最佳化器SQL Tuning Advisor (STA)OracleSQL
- Oracle SQL最佳化之sql tuning advisor(STA)OracleSQL
- SQL Access Advisor、SQL Tuning Advisor 測試SQL
- sql tuning advisor和sql access advisor區別SQL
- SQL Repair AdvisorSQLAI
- SQL Access Advisor!SQL
- Oracle Undo SegmentOracle
- 手工執行sql tuning advisor和sql access advisorSQL
- Oracle優化案例-關閉auto space advisor和sql tuning advisor(十九)Oracle優化SQL
- zt_Segment Advisor監控物件的碎片程度並回收物件
- [原創]ORACLE SQL TUNING ADVISOR 使用方法OracleSQL
- SQL Access Advisor(zt)SQL
- SQL TUNING ADVISORSQL
- SQL Access Advisor 概要SQL
- 使用dbms_advisor來執行sql access advisorSQL
- SQL Access Advisor的 DBMS_ADVISOR.QUICK_TUNE 使用SQLUI
- [Oracle Script] Rollback Segment UsageOracle
- Oracle-Segment space managementOracle
- Oracle Data Recovery AdvisorOracle
- Advisor Webcasts for Oracle DatabaseWebASTOracleDatabase
- oracle實用sql(6)--tablespace/datafile resizeOracleSQL
- SQL Tuning Advisor簡介SQL
- 使用sql tuning advisor最佳化sqlSQL
- Oracle OCP 1Z0 053 Q258(SQL Repair Advisor)OracleSQLAI
- Oracle OCP IZ0-053 Q232(sql access advisor)OracleSQL
- Oracle自帶工具sql優化集-SQL Tuning Advisor (使用心得體會)OracleSQL優化
- ORACLE LOB SEGMENT常規管理Oracle
- How to Shrink Undo Segment In Oracle DatabaseOracleDatabase
- oracle addm segment tuningOracle