博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优
阅读量:5021 次
发布时间: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/4206209.html

你可能感兴趣的文章
Javascript 清除文本框、文本域中的 HTML 代码
查看>>
第26月第28天 avplayer cache
查看>>
LeetCode Integer Replacement
查看>>
node 图片验证码
查看>>
(转)MVC3+EntityFramework实践笔记
查看>>
Executor
查看>>
Ubuntu14.04终端主机名+用户名修改配色方案
查看>>
Codeforces Round #189 (Div. 1) C - Kalila and Dimna in the Logging Industry 斜率优化dp
查看>>
HTML5中的Canvas路径
查看>>
nc工具使用
查看>>
浅析toString()和toLocaleString()的区别
查看>>
学习活动图的制作
查看>>
react-native v0.29.x 后 Android 平台部分第三方组件无法使用的问题
查看>>
xcode创建应用图标
查看>>
Graphics 绘图
查看>>
配置阿里云镜像源
查看>>
Nginx(PHP/fastcgi)的PATH_INFO问题
查看>>
[原创软件]考勤查询工具
查看>>
android 系统的一些基础知识点
查看>>
找到并替换 字符串中最后一个(不一定是末尾最后一个) 指定字符
查看>>