oracle 基線與優化:
生產庫sts獲取:
BEGIN dbms_sqltune.create_sqlset(sqlset_name => 'SPS5', sqlset_owner => 'SYS'); END; begin DBMS_SCHEDULER.CREATE_JOB(job_name => 'SPS5', job_type => 'PLSQL_BLOCK', job_action => 'DECLARE bf VARCHAR2(98); BEGIN <span style="color:#ff6666;"> bf := q''#UPPER(PARSING_SCHEMA_NAME) = ''SYS'' AND UPPER(SQL_TEXT) = ''SELECT COUNT(*) FROM SYS.SPS_TEST'' #'</span>'; dbms_sqltune.capture_cursor_cache_sqlset( sqlset_name=>''SPS5'', time_limit=>''120'', repeat_interval=>''5'', basic_filter=>bf, sqlset_owner=>''SYS''); END;', enabled => TRUE); end;
生產庫sts信息查詢:
select name,statement_count from dba_sqlset;導出前准備:(幫助理解)
BEGIN DBMS_SQLTUNE.CREATE_STGTAB_SQLSET('PACK_SQLSET', 'SYSTEM'); END; BEGIN DBMS_SQLTUNE.PACK_STGTAB_SQLSET('SP52', 'SYS', 'PACK_SQLSET', 'SYSTEM'); END; SELECT * FROM SYSTEM.PACK_SQLSET導出並傳輸到測試庫:
執行:
begin DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET('SPS5','SYS',TRUE,'PACK_SQLSET','SYSTEM'); end;
測試庫上執行語句:
alter system flush buffer_cache; alter system flush shared_pool; select count(*) from SYS.SPS_TEST; SELECT COUNT(*) FROM SYS.SPS_TEST創建執行SQL分析
declare sts_task varchar2(64); begin sts_task := dbms_sqlpa.create_analysis_task(task_name => 'SPS5', description => 'experiment11gR2 execute', sqlset_name => 'SPS5'); end;執行分析:
declare exe_task varchar2(64); begin exe_task := dbms_sqlpa.execute_analysis_task(task_name => 'SPS5', execution_name => 'SPS51', execution_type => 'CONVERT SQLSET', <span style="color:#3333ff;"> --sts獲取</span> execution_desc => '11g sql trail'); end; declare exe_task varchar2(64); begin exe_task := dbms_sqlpa.execute_analysis_task(task_name => 'SPS5', execution_name => 'SPS52', execution_type => 'TEST EXECUTE', execution_desc => '11g sql trail2'); end;
begin DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name => 'SPS5', execution_type => 'COMPARE PERFORMANCE', execution_name => 'Compare_elapsed_time2', execution_params => dbms_advisor.arglist('execution_name1', 'SPS51', 'execution_name2', 'SPS52', 'comparison_metric', 'elapsed_time')); end;
select xmltype(dbms_sqlpa.report_analysis_task('SPS5', 'html', 'typical', 'all', null, 100, 'Compare_elapsed_time')).getclobval(0, 0) from dual;
General Information
其他:
--比較CPU_TIME begin dbms_sqlpa.execute_analysis_task(task_name => '11gsps2', execution_name => 'comparecpu', execution_type => 'COMPARE PERFORMANCE', execution_params => dbms_advisor.arglist('COMPARISON_METRIC', 'CPU_TIME', 'EXECUTION_NAME1', '11g_trail', 'EXECUTION_NAME2', '11g_trail2'), execution_desc => 'Compare 10g SQL Trace Performance to 11g Test-Execute for CPU_TIME'); end; / --比較BUFFER_GETS begin dbms_sqlpa.execute_analysis_task(task_name => '11gsps2', execution_name => 'comparbuffergets', execution_type => 'COMPARE PERFORMANCE', execution_params => dbms_advisor.arglist('COMPARISON_METRIC', 'BUFFER_GETS', 'EXECUTION_NAME1', '11g_trail', 'EXECUTION_NAME2', '11g_trail2'), execution_desc => 'Compare 10g SQL Trace Performance to 11g Test-Execute for BUFFER_GETS'); end; --比較實際執行時長 begin DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name => '11gsps2', execution_type => 'COMPARE PERFORMANCE', execution_name => 'Compare_elapsed_time', execution_params => dbms_advisor.arglist('execution_name1', '11g_trail', 'execution_name2', '11g_trail2', 'comparison_metric', 'elapsed_time')); end; / --比較物理讀 begin DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(task_name => '11gsps2', execution_type => 'COMPARE PERFORMANCE', execution_name => 'Compare_physical_reads0', execution_params => dbms_advisor.arglist('execution_name1', '11g_trail', 'execution_name2', '11g_trail2', 'comparison_metric', 'disk_reads')); end; / set long 100000 longchunksize 100000 linesize 200 head off feedback off echo off spool spa_report_elapsed_time.html SELECT dbms_sqlpa.report_analysis_task('SPA_TEST', 'HTML', 'ALL','ALL', execution_name=>'Compare_elapsed_time') FROM dual; spool off