标签:bsp 针对 use ash char hunk profile set and
sql tuning advisor:
创建任务
DECLARE
my_task_name VARCHAR2(30); my_sqltext CLOB; BEGIN my_sqltext := ‘SELECT /*+ ORDERED */ * ‘ || ‘FROM employees e, locations l, departments d ‘ || ‘WHERE e.department_id = d.department_id AND ‘ || ‘l.location_id = d.location_id AND ‘ || ‘e.employee_id < :bnd‘; my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK( sql_text => my_sqltext, bind_list => sql_binds(anydata.ConvertNumber(100)), user_name => ‘HR‘, scope => ‘COMPREHENSIVE‘, time_limit => 60, task_name => ‘my_sql_tuning_task‘, description => ‘Task to tune a query on a specified employee‘); END; /
运行任务
BEGIN DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => ‘my_sql_tuning_task‘ ); END; /
查看状态和查看结果
SELECT status FROM USER_ADVISOR_TASKS WHERE task_name = ‘my_sql_tuning_task‘;
SET LONG 1000 SET LONGCHUNKSIZE 1000 SET LINESIZE 100 SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( ‘my_sql_tuning_task‘) FROM DUAL;
如想针对sql_id做调优,create task时使用如下语法:
DBMS_SQLTUNE.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;
下面举例一个:
1、为SQL_id创建一个STA(SQL Tuning advisor)分析任务(使用SYS用户执行)
SQL> variable task_li_test varchar2(2000);
SQL>exec :task_li_test:=dbms_sqltune.create_tuning_task(sql_id=>‘xxxxxxxxxxx‘,time_limit=>600,task_name=>‘li_sql_1‘);
2、执行上面创建的STA(需要一定的时间)
SQL> exec dbms_sqltune.execute_tuning_task(task_name=>‘li_sql_1‘);
3、查询优化任务创建与执行的情况
select a.owner,b.task_id,b.task_name,a.created from dba_advisor_tasks a,dba_advisor_log b where a.task_id=b.task_id and a.task_name=‘li_sql_1‘;
4、查看任务优化报告(优化的详细内容)
SQL>select dbms_sqltune.report_tuning_task(‘li_sql_1‘) from dual;
5、接受建议的 SQL 概要文件,即创建SQL_Profle
SQL> execute dbms_sqltune.accept_sql_profile(task_name => ‘li_sql_1‘,task_owner =>‘SYS‘, replace => TRUE);
6、查看第5步创建起来的SQL_Profile信息
SQL>select a.name,a.task_id,a.created from dba_sql_profiles a,dba_advisor_log b where a.task_id=b.task_id and b.task_name=‘li_sql_1‘
NAME
TASK_ID
CREATED
SYS_SQLPROF_01411bdf99410002
106699
14-9月 -13 05.49.00.000000 下午
7、再次执行SQLID为‘xxxxxxxxxxx’的语句
7.1、执行时间由原来的6分钟降为3秒
7.2、查看执行计划,执行计划中包含下面信息,说明是使用了创建的SQL_Profile所起到的效果
- SQL profile SYS_SQLPROF_01411bdf99410002used for this statement
8、删除SQL_Profile
SQL>exec dbms_sqltune.drop_sql_profile(name =>‘SYS_SQLPROF_01411bdf99410002‘);
9、删除优化任务
SQL> exec dbms_sqltune.drop_tuning_task(task_name => ‘li_sql_1‘);
手工执行sql tuning advisor和sql access advisor
标签:bsp 针对 use ash char hunk profile set and
原文地址:http://www.cnblogs.com/Clark-cloud-database/p/7818274.html