Oracle10g SQL tune adviser
Oracle10g SQL tune adviser简单介绍
本文简单介绍下SQL Tuning Adviser的配置使用方法和一些相关知识点,如果了解SQL Tuning Adviser详细信息,参看Oracle联机文档。本文对分析结果没有详细分析。
一、自动SQL Tuning简单介绍:
1、优化模式:
10G增强的优化模式有两种:
a、Normal mode
在普通优化模式下,优化器编译sql然后产生执行计划。普通优化模式下优化器能够快速的为sql语句产生可行的执行计划。
b、Tuning mode
在tuning mode模式下,优化器将花费额外的时间检查一个普通模式下产生的执行计划是否可以优化。优化器的输出结果将不仅仅是产生一个执行计划,
而将执行一系列的动作,在该模式下优化器也许化肥几分钟去调整一个语句。每次一个sql语句被硬解析后将在自动调整优化上花费更多的时间和资源。
sql自动调整优化更适用于有复杂sql或者high-load sql的系统(例如addm中标记为高负载的sql就非常适合作为sql自动调整的目标)。
2、 SQL Tuning类型
Automatic SQL Tuning包含四种类型的分析:
a、Statistics Analysis
b、SQL Profiling
c、Access Path Analysis
d、SQL Structure Analysis
二、SQL Tuning Adviser:
1、授予用户相应权限:
CONN sys/password AS SYSDBA
GRANT ADVISOR TO TEST;
CONN TEST/TEST
2、创建Tuning任务:
可以通过以下方式创建Tuning任务:
a、Automatic Workload Repository (AWR)
b、the cursor cache
c、SQL tuning set
d、specified manually
SET SERVEROUTPUT ON
--a、通过AWR设置Tuning任务.
SQL> conn /as sysdba
已连接。
--查看AWR的SNAPSHOT信息:
SQL> SELECT max(snap_id) FROM WRM$_SNAPSHOT;
MAX(SNAP_ID)
------------
201
--查看SNAP间隔:
SQL> select snap_interval, retention from dba_hist_wr_control;
SNAP_INTERVAL RETENTION
------------------------------ ------------------------------
+00000 01:00:00.0 +00007 00:00:00.0
--我们可以手工缩短AWR采样时间间隔(加快测试速度,本利采用手工执行创建SNAPSHOT的方法):
begin
dbms_workload_repository.modify_snapshot_settings (
interval => 10,
retention => 10*24*60
);
end;
SQL> conn test/test
已连接。
--执行目标SQL:
SQL> select /*We will trace this sql*/ name,addr,insertdata from (select name,ad
dr,insertdata,rank() over(partition by name,addr order by insertdata desc) rn fr
om t ) where rn = 1;
NAME ADDR INSERTDATA
---------- -------------------- -------------------
王 上海 19-12-2006 10:09:33
王1 上海 16-12-2006 10:11:15
王2 上海 16-12-2006 10:11:15
张 北京 19-12-2006 10:08:42
--查找SQL_ID:
SQL> select sql_id,executions from v$sqlarea where lower(sql_text) like '%we wil
l trace this sql%';
SQL_ID EXECUTIONS
------------- ----------
8zu31x4adn76f 1
1k659753fzcxn 1
SQL> /
SQL_ID EXECUTIONS
------------- ----------
8zu31x4adn76f 2
1k659753fzcxn 1 --我们将分析该SQL
SQL> select sql_id from DBA_HIST_SQLSTAT where sql_id='1k659753fzcxn';
未选定行
--手工创建新的AWR SNAPSHOT:
SQL> execute dbms_workload_repository.create_snapshot;
PL/SQL 过程已成功完成。
SQL> select sql_id from DBA_HIST_SQLSTAT where sql_id='1k659753fzcxn';
SQL_ID
-------------
1k659753fzcxn
--创建Tuning task:
SQL> DECLARE
2 l_sql_tune_task_id VARCHAR2(100);
3 BEGIN
4 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
5 begin_snap => 201,
6 end_snap => 202,
7 sql_id => '1k659753fzcxn',
8 scope => DBMS_SQLTUNE.scope_comprehensive,
9 time_limit => 60,
10 task_name => '1k659753fzcxn_awr_tuning_task',
11 description => 'Tuning task for statement 1k659753fzcxn in AWR.');
12 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
13 END;
14 /
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task INITIAL
--执行Tuning task:
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => '1k659753fzcxn_awr_tuning_task');
PL/SQL 过程已成功完成。
SQL> SET LONG 999999;
SQL> SET PAGESIZE 1000
SQL> SET LINESIZE 200
--查看Tuning advice:
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('1k659753fzcxn_awr_tuning_task') AS recommendations FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : 1k659753fzcxn_awr_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/09/2008 22:40:27
Completed at : 07/09/2008 22:40:28
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 1k659753fzcxn
SQL Text : select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr
order by insertdata desc) rn from t ) where rn = 1
-------------------------------------------------------------------------------
ADDITIONAL INFORMATION SECTION
-------------------------------------------------------------------------------
-优化程序不能合并位于执行计划的行 ID 1 处的视图。.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 3047187157
--------------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 8 | 368 | 4 (25)| 00:00:01
|
|* 1 | VIEW | | 8 | 368 | 4 (25)| 00:00:01
|
|* 2 | WINDOW SORT PUSHED RANK| | 8 | 136 | 4 (25)| 00:00:01
|
| 3 | TABLE ACCESS FULL | T | 8 | 136 | 3 (0)| 00:00:01
|
--------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RN"=1)
2 - filter(RANK() OVER ( PARTITION BY "NAME","ADDR" ORDER BY
INTERNAL_FUNCTION("INSERTDATA") DESC )<=1)
-------------------------------------------------------------------------------
--中断Tuning task:
EXEC DBMS_SQLTUNE.interrupt_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--继续Tuning task:
EXEC DBMS_SQLTUNE.resume_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--取消Tuning task:
EXEC DBMS_SQLTUNE.cancel_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--重置Tuning task:
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task COMPLETED
SQL> EXEC DBMS_SQLTUNE.reset_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task INITIAL
--删除Tuning task:
SQL> BEGIN
2 DBMS_SQLTUNE.drop_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
3 END;
4 /
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
--b、通过cursor cache设置Tuning任务.
--方法大致如下,这里我们就不再另外举例了。
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => '1k659753fzcxn',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '1k659753fzcxn_tuning_task',
description => 'Tuning task for statement 1k659753fzcxn.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
--c、通过SQL tuning set设置Tuning任务.
我们可以创建调整SQL的集合:
SQL> CONN /AS SYSDBA
已连接。
SQL> GRANT ADMINISTER ANY SQL TUNING SET TO TEST;
授权成功。
SQL> CONN TEST/TEST
已连接。
SQL> BEGIN
2 DBMS_SQLTUNE.create_sqlset (
3 sqlset_name => 'test_sql_tuning_set',
4 description => 'A test SQL tuning set.');
5 END;
6 /
PL/SQL 过程已成功完成。
SQL> SELECT OWNER,NAME FROM DBA_SQLSET;
OWNER NAME
------------------------------ ------------------------------
TEST test_sql_tuning_set
SQL> declare
2 cur dbms_sqltune.sqlset_cursor;
3 begin
4 open cur for select value(p) from table(dbms_sqltune.select_cursor_cache('parsing_schema_name = ''TEST'' ',null,null,null,null,1,null,'ALL')) P;
5 dbms_sqltune.load_sqlset(sqlset_name=>'test_sql_tuning_set',populate_cursor=>cur);
6 end;
7 /
PL/SQL 过程已成功完成。
SQL> select count(*) from table(dbms_sqltune.select_sqlset('test_sql_tuning_set'
, 'parsing_schema_name = ''TEST'' '));
COUNT(*)
----------
17
SQL> declare
2 my_task_name varchar2(30);
3 begin
4 my_task_name := dbms_sqltune.create_tuning_task(sqlset_name=>'test_sql_tuning_set',
5 time_limit=>600,
6 scope=>'COMPREHENSIVE',
7 task_name=>'test_tuning_task',
8 description=>'test tuning task');
9 end;
10 /
PL/SQL 过程已成功完成。
SQL> begin
2 dbms_sqltune.set_tuning_task_parameter(
3 task_name=> 'test_tuning_task',
4 parameter => 'TIME_LIMIT',
5 value=>800);
6 end;
7 /
PL/SQL 过程已成功完成。
SQL> exec dbms_sqltune.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> set long 999999
SQL> set longchunksize 1000
SQL> set linesize 200
SQL> select dbms_sqltune.report_tuning_task('test_tuning_task') from dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_TUNING_TASK')
-------------------------------------------------------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 800
Completion Status : COMPLETED
Started at : 07/10/2008 12:38:55
Completed at : 07/10/2008 12:38:59
SQL Tuning Set (STS) Name : test_sql_tuning_set
SQL Tuning Set Owner : TEST
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_TUNING_TASK')
-------------------------------------------------------------------------------------------------------------------------------
Number of Statements in the STS : 17
Number of Statements in the Report: 17
Number of Statements with Findings: 7
Number of Statistic Findings : 9
Number of SQL Profile Findings : 2
Number of SQL Restructure Findings: 1
Number of Errors : 1
.........................................
.........................................
这里就不显示分析结果了,上千行的分析结果。
和创建Tuning task类似,select_sqlset也可以从AWR中获得sql集合,也可拷贝其他集合。这里不再详细介绍。
--d、通过manually specified statement设置Tuning任务.
--没有绑定变量的情况:
SQL> DECLARE
2 l_sql VARCHAR2(500);
3 l_sql_tune_task_id VARCHAR2(100);
4 BEGIN
5 l_sql := 'select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr order by
insertdatadesc) rn from t ) where rn = 1';
7 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
8 sql_text => l_sql,
9 user_name => 'TEST',
10 scope => DBMS_SQLTUNE.scope_comprehensive,
11 time_limit => 60,
12 task_name => 'test_tuning_task',
13 description => 'Tuning task for an a simple query.');
14 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
15 END;
16 /
PL/SQL 过程已成功完成。
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendations FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/10/2008 01:17:09
Completed at : 07/10/2008 01:17:09
Number of Statistic Findings : 1
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 3zdbsrhb1mhuq --该处的sql_id显示不正确,可能是oracle的一个 bug
SQL Text : select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr
order by insertdata desc) rn from t ) where rn = 1
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
RECOMMENDATIONS
--------------------------------------------------------------------------------
1- Statistics Finding
---------------------
尚未分析表 "TEST"."
Recommendation
--------------
- 考虑收集此表的优
execute dbms_stats.gather_table_stats(ownname => 'TEST', tabname => 'T',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO');
RECOMMENDATIONS
--------------------------------------------------------------------------------
Rationale
---------
为了选择好的执行计划, 优化程序需
-------------------------------------------------------------------------------
ADDITIONAL INFORMATION SECTION
-------------------------------------------------------------------------------
-优化程序不能合并位于执行计划的行 ID 1 处的视图。.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 3047187157
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 368 | 4 (25)| 00:00:01
|* 1 | VIEW | | 8 | 368 | 4 (25)| 00:00:01
RECOMMENDATIONS
--------------------------------------------------------------------------------
|* 2 | WINDOW SORT PUSHED RANK| | 8 | 264 | 4 (25)| 00:00:01
| 3 | TABLE ACCESS FULL | T | 8 | 264 | 3 (0)| 00:00:01
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RN"=1)
2 - filter(RANK() OVER ( PARTITION BY "NAME","ADDR" ORDER BY
INTERNAL_FUNCTION("INSERTDATA") DESC )<=1)
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--带有绑定变量的情况:
SQL> variable var_1 number;
SQL> variable var_2 number;
SQL> variable var_3 number;
SQL> exec :var_1 := 5;
PL/SQL 过程已成功完成。
SQL> exec :var_2 := 4;
PL/SQL 过程已成功完成。
SQL> exec :var_3 := 3;
PL/SQL 过程已成功完成。
SQL> select id,name,addr from t where id<>:var_1 and id<:var_2 and id<:var_3;
ID NAME ADDR
---------- -------------------- --------------------
1 张 北京
2 张 北京
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
test_tuning_task COMPLETED
SQL> BEGIN
2 DBMS_SQLTUNE.drop_tuning_task (task_name => 'test_tuning_task');
3 END;
4 /
PL/SQL 过程已成功完成。
SQL>
SQL>
SQL> DECLARE
2 l_sql VARCHAR2(500);
3 l_sql_tune_task_id VARCHAR2(100);
4 BEGIN
5 l_sql := 'select id,name,addr from t where id<>:var_1 and id<:var_2 and i
d<:var_3';
6
7 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
8 sql_text => l_sql,
9 bind_list => sql_binds(anydata.ConvertNumber(5),
anydata.ConvertNumber(4),anydata.ConvertNumber(3)),
10 user_name => 'TEST',
11 scope => DBMS_SQLTUNE.scope_comprehensive,
12 time_limit => 60,
13 task_name => 'test_tuning_task',
14 description => 'Tuning task for an a simple query
.');
15 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
16 END;
17 /
PL/SQL 过程已成功完成。
SQL> SELECT * FROM DBA_SQLTUNE_BINDS;
TASK_ID OBJECT_ID POSITION VALUE()
---------- ---------- ---------- --------------------
393 1 1 ANYDATA()
393 1 2 ANYDATA()
393 1 3 ANYDATA()
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendatio
ns FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/10/2008 02:04:29
Completed at : 07/10/2008 02:04:29
Number of Statistic Findings : 1
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 15c91q9b2sxvk --该处的sql_id显示不正确,可能是oracle的一个 bug
SQL Text : select id,name,addr from t where id<>:var_1 and id<:var_2 and
id<:var_3
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- Statistics Finding
RECOMMENDATIONS
--------------------------------------------------------------------------------
---------------------
尚未分析表 "TEST"."
Recommendation
--------------
- 考虑收集此表的优
execute dbms_stats.gather_table_stats(ownname => 'TEST', tabname => 'T',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO');
Rationale
RECOMMENDATIONS
--------------------------------------------------------------------------------
---------
为了选择好的执行计划, 优化程序需
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 1601196873
RECOMMENDATIONS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 296 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T | 8 | 296 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"<>:VAR_1 AND "ID"<:VAR_2 AND "ID"<:VAR_3)
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
三、SQL Profile:
由于缺少各种信息,优化器有时候会产生不正确的执行计划,通常我们可以指定hints来干预执行计划。
SQL AUTO TUNING通过SQL Profiling来解决类似的问题。自动调整优化器会创建SQL Profile,SQL Profile包含SQL语句的辅助统计信息。
普通优化模式下,优化器通过估算出一个集式、选择性、cost来最后决定使用什么样的执行计划。SQL Profile利用存储的额外的信息,
通过采样或者部分执行的方式来验证一个执行计划是否为最优化,保存历史运行统计信息。
如果一个tuning task accept SQL Profile,SQL Profile将被永久存储在数据字典中。普通优化模式下,优化器在产生执行计划的时候
将利用数据库的统计信息结合SQL Profile的信息一起分析,最终产生最优化的执行计划。
可以利用CATAGORY控制SQL Profile的使用权限,数据库参数sqltune_category为默认DEFAULT。
SQL> SHOW PARAMETER SQLTUNE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
sqltune_category string DEFAULT
我们也可以修改数据库参数文件,指定我们自己的SQLTUNE_CATEGORY:
ALTER SYSTEM SET SQLTUNE_CATEGORY = PROD;
SQL Profiles apply to the following statement types:
SELECT statements
UPDATE statements
INSERT statements (only with a SELECT clause)
DELETE statements
CREATE TABLE statements (only with the AS SELECT clause)
MERGE statements (the update or insert operations)
SQL Profile基本操作:
SQL> conn /as sysdba
已连接。
SQL> GRANT CREATE ANY SQL_PROFILE TO TEST;
授权成功。
SQL> GRANT DROP ANY SQL PROFILE TO TEST;
授权成功。
SQL> GRANT ALTER ANY SQL PROFILE TO TEST;
授权成功。
SQL> CONN TEST/TEST
已连接。
SET SERVEROUTPUT ON
DECLARE
l_sql_tune_task_id VARCHAR2(20);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.accept_sql_profile (
task_name => 'test_tuning_task',
name => 'test_profile');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
BEGIN
DBMS_SQLTUNE.alter_sql_profile (
name => 'test_profile',
attribute_name => 'STATUS',
value => 'DISABLED');
END;
/
BEGIN
DBMS_SQLTUNE.drop_sql_profile (
name => 'test_profile',
ignore => TRUE);
END;
/
--example:
SQL> execute dbms_sqltune.accept_sql_profile(task_name => 'test_tuning_task',object_id => 6, replace => TRUE);
SQL> select count(1) from DBA_SQL_PROFILES;
COUNT(1)
----------
1
PL/SQL 过程已成功完成。
四、几个有用的automatic SQL tuning相关的数据字典:
DBA_ADVISOR_TASKS
DBA_ADVISOR_FINDINGS
DBA_ADVISOR_RECOMMENDATIONS
DBA_ADVISOR_RATIONALE
DBA_SQLTUNE_STATISTICS
DBA_SQLTUNE_BINDS
DBA_SQLTUNE_PLANS
DBA_SQLSET
DBA_SQLSET_BINDS
DBA_SQLSET_STATEMENTS
DBA_SQLSET_REFERENCES
DBA_SQL_PROFILES
V$SQL
V$SQLAREA
V$ACTIVE_SESSION_HISTORY
五、DBMS_SQLTUNE包的详细方法可以参考:
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10802/d_sqltun.htm
本文简单介绍下SQL Tuning Adviser的配置使用方法和一些相关知识点,如果了解SQL Tuning Adviser详细信息,参看Oracle联机文档。本文对分析结果没有详细分析。
一、自动SQL Tuning简单介绍:
1、优化模式:
10G增强的优化模式有两种:
a、Normal mode
在普通优化模式下,优化器编译sql然后产生执行计划。普通优化模式下优化器能够快速的为sql语句产生可行的执行计划。
b、Tuning mode
在tuning mode模式下,优化器将花费额外的时间检查一个普通模式下产生的执行计划是否可以优化。优化器的输出结果将不仅仅是产生一个执行计划,
而将执行一系列的动作,在该模式下优化器也许化肥几分钟去调整一个语句。每次一个sql语句被硬解析后将在自动调整优化上花费更多的时间和资源。
sql自动调整优化更适用于有复杂sql或者high-load sql的系统(例如addm中标记为高负载的sql就非常适合作为sql自动调整的目标)。
2、 SQL Tuning类型
Automatic SQL Tuning包含四种类型的分析:
a、Statistics Analysis
b、SQL Profiling
c、Access Path Analysis
d、SQL Structure Analysis
二、SQL Tuning Adviser:
1、授予用户相应权限:
CONN sys/password AS SYSDBA
GRANT ADVISOR TO TEST;
CONN TEST/TEST
2、创建Tuning任务:
可以通过以下方式创建Tuning任务:
a、Automatic Workload Repository (AWR)
b、the cursor cache
c、SQL tuning set
d、specified manually
SET SERVEROUTPUT ON
--a、通过AWR设置Tuning任务.
SQL> conn /as sysdba
已连接。
--查看AWR的SNAPSHOT信息:
SQL> SELECT max(snap_id) FROM WRM$_SNAPSHOT;
MAX(SNAP_ID)
------------
201
--查看SNAP间隔:
SQL> select snap_interval, retention from dba_hist_wr_control;
SNAP_INTERVAL RETENTION
------------------------------ ------------------------------
+00000 01:00:00.0 +00007 00:00:00.0
--我们可以手工缩短AWR采样时间间隔(加快测试速度,本利采用手工执行创建SNAPSHOT的方法):
begin
dbms_workload_repository.modify_snapshot_settings (
interval => 10,
retention => 10*24*60
);
end;
SQL> conn test/test
已连接。
--执行目标SQL:
SQL> select /*We will trace this sql*/ name,addr,insertdata from (select name,ad
dr,insertdata,rank() over(partition by name,addr order by insertdata desc) rn fr
om t ) where rn = 1;
NAME ADDR INSERTDATA
---------- -------------------- -------------------
王 上海 19-12-2006 10:09:33
王1 上海 16-12-2006 10:11:15
王2 上海 16-12-2006 10:11:15
张 北京 19-12-2006 10:08:42
--查找SQL_ID:
SQL> select sql_id,executions from v$sqlarea where lower(sql_text) like '%we wil
l trace this sql%';
SQL_ID EXECUTIONS
------------- ----------
8zu31x4adn76f 1
1k659753fzcxn 1
SQL> /
SQL_ID EXECUTIONS
------------- ----------
8zu31x4adn76f 2
1k659753fzcxn 1 --我们将分析该SQL
SQL> select sql_id from DBA_HIST_SQLSTAT where sql_id='1k659753fzcxn';
未选定行
--手工创建新的AWR SNAPSHOT:
SQL> execute dbms_workload_repository.create_snapshot;
PL/SQL 过程已成功完成。
SQL> select sql_id from DBA_HIST_SQLSTAT where sql_id='1k659753fzcxn';
SQL_ID
-------------
1k659753fzcxn
--创建Tuning task:
SQL> DECLARE
2 l_sql_tune_task_id VARCHAR2(100);
3 BEGIN
4 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
5 begin_snap => 201,
6 end_snap => 202,
7 sql_id => '1k659753fzcxn',
8 scope => DBMS_SQLTUNE.scope_comprehensive,
9 time_limit => 60,
10 task_name => '1k659753fzcxn_awr_tuning_task',
11 description => 'Tuning task for statement 1k659753fzcxn in AWR.');
12 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
13 END;
14 /
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task INITIAL
--执行Tuning task:
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => '1k659753fzcxn_awr_tuning_task');
PL/SQL 过程已成功完成。
SQL> SET LONG 999999;
SQL> SET PAGESIZE 1000
SQL> SET LINESIZE 200
--查看Tuning advice:
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('1k659753fzcxn_awr_tuning_task') AS recommendations FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : 1k659753fzcxn_awr_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/09/2008 22:40:27
Completed at : 07/09/2008 22:40:28
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 1k659753fzcxn
SQL Text : select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr
order by insertdata desc) rn from t ) where rn = 1
-------------------------------------------------------------------------------
ADDITIONAL INFORMATION SECTION
-------------------------------------------------------------------------------
-优化程序不能合并位于执行计划的行 ID 1 处的视图。.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 3047187157
--------------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 8 | 368 | 4 (25)| 00:00:01
|
|* 1 | VIEW | | 8 | 368 | 4 (25)| 00:00:01
|
|* 2 | WINDOW SORT PUSHED RANK| | 8 | 136 | 4 (25)| 00:00:01
|
| 3 | TABLE ACCESS FULL | T | 8 | 136 | 3 (0)| 00:00:01
|
--------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RN"=1)
2 - filter(RANK() OVER ( PARTITION BY "NAME","ADDR" ORDER BY
INTERNAL_FUNCTION("INSERTDATA") DESC )<=1)
-------------------------------------------------------------------------------
--中断Tuning task:
EXEC DBMS_SQLTUNE.interrupt_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--继续Tuning task:
EXEC DBMS_SQLTUNE.resume_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--取消Tuning task:
EXEC DBMS_SQLTUNE.cancel_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
--重置Tuning task:
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task COMPLETED
SQL> EXEC DBMS_SQLTUNE.reset_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
1k659753fzcxn_awr_tuning_task INITIAL
--删除Tuning task:
SQL> BEGIN
2 DBMS_SQLTUNE.drop_tuning_task (task_name => '1k659753fzcxn_awr_tuning_task');
3 END;
4 /
PL/SQL 过程已成功完成。
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
--b、通过cursor cache设置Tuning任务.
--方法大致如下,这里我们就不再另外举例了。
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => '1k659753fzcxn',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '1k659753fzcxn_tuning_task',
description => 'Tuning task for statement 1k659753fzcxn.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
--c、通过SQL tuning set设置Tuning任务.
我们可以创建调整SQL的集合:
SQL> CONN /AS SYSDBA
已连接。
SQL> GRANT ADMINISTER ANY SQL TUNING SET TO TEST;
授权成功。
SQL> CONN TEST/TEST
已连接。
SQL> BEGIN
2 DBMS_SQLTUNE.create_sqlset (
3 sqlset_name => 'test_sql_tuning_set',
4 description => 'A test SQL tuning set.');
5 END;
6 /
PL/SQL 过程已成功完成。
SQL> SELECT OWNER,NAME FROM DBA_SQLSET;
OWNER NAME
------------------------------ ------------------------------
TEST test_sql_tuning_set
SQL> declare
2 cur dbms_sqltune.sqlset_cursor;
3 begin
4 open cur for select value(p) from table(dbms_sqltune.select_cursor_cache('parsing_schema_name = ''TEST'' ',null,null,null,null,1,null,'ALL')) P;
5 dbms_sqltune.load_sqlset(sqlset_name=>'test_sql_tuning_set',populate_cursor=>cur);
6 end;
7 /
PL/SQL 过程已成功完成。
SQL> select count(*) from table(dbms_sqltune.select_sqlset('test_sql_tuning_set'
, 'parsing_schema_name = ''TEST'' '));
COUNT(*)
----------
17
SQL> declare
2 my_task_name varchar2(30);
3 begin
4 my_task_name := dbms_sqltune.create_tuning_task(sqlset_name=>'test_sql_tuning_set',
5 time_limit=>600,
6 scope=>'COMPREHENSIVE',
7 task_name=>'test_tuning_task',
8 description=>'test tuning task');
9 end;
10 /
PL/SQL 过程已成功完成。
SQL> begin
2 dbms_sqltune.set_tuning_task_parameter(
3 task_name=> 'test_tuning_task',
4 parameter => 'TIME_LIMIT',
5 value=>800);
6 end;
7 /
PL/SQL 过程已成功完成。
SQL> exec dbms_sqltune.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> set long 999999
SQL> set longchunksize 1000
SQL> set linesize 200
SQL> select dbms_sqltune.report_tuning_task('test_tuning_task') from dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_TUNING_TASK')
-------------------------------------------------------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 800
Completion Status : COMPLETED
Started at : 07/10/2008 12:38:55
Completed at : 07/10/2008 12:38:59
SQL Tuning Set (STS) Name : test_sql_tuning_set
SQL Tuning Set Owner : TEST
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_TUNING_TASK')
-------------------------------------------------------------------------------------------------------------------------------
Number of Statements in the STS : 17
Number of Statements in the Report: 17
Number of Statements with Findings: 7
Number of Statistic Findings : 9
Number of SQL Profile Findings : 2
Number of SQL Restructure Findings: 1
Number of Errors : 1
.........................................
.........................................
这里就不显示分析结果了,上千行的分析结果。
和创建Tuning task类似,select_sqlset也可以从AWR中获得sql集合,也可拷贝其他集合。这里不再详细介绍。
--d、通过manually specified statement设置Tuning任务.
--没有绑定变量的情况:
SQL> DECLARE
2 l_sql VARCHAR2(500);
3 l_sql_tune_task_id VARCHAR2(100);
4 BEGIN
5 l_sql := 'select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr order by
insertdatadesc) rn from t ) where rn = 1';
7 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
8 sql_text => l_sql,
9 user_name => 'TEST',
10 scope => DBMS_SQLTUNE.scope_comprehensive,
11 time_limit => 60,
12 task_name => 'test_tuning_task',
13 description => 'Tuning task for an a simple query.');
14 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
15 END;
16 /
PL/SQL 过程已成功完成。
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendations FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/10/2008 01:17:09
Completed at : 07/10/2008 01:17:09
Number of Statistic Findings : 1
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 3zdbsrhb1mhuq --该处的sql_id显示不正确,可能是oracle的一个 bug
SQL Text : select /*We will trace this sql*/ name,addr,insertdata from
(select name,addr,insertdata,rank() over(partition by name,addr
order by insertdata desc) rn from t ) where rn = 1
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
RECOMMENDATIONS
--------------------------------------------------------------------------------
1- Statistics Finding
---------------------
尚未分析表 "TEST"."
Recommendation
--------------
- 考虑收集此表的优
execute dbms_stats.gather_table_stats(ownname => 'TEST', tabname => 'T',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO');
RECOMMENDATIONS
--------------------------------------------------------------------------------
Rationale
---------
为了选择好的执行计划, 优化程序需
-------------------------------------------------------------------------------
ADDITIONAL INFORMATION SECTION
-------------------------------------------------------------------------------
-优化程序不能合并位于执行计划的行 ID 1 处的视图。.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 3047187157
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 368 | 4 (25)| 00:00:01
|* 1 | VIEW | | 8 | 368 | 4 (25)| 00:00:01
RECOMMENDATIONS
--------------------------------------------------------------------------------
|* 2 | WINDOW SORT PUSHED RANK| | 8 | 264 | 4 (25)| 00:00:01
| 3 | TABLE ACCESS FULL | T | 8 | 264 | 3 (0)| 00:00:01
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RN"=1)
2 - filter(RANK() OVER ( PARTITION BY "NAME","ADDR" ORDER BY
INTERNAL_FUNCTION("INSERTDATA") DESC )<=1)
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--带有绑定变量的情况:
SQL> variable var_1 number;
SQL> variable var_2 number;
SQL> variable var_3 number;
SQL> exec :var_1 := 5;
PL/SQL 过程已成功完成。
SQL> exec :var_2 := 4;
PL/SQL 过程已成功完成。
SQL> exec :var_3 := 3;
PL/SQL 过程已成功完成。
SQL> select id,name,addr from t where id<>:var_1 and id<:var_2 and id<:var_3;
ID NAME ADDR
---------- -------------------- --------------------
1 张 北京
2 张 北京
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
TASK_NAME STATUS
------------------------------ -----------
ADDM:1184202927_1_201 COMPLETED
ADDM:1184202927_1_202 COMPLETED
test_tuning_task COMPLETED
SQL> BEGIN
2 DBMS_SQLTUNE.drop_tuning_task (task_name => 'test_tuning_task');
3 END;
4 /
PL/SQL 过程已成功完成。
SQL>
SQL>
SQL> DECLARE
2 l_sql VARCHAR2(500);
3 l_sql_tune_task_id VARCHAR2(100);
4 BEGIN
5 l_sql := 'select id,name,addr from t where id<>:var_1 and id<:var_2 and i
d<:var_3';
6
7 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
8 sql_text => l_sql,
9 bind_list => sql_binds(anydata.ConvertNumber(5),
anydata.ConvertNumber(4),anydata.ConvertNumber(3)),
10 user_name => 'TEST',
11 scope => DBMS_SQLTUNE.scope_comprehensive,
12 time_limit => 60,
13 task_name => 'test_tuning_task',
14 description => 'Tuning task for an a simple query
.');
15 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
16 END;
17 /
PL/SQL 过程已成功完成。
SQL> SELECT * FROM DBA_SQLTUNE_BINDS;
TASK_ID OBJECT_ID POSITION VALUE()
---------- ---------- ---------- --------------------
393 1 1 ANYDATA()
393 1 2 ANYDATA()
393 1 3 ANYDATA()
SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
PL/SQL 过程已成功完成。
SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendatio
ns FROM dual;
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : test_tuning_task
Tuning Task Owner : TEST
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 07/10/2008 02:04:29
Completed at : 07/10/2008 02:04:29
Number of Statistic Findings : 1
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: TEST
SQL ID : 15c91q9b2sxvk --该处的sql_id显示不正确,可能是oracle的一个 bug
SQL Text : select id,name,addr from t where id<>:var_1 and id<:var_2 and
id<:var_3
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- Statistics Finding
RECOMMENDATIONS
--------------------------------------------------------------------------------
---------------------
尚未分析表 "TEST"."
Recommendation
--------------
- 考虑收集此表的优
execute dbms_stats.gather_table_stats(ownname => 'TEST', tabname => 'T',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO');
Rationale
RECOMMENDATIONS
--------------------------------------------------------------------------------
---------
为了选择好的执行计划, 优化程序需
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 1601196873
RECOMMENDATIONS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 296 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T | 8 | 296 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"<>:VAR_1 AND "ID"<:VAR_2 AND "ID"<:VAR_3)
RECOMMENDATIONS
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
三、SQL Profile:
由于缺少各种信息,优化器有时候会产生不正确的执行计划,通常我们可以指定hints来干预执行计划。
SQL AUTO TUNING通过SQL Profiling来解决类似的问题。自动调整优化器会创建SQL Profile,SQL Profile包含SQL语句的辅助统计信息。
普通优化模式下,优化器通过估算出一个集式、选择性、cost来最后决定使用什么样的执行计划。SQL Profile利用存储的额外的信息,
通过采样或者部分执行的方式来验证一个执行计划是否为最优化,保存历史运行统计信息。
如果一个tuning task accept SQL Profile,SQL Profile将被永久存储在数据字典中。普通优化模式下,优化器在产生执行计划的时候
将利用数据库的统计信息结合SQL Profile的信息一起分析,最终产生最优化的执行计划。
可以利用CATAGORY控制SQL Profile的使用权限,数据库参数sqltune_category为默认DEFAULT。
SQL> SHOW PARAMETER SQLTUNE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
sqltune_category string DEFAULT
我们也可以修改数据库参数文件,指定我们自己的SQLTUNE_CATEGORY:
ALTER SYSTEM SET SQLTUNE_CATEGORY = PROD;
SQL Profiles apply to the following statement types:
SELECT statements
UPDATE statements
INSERT statements (only with a SELECT clause)
DELETE statements
CREATE TABLE statements (only with the AS SELECT clause)
MERGE statements (the update or insert operations)
SQL Profile基本操作:
SQL> conn /as sysdba
已连接。
SQL> GRANT CREATE ANY SQL_PROFILE TO TEST;
授权成功。
SQL> GRANT DROP ANY SQL PROFILE TO TEST;
授权成功。
SQL> GRANT ALTER ANY SQL PROFILE TO TEST;
授权成功。
SQL> CONN TEST/TEST
已连接。
SET SERVEROUTPUT ON
DECLARE
l_sql_tune_task_id VARCHAR2(20);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.accept_sql_profile (
task_name => 'test_tuning_task',
name => 'test_profile');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
BEGIN
DBMS_SQLTUNE.alter_sql_profile (
name => 'test_profile',
attribute_name => 'STATUS',
value => 'DISABLED');
END;
/
BEGIN
DBMS_SQLTUNE.drop_sql_profile (
name => 'test_profile',
ignore => TRUE);
END;
/
--example:
SQL> execute dbms_sqltune.accept_sql_profile(task_name => 'test_tuning_task',object_id => 6, replace => TRUE);
SQL> select count(1) from DBA_SQL_PROFILES;
COUNT(1)
----------
1
PL/SQL 过程已成功完成。
四、几个有用的automatic SQL tuning相关的数据字典:
DBA_ADVISOR_TASKS
DBA_ADVISOR_FINDINGS
DBA_ADVISOR_RECOMMENDATIONS
DBA_ADVISOR_RATIONALE
DBA_SQLTUNE_STATISTICS
DBA_SQLTUNE_BINDS
DBA_SQLTUNE_PLANS
DBA_SQLSET
DBA_SQLSET_BINDS
DBA_SQLSET_STATEMENTS
DBA_SQLSET_REFERENCES
DBA_SQL_PROFILES
V$SQL
V$SQLAREA
V$ACTIVE_SESSION_HISTORY
五、DBMS_SQLTUNE包的详细方法可以参考:
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10802/d_sqltun.htm