Oracle SQL Performance Analyzer的使用
通過 SPA,您可以根據各種更改類型(如初始化參數更改、最佳化器統計重新整理和資料庫升級)播放特定的 SQL 或整個 SQL 負載,然後產生比較報告,協助您評估它們的影響。
在 Oracle Database 11g 之前的版本中,我必須捕獲所有 SQL 陳述式,通過跟蹤運行這些語句, 然後得到執行計畫 — 這是一項極其耗時又極易出錯的任務。新版本中,我們不需要再那樣做了, 我改用非常簡單而有效 SQL Performance Analyzer。
在CentOS 6.4下安裝Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虛擬機器中安裝步驟
Debian 下 安裝 Oracle 11g XE R2
---使用情境
1.資料庫升級
2.實施最佳化建議
3.更改方案
4.收集統計資訊
5.更改資料庫參數
6.更改作業系統和硬體
create tablespace test
datafile 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\test01.DBF'
size 5000m
autoextend on
next 100m maxsize unlimited
extent management local autoallocate
segment space management auto;
create table t1
(
sid int not null ,
sname varchar2(10)
)
tablespace test;
-2.-迴圈匯入資料
declare
maxrecords constant int:=1000000;
i int :=1;
begin
for i in 1..maxrecords loop
insert into t1 values(i,'ocpyang');
end loop;
dbms_output.put_line(' 成功錄入資料! ');
commit;
end;
/
update t1 set sname='蘇州' where sid=500001;
update t1 set sname='南京' where sid=600001;
---3.收集統計資訊
exec dbms_stats.gather_table_stats(USER,'T1',CASCADE=>TRUE)
alter system flush shared_pool;
---4.執行查詢
select count(*) from t1 where sid<=100;
select count(*) from t1 where sid<=500;
select count(*) from t1 where sid>50000;
---5.建立STS
BEGIN
DBMS_SQLTUNE.DROP_SQLSET(
sqlset_name => 'OCPYANG_STS'
);
END;
/
BEGIN
DBMS_SQLTUNE.CREATE_SQLSET(
sqlset_name => 'OCPYANG_STS',
sqlset_owner => 'SYS',
description => 'ocpyangtest');
END;
/
---6.載入sql最佳化集
set serveroutput on
DECLARE
cur01 dbms_sqltune.sqlset_cursor;
BEGIN
open cur01 for select value(a) from table(dbms_sqltune.select_cursor_cache
(
basic_filter => 'sql_text like ''%T1%'' and parsing_schema_name =''SYS''',
attribute_list => 'ALL'
)
) a;
dbms_sqltune.load_sqlset(
sqlset_name => 'OCPYANG_STS',
populate_cursor => cur01);
close cur01;
END;
/
/*********有兩個參數值得特別說明:
1)SELECT_CURSOR_CACHE的第一個參數是basic_filter ,它可以取的值有:
sql_id VARCHAR(13),
force_matching_signature NUMBER,
sql_text CLOB,
object_list sql_objects,
bind_data RAW(2000),
parsing_schema_name VARCHAR2(30),
module VARCHAR2(48),
action VARCHAR2(32),
elapsed_time NUMBER,
cpu_time NUMBER,
buffer_gets NUMBER,
disk_reads NUMBER,
direct_writes NUMBER,
rows_processed NUMBER,
fetches NUMBER,
executions NUMBER,
end_of_fetch_count NUMBER,
optimizer_cost NUMBER,
optimizer_env RAW(1000),
priority NUMBER,
command_type NUMBER,
first_load_time VARCHAR2(19),
stat_period NUMBER,
active_stat_period NUMBER,
other CLOB,
plan_hash_value NUMBER,
sql_plan sql_plan_table_type,
bind_list sql_binds
2)SELECT_CURSOR_CACHE的最後一個參數是attribute_list
BASIC (default) -all attributes (such as execution statistics and binds) are returned except the plans The execution context is always part of the result.
TYPICAL - BASIC + SQL plan (without row source statistics) and without object reference list
ALL - return all attributes
Comma separated list of attribute names this allows to return only a subset of SQL attributes: EXECUTION_STATISTICS, BIND_LIST, OBJECT_LIST, SQL_PLAN,SQL_PLAN_STATISTICS: similar to SQL_PLAN + row source statistics
*********/
更多詳情見請繼續閱讀下一頁的精彩內容: