ORACLE SPA(SQL Performance Analyzer)讲解

Posted Oracle一体机用户组

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ORACLE SPA(SQL Performance Analyzer)讲解相关的知识,希望对你有一定的参考价值。

作者简介

孙显鹏,Oracle十年从业经验,拥有11G ocp认证,精通内部原理,擅长调优,解决疑难问题,致力于帮助客户解决生产过程过出现的性能问题,提高生产效率!爱好书法!


前言:


迁移数据库,修改数据库参数或者升级数据库后,如何确定原库的SQL在目标库执行时没有出现性能衰退呢?使用ORACLE的SPA(SQL Performance Analyzer)包可完成该功能。SPA通过比较原库和目标库收集的SQL集合的执行统计数据,最终给我们一个比较结果,通过分析对比结果数据可明确哪些SQL出现性能衰退。查找衰退原因修复问题,确保SQL在迁移后能满足业务需求。这样的迁移才是完整的。接下来演示如何使用SPA测试SQL的执行情况。


场景:


原库为11.2.0.3,目标库为12.2.0.1,把目标库当做要升级的数据库(通过xtts迁移了两个表空间),在目标库中建立spa-sts,首先通过dblink在原库执行sql trial,然后在目标库执行SQL trial,最后比较两个SQL trial。这样就达到了对比升级后系统是否可以符合业务实际要求。


操作步骤:


准备测试SQL:


delete from yaclaim.c_pay where rownum<100;
delete from yaclaim.c_pay where rownum<10;
select * from yaclaim.c_pay where rownum<100;
select count(*) from yaclaim.c_pay where CLAIMTIME>to_date('2018-03-20','yyyy-mm-dd');
select count(*) from yaclaim.c_pay where CLAIMTIME<to_date('2018-03-20','yyyy-mm-dd');


create sts :


sqlplus / as sysdba 
exec dbms_sqltune.create_sqlset(sqlset_name => 'test_set', description =>'11g workload upgrade to 12c');
declare
mycur dbms_sqltune.sqlset_cursor;
begin
open mycur for
select value (P)
from table(dbms_sqltune.select_cursor_cache('sql_text like ''%c_pay%''', null, null, null, null,1, null, 'ALL')
) P;
dbms_sqltune.load_sqlset(sqlset_name => 'test_set', populate_cursor => mycur);
end;
/


如果获取特定schema信息如下:


–dbms_sqltune.select_cursor_cache(‘parsing_schema_name<> ”YACLAIM”’, null, null, null, null,1, null, ‘ALL’)

 


select sql_text from dba_sqlset_statements where sqlset_name='test_set';


Create a task to run Sql Performance Analyzer:


create_sqlpa_task.sql 
---create sql task
-- declare vars
var tname varchar2(30);
var sname varchar2(30);
-- init vars
exec :sname := 'test_set';
exec :tname := 'my_sqlpa_demo_task';


— 1.create a task with a purpose of change impact analysis


exec :tname := dbms_sqlpa.create_analysis_task(sqlset_name => :sname, task_name => :tname);


— 2.check task status


SELECT task_name, status 
FROM user_advisor_tasks
WHERE task_name = :tname;


Execute Before Change TEST EXECUTE (Pre-Change SQL Trial):


beforechange.sql

 

–Now I am ready to run the Before Change Execute


begin
DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(
task_name => 'my_sqlpa_demo_task',
execution_type => 'TEST EXECUTE',
execution_name => 'BEFORE',
execution_params => dbms_advisor.arglist('DATABASE_LINK', 'TTSLINK'));
end;
/


Execute After Change TEST EXECUTE (Post-Change SQL Trial):


begin 
DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(
task_name => 'my_sqlpa_demo_task',
execution_type => 'TEST EXECUTE',
execution_name => 'AFTER');
end;
/


Comparing SQL Trials:


–Now we need to compare the 2 executions Before Change and After Change.

 

–I am selecting the comparison matrix as BUFFER_GETS.

 

–compare_runs.sql


begin 
DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(
task_name => 'my_sqlpa_demo_task',
execution_type => 'COMPARE PERFORMANCE',
execution_name => 'DEMOTASK03',
execution_params => dbms_advisor.arglist(
'comparison_metric',
'buffer_gets',
'optimizer_cost',
'physical_i/o'));
end;
/


Generate compare report:


–Now I will generate a compare report

 

–The report format can be TEXT,html,OR XML

 

–report.sql


set long 100000 longchunksize 100000 linesize 200 head off feedback off echo off 
spool report.html
SELECT dbms_sqlpa.report_analysis_task('my_sqlpa_demo_task', 'HTML', 'ALL','ALL') FROM dual;
spool off


analyze report:


这里贴出部分报告


ORACLE SPA(SQL Performance Analyzer)讲解

ORACLE SPA(SQL Performance Analyzer)讲解

ORACLE SPA(SQL Performance Analyzer)讲解



原创文章,版权归本文作者所有,如需转载请注明出处


喜欢本文请长按下方的二维码订阅Oracle一体机用户组

以上是关于ORACLE SPA(SQL Performance Analyzer)讲解的主要内容,如果未能解决你的问题,请参考以下文章

『ORACLE』SPA性能分析器

ORACLE SPA

spring data spa 和 oracle 包

sh 通过/ u / Nikolas Britton测试密码吞吐量的单线程@ https://www.systutorials.com/5450/improving-sshscp-performanc

SPA 介绍

问题解决:信息提示SpringBoot启动时提示The APR based Apache Tomcat Native library which allows optimal performanc(代