欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle SQL Performance Analyzer的使用

程序员文章站 2024-02-20 12:13:16
...

在 Oracle Database 11g 之前的版本中,我必须捕获所有 SQL 语句,通过跟踪运行这些语句, 然后得到执行计划 mdash; 这是一项极

通过 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

select count(*) from t1 where sid

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

*********/

更多详情见请继续阅读下一页的精彩内容:

Oracle SQL Performance Analyzer的使用