通过 SPA,您能够依据各种更改类型(如初始化參数更改、优化器统计刷新和数据库升级)播放特定的

SQL 或整个 SQL 负载,然后生成比較报告,帮助您评估它们的影响.

在 Oracle Database 11g 之前的版本号中,我必须捕获全部 SQL 语句,通过跟踪执行这些语句,

然后得到运行计划 — 这是一项极其耗时又极易出错的任务。新版本号中,我们不须要再那样做了,

我改用很easy而有效的 SQL Performance Analyzer。

---使用场景

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

*********/

---7.查询sql优化集

select sql_id,sql_text from dba_sqlset_statements

where sqlset_name='OCPYANG_STS' and sql_text like '% from t1%';

---8.新建SPA

var v_task varchar2(64);

begin

:v_task:=dbms_sqlpa.create_analysis_task(

sqlset_name => 'OCPYANG_STS',

task_name => 'SPA01'

);

end;

/

/**********语法

Syntax

SQL text format. This form of the function is called to prepare the analysis of a single statement given its text.

DBMS_SQLPA.CREATE_ANALYSIS_TASK(

  sql_text         IN CLOB,

  bind_list        IN sql_binds := NULL,

  parsing_schema   IN VARCHAR2  := NULL,

  task_name        IN VARCHAR2  := NULL,

  description      IN VARCHAR2  := NULL)

RETURN VARCHAR2;

SQL ID format. This form of the function is called to prepare the analysis of a single statement from the cursor cache given its identifier.

DBMS_SQLPA.CREATE_ANALYSIS_TASK(

  sql_id           IN VARCHAR2,

  plan_hash_value  IN NUMBER    := NULL,

  task_name        IN VARCHAR2  := NULL,

  description      IN VARCHAR2  := NULL)

RETURN VARCHAR2;

Workload Repository format. This form of the function is called to prepare the analysis of a single statement from the workload repository given a range of snapshot identifiers.

DBMS_SQLPA.CREATE_ANALYSIS_TASK(

  begin_snap       IN NUMBER,

  end_snap         IN NUMBER,

  sql_id           IN VARCHAR2,

  plan_hash_value  IN NUMBER    := NULL,

  task_name        IN VARCHAR2  := NULL,

  description      IN VARCHAR2  := NULL)

RETURN VARCHAR2;

SQLSET format. This form of the function is called to prepare the analysis of a SQL tuning set.

DBMS_SQLPA.CREATE_ANALYSIS_TASK(

  sqlset_name       IN VARCHAR2,

  basic_filter      IN VARCHAR2 :=  NULL,

  order_by          IN VARCHAR2 :=  NULL,

  top_sql           IN VARCHAR2 :=  NULL,

  task_name         IN VARCHAR2 :=  NULL,

  description       IN VARCHAR2 :=  NULL

  sqlset_owner      IN VARCHAR2 :=  NULL)

RETURN VARCHAR2;

**********/

---9.运行SPA

begin

dbms_sqlpa.execute_analysis_task

(

task_name => 'SPA01',

execution_type => 'test execute',

execution_name => 'before_change'

);

end;

/

/*********语法

DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(

   task_name         IN VARCHAR2,

   execution_type    IN VARCHAR2               := 'test execute',

   execution_name    IN VARCHAR2               := NULL,

   execution_params  IN dbms_advisor.argList   := NULL,

   execution_desc    IN VARCHAR2               := NULL)

 RETURN VARCHAR2;

DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(

   task_name         IN VARCHAR2,

   execution_type    IN VARCHAR2               := 'test execute',

   execution_name    IN VARCHAR2               := NULL,

   execution_params  IN dbms_advisor.argList   := NULL,

   execution_desc    IN VARCHAR2               := NULL);

*********/

---10.改变

create index index_01 on t1(sid,sname)

tablespace test;

exec dbms_stats.gather_table_stats(USER,'T1',CASCADE=>TRUE)

---11.改变后运行

begin

dbms_sqlpa.execute_analysis_task

(

task_name => 'SPA01',

execution_type => 'test execute',

execution_name => 'after_change'

);

end;

/

col TASK_NAME format a30

col EXECUTION_NAME for a30

select execution_name,

status,

execution_end

from DBA_ADVISOR_EXECUTIONS

where task_name='SPA01'

order by execution_end

/

EXECUTION_NAME                 STATUS      EXECUTION_END

------------------------------ ----------- -------------------

before_change                  COMPLETED   2014-05-28 15:43:58

after_change                   COMPLETED   2014-05-28 15:44:58

---12.运行任务比較

begin

dbms_sqlpa.EXECUTE_ANALYSIS_TASK(

task_name        => 'SPA01',

execution_type   => 'compare performance',

execution_params => dbms_advisor.arglist(

'execution_name1',

'before_change',

'execution_name2',

'after_change'));

