博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优
阅读量:5073 次
发布时间:2019-06-12

本文共 5691 字,大约阅读时间需要 18 分钟。



怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优

1》。这里简单举个样例来说明DBMS_SQLTUNE 的使用

首先现运行下某个想要调优的sql,然后获取sqlid

SQL> 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 dual

1 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, null

15 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#,length

f6cz4n8y72xdc      63.29

SELECT space_usage_kbytes  FROM  v$sysaux_occupants  WH

6mcpb06rctk0x      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_tim

12a2xbmwn5v6z      39.87

select owner, segment_name, blocks from dba_segments wh

05s9358mm6vrr      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 TIMESTAM

dbvkky621gqtr      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 segment

8swypbbr0m372      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: a5ks9fhw2v9s1

Sql 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: SYS

SQL ID     : a5ks9fhw2v9s1

SQL Text   : select * from dual

-------------------------------------------------------------------------------

There are no recommendations to improve the statement.

-------------------------------------------------------------------------------

备注:在生产环境下没有測试过,不知道Sql Tuning Advisor 的效果怎样,这个有待然后验证下!

转载于:https://www.cnblogs.com/gcczhongduan/p/4021013.html

你可能感兴趣的文章
获取元素
查看>>
proxy写监听方法,实现响应式
查看>>
第一阶段冲刺06
查看>>
十个免费的 Web 压力测试工具
查看>>
EOS生产区块:解析插件producer_plugin
查看>>
mysql重置密码
查看>>
jQuery轮 播的封装
查看>>
一天一道算法题--5.30---递归
查看>>
JS取得绝对路径
查看>>
排球积分程序(三)——模型类的设计
查看>>
python numpy sum函数用法
查看>>
php变量什么情况下加大括号{}
查看>>
linux程序设计---序
查看>>
【字符串入门专题1】hdu3613 【一个悲伤的exkmp】
查看>>
C# Linq获取两个List或数组的差集交集
查看>>
HDU 4635 Strongly connected
查看>>
ASP.NET/C#获取文章中图片的地址
查看>>
Spring MVC 入门(二)
查看>>
格式化输出数字和时间
查看>>
页面中公用的全选按钮,单选按钮组件的编写
查看>>