sql tuning set是性能调整中重要的一个环节。以下我们先看该功能的使用,再来说明其用途。
(1)创建:
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Sat Dec 22 21:48:06 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn scott/scott
Connected.
SQL> begin
2 dbms_sqltune.create_sqlset(sqlset_name=>'my_sql_tuningset',
3 description=>'i/o intensive workload');
4 end;
5 /
PL/SQL procedure successfully completed.
(2)显示:
SQL>select * from table(dbms_sqltune.select_sqlset('my_sql_tuningset','(disk_reads/buffer_gets)>=0.75'));
no rows selected
SQL> select * from dba_sqlset;
ID NAME OWNER DESCRIPTI CREATED LAST_MODI STATEMENT_COUNT
---------- ---------------------- -------------- --------------------------- ---------------- --------------------- ---------------------------
1 my_seq_tuning_set SCOTT I/O intensive workload 22-DEC-12 22-DEC-12 0
2 my_sql_tuningset SCOTT i/o intensive workload 22-DEC-12 22-DEC-12 0
注:ID为1的记录是以前创建的。
这时,dba_sqlset_statements和dba_sqlset_binds表中并没有相关记录
(3)删除:
SQL> begin
2 dbms_sqltune.drop_sqlset(sqlset_name=>'my_seq_tuning_set');
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> select * from dba_sqlset;
--再次查询
ID NAME OWNER DESCRIPTI CREATED LAST_MODI STATEMENT_COUNT
---------- ---------------------- -------------- --------------------------- ---------------- --------------------- ---------------------------
2 my_sql_tuningset SCOTT i/o intensive workload 22-DEC-12 22-DEC-12 0
(4)加载:
load_sqlset过程将sql语句放入sql tuning set(简称STS)中。
可以放入STS的资源包括负载报告(workload repository)、其他STS或者共享sql区(shared SQL area)。
对于负载报告和STS,预定义的表函数可以从资源表中选择列并放入新的STS中。
下面这个例子中,调用名字为peak baseline的AWR基线加载到my_sql_tuning_set中。
数据按照花费时间排序,只选择前三十个sql语句。
未操作:
DECLARE
baseline_cursor DBMS_SQLTUNE.SQLSET_CURSOR;--声明游标类型
BEGIN
OPEN baseline_cursor FOR--将负载报告内容放入该游标中
SELECT VALUE(p)
FROM TABLE (DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(
'peak baseline',NULL, NULL,'elapsed_time',NULL, NULL, NULL,30)) p;--
DBMS_SQLTUNE.LOAD_SQLSET(sqlset_name => 'my_sql_tuningset',
populate_cursor => baseline_cursor);--将负载报告的内容放入已经定义的STS中
END;
/
修改:
BEGIN
DBMS_SQLTUNE.DELETE_SQLSET(
sqlset_name => 'my_sql_tuning_set',
basic_filter => 'executions < 50');
END;
/
转换:
BEGIN
DBMS_SQLTUNE.create_stgtab_sqlset(
table_name => 'my_10g_staging_table',
schema_name => 'dba1',
db_version => DBMS_SQLTUNE.STS_STGTAB_10_2_VERSION );
END;
/
BEGIN
DBMS_SQLTUNE.pack_stgtab_sqlset(
sqlset_name => 'my_sts',
sqlset_owner => 'hr',
staging_table_name => 'my_10g_staging_table',
staging_schema_owner => 'dba1',
db_version => DBMS_SQLTUNE.STS_STGTAB_10_2_VERSION );
END;
/
BEGIN
DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET(
sqlset_name => '%',
replace => TRUE,
staging_table_name => 'my_10g_staging_table');
END;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26451536/viewspace-753080/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26451536/viewspace-753080/