end;

/

---13.生产报告

set serveroutput on size 999999

set long 100000000

set pagesize 0

set linesize 200

set longchunksize 200

set trimspool on

spool e:\report.txt

select DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA01') from dual;

spool off;

实战:ORACLE SQL Performance Analyzer的更多相关文章

  1. SQL Performance Analyzer

    SQL Performance Analyzer 系统发生变更,比如升级数据库.增加索引,都会可能导致sql的执行计划发生改变,从而影响sql的性能. 如果能预知系统变更会对sql的性能的影响,就可以 ...

  2. Oracle SQL tuning 步骤

    Oracle SQL tuning 步骤 SQL是的全称是Structured Query Language(结构化查询语言).SQL是一个在80年代中期被使用的工业标准数据库查询语言.不要把SQL语 ...

  3. 11g SPA (sql Performance Analyze) 进行升级测试

    注;转自http://ju.outofmemory.cn/entry/77139 11G的新特性SPA(SQL Performance Analyze)现在被广泛的应用到升级和迁移的场景.当然还有一些 ...

  4. ORACLE SQL TUNING ADVISOR 使用方法

    sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法  下面来按照这个顺序来实施 ...

  5. Oracle SQL explain/execution Plan

    From http://blog.csdn.net/wujiandao/article/details/6621073 1. Four ways to get execution plan(anyti ...

  6. 30 分钟快快乐乐学 SQL Performance Tuning

    转自:http://www.cnblogs.com/WizardWu/archive/2008/10/27/1320055.html 有些程序员在撰写数据库应用程序时,常专注于 OOP 及各种 fra ...

  7. Oracle Dynamic Performance Views Version 12.2.0.1

    Oracle Dynamic Performance ViewsVersion 12.2.0.1 https://www.morganslibrary.org/reference/dyn_perf_v ...

  8. A simple way to monitor SQL server SQL performance.

    This is all begins from a mail. ... Dear sir: This is liulei. Thanks for your help about last PM for ...

  9. Oracle SQL Developer 连接 MySQL

    1. 在ORACLE官网下载Oracle SQL Developer第三方数据库驱动 下载页面:http://www.oracle.com/technetwork/developer-tools/sq ...

随机推荐

  1. the field is sometimes used inside synchronized block and sometimes used without synchronization

    http://stackoverflow.com/questions/28715625/is-it-safe-to-use-field-inside-and-outside-synchronized- ...

  2. Tomcat详解

    解压缩下载的Tomcat压缩包,呈现的目录结构如下. bin:目录存放一些启动和关闭Tomcat的可执行程序和相关内容.conf:存放关于Tomcat服务器的全局配置.lib:目录存放Tomcat运行 ...

  3. sizeof(数组)

    这里就不讨论一般的数组长度计算了,只说明一下任何数据到了函数的形参中都将退化为指针,所以计算大小的时候,也是计算的指针的大小 直接上代码了 // class sizeof测试.cpp : 定义控制台应 ...

  4. 1701. Ostap and Partners(并查集-关系)

    1701 又是类似食物链的这一类题 这题是找与根节点的和差关系 因为0节点是已知的 为0  那么所有的都可以转换为与0的和差关系 可以规定合并的两节点 由大的指向小的 然后再更新和差关系 有可能最后有 ...

  5. linux mount 命令详解

    命令格式: mount [-t vfstype] [-o options] device dir 其中: 1.-t vfstype 指定文件系统的类型,通常不必指定.mount 会自动选择正确的类型. ...

  6. python扩展实现方法--python与c混和编程

    前言 需要扩展Python语言的理由: 创建Python扩展的步骤 1. 创建应用程序代码 2. 利用样板来包装代码 a. 包含python的头文件 b. 为每个模块的每一个函数增加一个型如PyObj ...

  7. RMAN数据库异机迁移步骤

    --RMAN数据库异机迁移步骤----------------------------2013/09/28 测试环境:AIX+ora11g   一. source数据库准备.   1.获取数据文件编号 ...

  8. ORACLE SQLloader详细语法

    Oracle   SQL   Loader的详细语法     SQL*LOADER是ORACLE的数据加载工具,通常用来将操作系统文件迁移到ORACLE数据库中.SQL*LOADER是大型数据     ...

  9. extjs分组查询

    <script type="text/jscript"> var grid; Ext.onReady(function () { Ext.QuickTips.init( ...

  10. ASP.NET Web API 如何通过程序控制返回xml还是json

    雖然 ASP.NET Web API 內建支援 JSON 與 XML 兩種輸出格式,並依據瀏覽器端送出的 Accept 標頭自動決定回應的內容格式,不過有時候我們的確也需要讓程式來控制要回應哪種格式, ...