ORACLE SQL TUNING ADVISOR 使用方法
1 建立tunning task
2 执行task
3 显示tunning 结果
4 根据建议来运行相应的调优方法
下面来按照这个顺序来实施一遍:
1 建立测试表以及索引
SQL> CREATE TABLE test_sql_advisor AS SELECT OWNER,OBJECT_NAME,OBJECT_ID FROM DBA_OBJECTS;
Table created
SQL> select count(*) from test_sql_advisor;
COUNT(*)
----------
757229
2 授权 SYSDBA权限登录
SQL> GRANT ADVISOR TO noap;
Grant succeeded
SQL> GRANT SELECT_CATALOG_ROLE TO noap;
Grant succeeded
SQL> GRANT EXECUTE ON DBMS_SQLTUNE TO noap;
Grant succeeded
3 CREATE TASK
You can create tuning tasks from the following:
- SQL statement selected by SQL identifier from the cursor cache
- SQL Tuning Set containing multiple statements
- Text of a single SQL statement
- SQL statement selected by SQL identifier from the Automatic Workload Repository.
上面翻译可以理解为建立调优任务可以通过以下几种方式:
1 通过取得来自cursor cache 的sql_id来指定sql语句来建立任务
2 sql调优的集合包括的多个语句来建立任务
3 单一sql语句的文本来建立任务
4 通过用awr中相应的sql_id来取得sql语句建立任务
建立任务主要用的是DBMS_SQLTUNE.CREATE_TUNING_TASK 这个函数,该函数存在重写,下面的贴出来接口
1 基于SQL文本建立任务
-------------------- create_tuning_task - sql text format ------------------
-- NAME:
-- create_tuning_task - CRATE a TUNING TASK in order to tune a single SQL
-- statement (sql text format)
--
-- DESCRIPTION
-- This function is called to prepare the tuning of a single statement
-- given its text.
-- The function mainly creates an advisor task and sets its parameters.
--
-- PARAMETERS:
-- sql_text (IN) - text of a SQL statement
-- bind_list (IN) - a set of bind values
-- user_name (IN) - the username for who the statement will be tuned
-- scope (IN) - tuning scope (limited/comprehensive)
-- time_limit (IN) - maximum duration in second for the tuning session
-- task_name (IN) - optional tuning task name
-- description (IN) - maximum of 256 SQL tuning session description
--
-- RETURNS:
-- SQL tuning task unique name
--
-- EXCEPTIONS:
-- To be done
-----------------------------------------------------------------------------
FUNCTION create_tuning_task(
sql_text IN CLOB,
bind_list IN sql_binds := NULL,
user_name IN VARCHAR2 := NULL,
scope IN VARCHAR2 := SCOPE_COMPREHENSIVE,
time_limit IN NUMBER := TIME_LIMIT_DEFAULT,
task_name IN VARCHAR2 := NULL,
description IN VARCHAR2 := NULL)
RETURN VARCHAR2;
2 基于sql_id建立任务
--------------------- create_tuning_task - sql_id format --------------------
-- NAME:
-- create_tuning_task - sql_id format
--
-- DESCRIPTION
-- This function is called to prepare the tuning of a single statement
-- from the Cursor Cache given its identifier.
-- The function mainly creates an advisor task and sets its parameters.
--
-- PARAMETERS:
-- sql_id (IN) - identifier of the statement
-- plan_hash_value (IN) - hash value of the sql execution plan
-- scope (IN) - tuning scope (limited/comprehensive)
-- time_limit (IN) - maximum tuning duration in second
-- task_name (IN) - optional tuning task name
-- description (IN) - maximum of 256 SQL tuning session description
--
-- RETURNS:
-- SQL tuning task unique name
--
-- EXCEPTIONS:
-- To be done
-----------------------------------------------------------------------------
FUNCTION create_tuning_task(
sql_id IN VARCHAR2,
plan_hash_value IN NUMBER := NULL,
scope IN VARCHAR2 := SCOPE_COMPREHENSIVE,
time_limit IN NUMBER := TIME_LIMIT_DEFAULT,
task_name IN VARCHAR2 := NULL,
description IN VARCHAR2 := NULL)
RETURN VARCHAR2;
3 基于AWR快照间隔以及相应SQL_ID建立任务
-------------- create_tuning_task - workload repository format --------------
-- NAME:
-- create_tuning_task - workload repository format
--
-- DESCRIPTION
-- This function is called to prepare the tuning of a single statement
-- from the workload repository given a range of snapshot identifiers.
-- The function mainly creates an advisor task and sets its parameters.
--
-- PARAMETERS:
-- begin_snap (IN) - begin snapshot identifier
-- end_snap (IN) - end snapshot identifier
-- sql_id (IN) - identifier of the statement
-- plan_hash_value (IN) - plan hash value
-- scope (IN) - tuning scope (limited/comprehensive)
-- time_limit (IN) - maximum duration in second for tuning
-- task_name (IN) - optional tuning task name
-- description (IN) - maximum of 256 SQL tuning session description
--
-- RETURNS:
-- SQL tuning task unique name
--
-- EXCEPTIONS:
-- To be done
-----------------------------------------------------------------------------
FUNCTION create_tuning_task(
begin_snap IN NUMBER,
end_snap IN NUMBER,
sql_id IN VARCHAR2,
plan_hash_value IN NUMBER := NULL,
scope IN VARCHAR2 := SCOPE_COMPREHENSIVE,
time_limit IN NUMBER := TIME_LIMIT_DEFAULT,
task_name IN VARCHAR2 := NULL,
description IN VARCHAR2 := NULL)
RETURN VARCHAR2;
当然还有基于sqlset,以及SQL Performance Analyzer (SPA) task 建立任务的函数 这个以后再写专题吧
sample的建立是基于sql文本来做实验的,如下所示
DECLARE
MY_TASK_NAME VARCHAR2(30);
MY_SQLTEXT CLOB;
BEGIN
MY_SQLTEXT :='SELECT * FROM TEST_OBJECT_TTX WHERE OBJECT_ID = :BND';
MY_TASK_NAME := DBMS_SQLTUNE.CREATE_TUNING_TASK(SQL_TEXT => MY_SQLTEXT,
BIND_LIST=>SQL_BINDS(ANYDATA.CONVERTNUMBER(9)),
USER_NAME => 'NOAP',
SCOPE=>'COMPREHENSIVE',
TIME_LIMIT => 60,
TASK_NAME => 'SQL_TUNING_TEST',
DESCRIPTION=>'TUNING TASK'
);
END;
建立后的状态为INITIAL 因为还没执行
4 EXECUTE TASK
SQL> BEGIN DBMS_SQLTUNE.EXECUTE_TUNING_TASK('SQL_TUNING_TEST'); END;
2 /
PL/SQL procedure successfully completed
SQL> SELECT status FROM USER_ADVISOR_TASKS WHERE task_name ='SQL_TUNING_TEST';
STATUS
-----------
COMPLETED
5 查询建议结果
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('SQL_TUNING_TEST') FROM DUAL;
该语句是一个CLOB字段的结果 点击自行查看 根据相应的建议优化sql
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : SQL_TUNING_TEST
Tuning Task Owner : NOAP
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 60
Completion Status : COMPLETED
Started at : 06/24/2011 12:45:20
Completed at : 06/24/2011 12:45:22
-------------------------------------------------------------------------------
Schema Name: NOAP
SQL ID : 5k6fk8cynf60x
SQL Text : SELECT * FROM TEST_SQL_ADVISOR WHERE OBJECT_ID = :BND
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- Statistics Finding
---------------------
尚未分析表 "NOAP"."TEST_SQL_ADVISOR"。
Recommendation
--------------
- 考虑收集此表的优化程序统计信息。
execute dbms_stats.gather_table_stats(ownname => 'NOAP', tabname =>
'TEST_SQL_ADVISOR', estimate_percent =>
DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE
AUTO');
Rationale
---------
为了选择好的执行计划, 优化程序需要此表的最新统计信息。
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 719217330
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 96 | 2 (0)| 00:03:18 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST_SQL_ADVISOR | 1 | 96 | 2 (0)| 00:03:18 |
|* 2 | INDEX RANGE SCAN | TEST_SQL_ADVISOR_IDX | 1 | | 1 (0)| 00:01:39 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=:BND)
-------------------------------------------------------------------------------
6 删除任务的方法
BEGIN dbms_sqltune.drop_tuning_task('SQL_TUNING_TEST'); END;
7 可以用到的视图
SELECT * FROM USER_ADVISOR_TASKS T WHERE TASK_NAME='SQL_TUNING_TEST';
SELECT * FROM DBA_SQLTUNE_STATISTICS
SELECT * FROM DBA_SQLTUNE_BINDS
SELECT * FROM DBA_SQLTUNE_PLANS WHERE TASK_ID=13009
ORACLE SQL TUNING ADVISOR 使用方法的更多相关文章
- Oracle SQL Tuning Advisor 测试
如果面对一个需要优化的SQL语句,没有很好的想法,可以先试试Oracle的SQL Tuning Advisor. SQL> select * from v$version; BANNER --- ...
- 使用ORACLE SQL Tuning advisor快速优化低效的SQL语句
ORACLE10G以后版本的SQL Tuning advisor可以从以下四个方面给出优化方案 (1)为统计信息丢失或失效的对象收集统计信息 (2)考虑优化器的任何数据偏差.复杂谓词或失效的统计信 ...
- [terry笔记]Oracle SQL 优化之sql tuning advisor (STA)
前言:经常可以碰到优化sql的需求,开发人员直接扔过来一个SQL让DBA优化,然后怎么办? 当然,经验丰富的DBA可以从各种方向下手,有时通过建立正确索引即可获得很好的优化效果,但是那些复杂SQL错综 ...
- Oracle自带工具sql优化集-SQL Tuning Advisor (使用心得体会)
如何有效的诊断和监控高负载的SQL对于DBA来说并非是件容易的事情,对SQL语句手工调优需要很多的经验和技巧, 结合个人经验常见如下问题: . 对SQL语句本身进行优化以便获得更优的 ...
- Oracle 10G强大的SQL优化工具:SQL Tuning Advisor
p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; orphans: 2; widow ...
- Oracle调整顾问(SQL Tuning Advisor 与 SQL Access Advisor
在Oracle数据库出现性能问题时,使用Oracle本身的工具包,给出合理的调优建议是比较省力的做法. tuning advisor 是对输入的sql set的执行计划进行优化accsee advis ...
- 怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优
怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优 1>.这里简单举个样例来说明DBMS_SQLTUN ...
- Oracle 11g 禁用 SQL Tuning Advisor 与 auto space advisor
生产上有一套11g数据库alert.log报错ORA-16957: SQL Analyze time limit interrupt. 查询MOS相关文档Troubleshooting: ORA-1 ...
- Oracle SQL tuning 步骤
Oracle SQL tuning 步骤 SQL是的全称是Structured Query Language(结构化查询语言).SQL是一个在80年代中期被使用的工业标准数据库查询语言.不要把SQL语 ...
随机推荐
- 关于MPEG2中的图像序列和图像组头GOP
图像序列 图像序列是由图像组构成的,是随机存取段落. sequence_header_code – The sequence_header_code is the bit string ‘000001 ...
- hadoop2.5.1搭建(二)
第一篇主要是整体的步骤,其实中间遇到很多问题,第二篇将遇到的问题全部列举下来: 1.1包不能加载警告 WARN util.NativeCodeLoader: Unable to load native ...
- php接口post提交方法 。
方法一,用 file_get_contents function send_post($url, $post_data) { //$postdata = http_build_query($post_ ...
- c#中如何做日期的三元判断(日期不为空赋值)
<dx:ASPxDateEdit runat="server" ID="edTab4_protocoldate" Width="100%&quo ...
- 【Hibernate 8】Hibernate的调优方法:抓取策略
在上一篇博客中,介绍了Hibernate的缓存机制.合理的配置缓存,可以极大程度上优化Hibernate的性能.这篇博客,介绍另外一个调优方式:抓取策略. 一.什么是抓取策略 抓取策略(fetchin ...
- golang初体验
使用golang开发已经有一个多月了,除了一开始遇到的各种小白问题,IDE的选择,gopath,goroot的配置...后边还算顺风顺水的.实践体验,golang真的适合快速开发.特别是后台开发,直接 ...
- (function($){...})(jQuery)是什么意思
这里实际上是匿名函数 function(arg){...} 这就定义了一个匿名函数,参数为arg 而调用函数 时,是在函数后面写上括号和实参的,由于操作符的优先级,函数本身也需要用括号,即: (fun ...
- ASP.NET-----Repeater数据控件的用法总结(转)
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- SVN创建资源与分支详解
创建分支的意义: 简单说,分支就是用于区分开发版本与当前发布版本的. 1. 主干负责新功能的开发 2..分支负责修正当前发布版本的bug(对于可以放入下个发布版本的改进性bug可以直接在主干上开发) ...
- 七个你可能不了解的CSS单位
我们很容易无法摆脱的使用我们所熟悉的CSS技术,当新的问题出现,这样会使我们处于不利的地位. 随着Web继续的发展,对新的解决方案的需求也会继续增大.因此,作为网页设计师和前端开发人员,我们别无选择, ...