如何建立SQL 調優集(二) 從AWR載入
Example 1
Example 2
Example 3
Verify how many sqls got loaded in the STS.
Verify the sql statements and its sql_d in the STS
Verify the execution Plan of a SQL_ID in the STS for an user sql.
Verify the Plan baseline to check how many plans before.
Verify the Plan baseline to check how many plans in plan baseline.
--From SNAP ID 1,2 Load sql id dmqch2g6rtvzf with plan_hash_value
--and its sql plan and all execution statistics
--into STS test2 .
--This will create an empty SQL Tuning set test2.
exec DBMS_SQLTUNE.CREATE_SQLSET('test2');
declare
baseline_ref_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
begin
open baseline_ref_cursor for
select VALUE(p) from table(DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(1, 2,
'sql_id='||CHR(39)||'dmqch2g6rtvzf'||CHR(39)||' and plan_hash_value=1421641795',NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;
DBMS_SQLTUNE.LOAD_SQLSET('test2', baseline_ref_cursor);
end;
--and its sql plan and all execution statistics
--into STS test2 .
--This will create an empty SQL Tuning set test2.
exec DBMS_SQLTUNE.CREATE_SQLSET('test2');
declare
baseline_ref_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
begin
open baseline_ref_cursor for
select VALUE(p) from table(DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(1, 2,
'sql_id='||CHR(39)||'dmqch2g6rtvzf'||CHR(39)||' and plan_hash_value=1421641795',NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;
DBMS_SQLTUNE.LOAD_SQLSET('test2', baseline_ref_cursor);
end;
By default, select_workload_repository does not include the SQL Plan.
we should pass TYPICAL or ALL as the 'attribute_list' parameter to get
the plan. The default value of BASIC does not capture the plan. Please
refer to PL/SQL Package guide for the DBMS_SQLTUNE package.
we should pass TYPICAL or ALL as the 'attribute_list' parameter to get
the plan. The default value of BASIC does not capture the plan. Please
refer to PL/SQL Package guide for the DBMS_SQLTUNE package.
DBMS_SQLTUNE.SELECT_WORKLAOD REPOSITORY (
baseline_name IN VARCHAR2,
basic_filter IN VARCHAR2 := NULL,
object_filter IN VARCHAR2 := NULL,
ranking_measure1 IN VARCHAR2 := NULL,
ranking_measure2 IN VARCHAR2 := NULL,
ranking_measure3 IN VARCHAR2 := NULL,
result_percentage IN NUMBER := 1,
result_limit IN NUMBER := NULL)
attribute_list IN VARCHAR2 := NULL)
RETURN sys.sqlset PIPELINED;
baseline_name IN VARCHAR2,
basic_filter IN VARCHAR2 := NULL,
object_filter IN VARCHAR2 := NULL,
ranking_measure1 IN VARCHAR2 := NULL,
ranking_measure2 IN VARCHAR2 := NULL,
ranking_measure3 IN VARCHAR2 := NULL,
result_percentage IN NUMBER := 1,
result_limit IN NUMBER := NULL)
attribute_list IN VARCHAR2 := NULL)
RETURN sys.sqlset PIPELINED;
Example 2
--This will load all the sqls captured in AWR snapshot FOR SNAP ID 1 AND 2 .
EXEC DBMS_SQLTUNE.CREATE_SQLSET('test3');
declare
baseline_ref_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
begin
open baseline_ref_cursor for
select VALUE(p) from table(DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(1, 2,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;
DBMS_SQLTUNE.LOAD_SQLSET('test3', baseline_ref_cursor);
end;
/
EXEC DBMS_SQLTUNE.CREATE_SQLSET('test3');
declare
baseline_ref_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
begin
open baseline_ref_cursor for
select VALUE(p) from table(DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(1, 2,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,'ALL')) p;
DBMS_SQLTUNE.LOAD_SQLSET('test3', baseline_ref_cursor);
end;
/
Example 3
In the following example all the sql plans for a given range of awr snapshot ids will capured in an STS.
set echo on
-- Displaying the list of AWR snapshot ids.
pause
select s.snap_id snap_id
, to_char(s.end_interval_time,'dd Mon YYYY HH24:mi') snapdate
from dba_hist_snapshot s order by snapdate;
pause
--These are the avaliable AWR snapshot ids.
pause
--Enter owner of SQL TUNING SET, owner name may be case sensitive in 11g.
--Enter the snapshot range from which you want capture the sql plans.
--Enter the STS NAME.
pause
declare
own VARCHAR2(30) := '&owner';
bid NUMBER := '&begin_snap';
eid NUMBER := '&end_snap';
stsname VARCHAR2(30) :='&stsname';
sts_cur dbms_sqltune.sqlset_cursor;
begin
dbms_sqltune.create_sqlset(sqlset_name => stsname, sqlset_owner =>
own);
open sts_cur for
select value(P) from table(dbms_sqltune.select_workload_repository(bid,
eid, null, null, null, null, null, 1, null, 'ALL')) P;
dbms_sqltune.load_sqlset(sqlset_name => stsname,
populate_cursor => sts_cur,
load_option => 'MERGE');
end;
/
--Now Verify the STS.
pause
select NAME,OWNER,CREATED,STATEMENT_COUNT FROM DBA_SQLSET;
set echo on
-- Displaying the list of AWR snapshot ids.
pause
select s.snap_id snap_id
, to_char(s.end_interval_time,'dd Mon YYYY HH24:mi') snapdate
from dba_hist_snapshot s order by snapdate;
pause
--These are the avaliable AWR snapshot ids.
pause
--Enter owner of SQL TUNING SET, owner name may be case sensitive in 11g.
--Enter the snapshot range from which you want capture the sql plans.
--Enter the STS NAME.
pause
declare
own VARCHAR2(30) := '&owner';
bid NUMBER := '&begin_snap';
eid NUMBER := '&end_snap';
stsname VARCHAR2(30) :='&stsname';
sts_cur dbms_sqltune.sqlset_cursor;
begin
dbms_sqltune.create_sqlset(sqlset_name => stsname, sqlset_owner =>
own);
open sts_cur for
select value(P) from table(dbms_sqltune.select_workload_repository(bid,
eid, null, null, null, null, null, 1, null, 'ALL')) P;
dbms_sqltune.load_sqlset(sqlset_name => stsname,
populate_cursor => sts_cur,
load_option => 'MERGE');
end;
/
--Now Verify the STS.
pause
select NAME,OWNER,CREATED,STATEMENT_COUNT FROM DBA_SQLSET;
Verify how many sqls got loaded in the STS.
SELECT NAME,OWNER,CREATED,STATEMENT_COUNT FROM DBA_SQLSET where name='test3';
Verify the sql statements and its sql_d in the STS
select sql_id, substr(sql_text,1, 15) text
from dba_sqlset_statements
where sqlset_name = 'test3'
order by sql_id;
from dba_sqlset_statements
where sqlset_name = 'test3'
order by sql_id;
Verify the execution Plan of a SQL_ID in the STS for an user sql.
SELECT * FROM table (
DBMS_XPLAN.DISPLAY_SQLSET(
'test3','dmqch2g6rtvzf'));
DBMS_XPLAN.DISPLAY_SQLSET(
'test3','dmqch2g6rtvzf'));
Verify the Plan baseline to check how many plans before.
SQL> select count(*) from dba_sql_plan_baselines;
2) Load the Sql Plan Baseline from STS.
set serveroutput on
declare
my_integer pls_integer;
begin
my_integer := dbms_spm.load_plans_from_sqlset (
sqlset_name => 'test2',
sqlset_owner => 'SYS',
fixed => 'NO',
enabled => 'YES');
DBMS_OUTPUT.PUT_line(my_integer);
end;
/
declare
my_integer pls_integer;
begin
my_integer := dbms_spm.load_plans_from_sqlset (
sqlset_name => 'test2',
sqlset_owner => 'SYS',
fixed => 'NO',
enabled => 'YES');
DBMS_OUTPUT.PUT_line(my_integer);
end;
/
Note
Ensure that your source STS capture does not have any sys or system or default user queries from user like sysman. Always ensure to filter the SYS or system schema or any default user like sysman related
queries while loading in the SPM in 11g by using basic_filter
for example using the following procedure :-
set serveroutput on
declare
my_integer pls_integer;
begin
my_integer := dbms_spm.load_plans_from_sqlset (
sqlset_name => 'test2',
sqlset_owner => 'SYS',
fixed => 'NO',
enabled => 'YES',
basic_filter => 'parsing_schema_name != ''SYS''');
DBMS_OUTPUT.PUT_line(my_integer);
end;
/
Ensure that your source STS capture does not have any sys or system or default user queries from user like sysman. Always ensure to filter the SYS or system schema or any default user like sysman related
queries while loading in the SPM in 11g by using basic_filter
for example using the following procedure :-
set serveroutput on
declare
my_integer pls_integer;
begin
my_integer := dbms_spm.load_plans_from_sqlset (
sqlset_name => 'test2',
sqlset_owner => 'SYS',
fixed => 'NO',
enabled => 'YES',
basic_filter => 'parsing_schema_name != ''SYS''');
DBMS_OUTPUT.PUT_line(my_integer);
end;
/
Verify the Plan baseline to check how many plans in plan baseline.
SQL> select count(*) from dba_sql_plan_baselines;
On 11.1.0.7.0 Apply one off patch for which is duplicate of
So Please apply one off patch for
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22034023/viewspace-708258/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何建立SQL 調優集(—) 從共享池載入SQL
- mysql調優從書寫sql開始MySql
- 【sql調優】使用繫結變數(二)SQL變數
- 我如何調優SQL Server查詢SQLServer
- SQL調優SQL
- sql監控與調優(sql monitoring and tuning) (轉載)SQL
- sql調優1SQL
- oracle sql調優OracleSQL
- MySQL調優篇 | SQL調優實戰(5)MySql
- 【效能調優】Oracle AWR報告指標全解析Oracle指標
- Teradata SQL調優SQL
- 程式集載入與反射(二):例項篇反射
- JVM原理及調優(4)——類載入機制JVM
- R(二)建立資料集
- Multidex(二)之 Dex 預載入優化IDE優化
- MySQL索引和SQL調優MySql索引
- SQL調優真實案例SQL
- SQL效能調優綜述SQL
- [精華zt] SQL調優整理SQL
- 如何調優 Oracle SQL系列文章:查詢優化器介紹OracleSQL優化
- 【AWR】Oracle資料庫建立awr基線Oracle資料庫
- 用MSCS建立SQL Server叢集SQLServer
- 【sql調優之執行計劃】使用hint(二)Hints for Access PathsSQL
- SQL Server一次SQL調優案例SQLServer
- Mysql 效能調優 二 1MySql
- Mysql 效能調優 二 2MySql
- 【調優】CBO基礎(二)
- 從cmd中匯入.SQL檔案並建立資料庫SQL資料庫
- 如何從文字檔案讀入 SQL 引數SQL
- SQL 調優一般思路SQL
- 【sql調優】動態取樣SQL
- 一條大sql的調優SQL
- 效能調優——SQL最佳化SQL
- SQL執行內幕:從執行原理看調優的本質SQL
- 生產環境sql語句調優實戰第二篇SQL
- Oracle SQL調優系列之SQL Monitor ReportOracleSQL
- 主從延遲調優思路
- Spark學習——效能調優(二)Spark