怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优
1》。这里简单举个样例来说明DBMS_SQLTUNE 的使用
首先现运行下某个想要调优的sql,然后获取sqlidSQL> select * from v$sqltext where sql_text like 'select * from dual%';
ADDRESS HASH_VALUE SQL_ID COMMAND_TYPE PIECE SQL_TEXT
---------------- ---------- ------------- ------------ ---------- ---------------------------------------------------------------- 0000000069BC2BE0 942515969 a5ks9fhw2v9s1 3 0 select * from dual1 row selected.
2》。执行sqltrpt 脚本
sqltrpt 里默认记录两种数据 15 Most expensive SQL in the cursor cache 15 Most expensive SQL in the workload repository 当然这里我们也能够手动输入我们想要调整的其它sql SQL> @?/rdbms/admin/sqltrpt 15 Most expensive SQL in the cursor cache ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL_ID ELAPSED SQL_TEXT_FRAGMENT
------------- ---------- ------------------------------------------------------- b6usrg82hwsa3 97.69 call dbms_stats.gather_database_stats_job_proc ( ) 6gvch1xu9ca3g 38.88 DECLARE job BINARY_INTEGER := :job; next_date DATE := : cvn54b7yz0s8u 21.34 select /*+ index(idl_ub1$ i_idl_ub11) +*/ piece#,length dbvkky621gqtr 16.22 SELECT /*+ parallel */ EXTRACTVALUE(VALUE(T), '/select_ 3ktacv9r56b51 9.68 select owner#,name,namespace,remoteowner,linkname,p_tim ga9j9xk5cy9s0 7.01 select /*+ index(idl_sb4$ i_idl_sb41) +*/ piece#,length 39m4sx9k63ba2 6.09 select /*+ index(idl_ub2$ i_idl_ub21) +*/ piece#,length 8swypbbr0m372 5.90 select order#,columns,types from access$ where d_obj#=: db78fxqxwxt7r 5.62 select /*+ rule */ bucket, endpoint, col#, epvalue from g5m0bnvyy37b1 5.38 select sql_id, plan_hash_value, bucket_id, begin 424h0nf7bhqzd 5.02 SELECT sqlset_row(sql_id, force_matching_signature,SQL_ID ELAPSED SQL_TEXT_FRAGMENT
------------- ---------- ------------------------------------------------------- 32hbap2vtmf53 4.31 select position#,sequence#,level#,argument,type#,charse 9s0xa5dgvuq55 4.29 DECLARE job BINARY_INTEGER := :job; next_date TIMESTAM d4taszv1bpc0w 4.02 DECLARE cnt NUMBER; bid NUMBER; eid 96g93hntrzjtr 3.78 select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null15 Most expensive SQL in the workload repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL_ID ELAPSED
------------- ---------- SQL_TEXT_FRAGMENT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- b6usrg82hwsa3 198.03 call dbms_stats.gather_database_stats_job_proc ( )6gvch1xu9ca3g 169.58
DECLARE job BINARY_INTEGER := :job; next_date DATE := :1jqcpqf8fpdr8 139.13
select count(*) from dba_objects a, dba_objects b where SQL_ID ELAPSED ------------- ---------- SQL_TEXT_FRAGMENT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- cvn54b7yz0s8u 82.99 select /*+ index(idl_ub1$ i_idl_ub11) +*/ piece#,lengthf6cz4n8y72xdc 63.29
SELECT space_usage_kbytes FROM v$sysaux_occupants WH6mcpb06rctk0x 44.62
call dbms_space.auto_space_advisor_job_proc ( ) SQL_ID ELAPSED ------------- ---------- SQL_TEXT_FRAGMENT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 3ktacv9r56b51 42.79 select owner#,name,namespace,remoteowner,linkname,p_tim12a2xbmwn5v6z 39.87
select owner, segment_name, blocks from dba_segments wh05s9358mm6vrr 37.59
begin dbms_feature_usage_internal.exec_db_usage_samplin SQL_ID ELAPSED ------------- ---------- SQL_TEXT_FRAGMENT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5zruc4v6y32f9 33.12 DECLARE job BINARY_INTEGER := :job; next_date TIMESTAMdbvkky621gqtr 31.66
SELECT /*+ parallel */ EXTRACTVALUE(VALUE(T), '/select_63n9pwutt8yzw 28.03
MERGE /*+ dynamic_sampling(ST 4) dynamic_sampling_est_c SQL_ID ELAPSED ------------- ---------- SQL_TEXT_FRAGMENT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7xa8wfych4mad 27.86 SELECT SUM(blocks) FROM x$kewx_segments WHERE segment8swypbbr0m372 26.81
select order#,columns,types from access$ where d_obj#=:db78fxqxwxt7r 26.37
select /*+ rule */ bucket, endpoint, col#, epvalue from Specify the Sql id ~~~~~~~~~~~~~~~~~~ Enter value for sqlid: a5ks9fhw2v9s1Sql Id specified: a5ks9fhw2v9s1
Tune the sql -----------------------------------------------这里为sql tuning advisor 的 建议
~~~~~~~~~~~~GENERAL INFORMATION SECTION
------------------------------------------------------------------------------- Tuning Task Name : TASK_219 Tuning Task Owner : SYS Workload Type : Single SQL Statement Scope : COMPREHENSIVE Time Limit(seconds): 1800 Completion Status : COMPLETED Started at : 05/17/2014 17:07:54 Completed at : 05/17/2014 17:07:54-------------------------------------------------------------------------------
Schema Name: SYSSQL ID : a5ks9fhw2v9s1
SQL Text : select * from dual-------------------------------------------------------------------------------
There are no recommendations to improve the statement.-------------------------------------------------------------------------------
备注:在生产环境下没有測试过,不知道Sql Tuning Advisor 的效果怎样,这个有待然后验证下!