主題:關於Oracle開啓自動收集統計信息的SPA測試
環境:Oracle RAC 11.2.0.4(Primary + Standby)
需求:生產Primary庫因爲歷史緣由關閉了自動統計信息的收集,目前客戶需求是想要從新開啓統計信息的自動收集,雖然通常來講,有了更準確的統計信息,SQL會有更好的執行計劃,但因爲生產環境數據複雜,實際上仍是須要評估哪些SQL會由於從新開啓自動統計信息收集性能反而會降低。
方案:本着儘量減小對生產Primary環境影響的原則,在Standby DG環境臨時開啓snapshot standby來進行SPA(SQL Performance Analyze)測試,比對開啓統計信息自動收集先後的性能差別,給客戶提供有價值的參考。html
檢查自動統計信息的開啓狀態:
select client_name,status from dba_autotask_client;
確認自動統計信息的收集是關閉的,對於「auto optimizer stats collection」的狀態應該是「DISABLED」。sql
SQL> select client_name,status from dba_autotask_client; CLIENT_NAME STATUS ---------------------------------------------------------------- -------- auto optimizer stats collection DISABLED auto space advisor ENABLED sql tuning advisor ENABLED
附:關閉數據庫的自動統計信息收集:數據庫
--光閉自動統計信息收集,(慎用,除非有其餘手工收集統計信息的完整方案,不然不建議關閉) BEGIN DBMS_AUTO_TASK_ADMIN.disable( client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL); END; /
DG備庫保持和主庫同步,因此這些設置項也都是徹底同樣的。windows
主要就是在mount模式下切換數據到snapshot Standby模式再read write打開庫,爲以後測試作準備。下面是核心步驟:性能
SQL> shutdown immediate SQL> startup mount SQL> alter database convert to snapshot standby; SQL> shutdown immediate SQL> startup
關於其餘細節可參考下面文章,主要是爲「開啓11gR2 DG的快照模式」,「後續還原成備庫」 等操做提供參考:測試
進行SPA測試時,強烈建議在數據庫中建立SPA測試專用用戶,這樣能夠與其餘用戶區分開以及避免誤操做。優化
SQL> CREATE USER SPA IDENTIFIED BY SPA DEFAULT TABLESPACE SYSAUX; GRANT DBA TO SPA; GRANT ADVISOR TO SPA; GRANT SELECT ANY DICTIONARY TO SPA; GRANT ADMINISTER SQL TUNING SET TO SPA;
備庫從AWR中採集到SQL。
4.1 獲取AWR快照的邊界IDspa
SET LINES 188 PAGES 1000 COL SNAP_TIME FOR A22 COL MIN_ID NEW_VALUE MINID COL MAX_ID NEW_VALUE MAXID SELECT MIN(SNAP_ID) MIN_ID, MAX(SNAP_ID) MAX_ID FROM DBA_HIST_SNAPSHOT WHERE END_INTERVAL_TIME > trunc(sysdate)-10 ORDER BY 1;
我這裏的結果是:3d
MIN_ID MAX_ID ---------- ---------- 2755 2848
4.2 新建SQL Set
注意:如下的規範部分都是引用以前同事編寫的SPA操做規範。code
參考規範:
EXEC DBMS_SQLTUNE.DROP_SQLSET ( - SQLSET_NAME => '${DBNAME}_SQLSET_${YYYYMMDD}', SQLSET_OWNER => 'SPA'); EXEC DBMS_SQLTUNE.CREATE_SQLSET ( - SQLSET_NAME => '${DBNAME}_SQLSET_${YYYYMMDD}', - DESCRIPTION => 'SQL Set Create at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), - SQLSET_OWNER => 'SPA');
依據個人實驗環境,真實的示例爲:
--鏈接用戶 conn SPA/SPA --若是以前有這個SQLSET的名字,能夠這樣刪除 EXEC DBMS_SQLTUNE.DROP_SQLSET (SQLSET_NAME => 'JYZHAO_SQLSET_20180106', SQLSET_OWNER => 'SPA'); --新建SQLSET:JYZHAO_SQLSET_20180106 EXEC DBMS_SQLTUNE.CREATE_SQLSET ( - SQLSET_NAME => 'JYZHAO_SQLSET_20180106', - DESCRIPTION => 'SQL Set Create at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), - SQLSET_OWNER => 'SPA');
4.3 轉化AWR數據中的SQL,將其載入到SQL Set
從備庫的AWR中提取SQL(這等同於主庫歷史的SQL)。
參考規範:
DECLARE SQLSET_CUR DBMS_SQLTUNE.SQLSET_CURSOR; BEGIN OPEN SQLSET_CUR FOR SELECT VALUE(P) FROM TABLE( DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY( &MINID, &MAXID, 'PARSING_SCHEMA_NAME NOT IN (''SYS'', ''SYSTEM'')', NULL, NULL, NULL, NULL, 1, NULL, 'ALL')) P; DBMS_SQLTUNE.LOAD_SQLSET( SQLSET_NAME => '${DBNAME}_SQLSET_${YYYYMMDD}', SQLSET_OWNER => 'SPA', POPULATE_CURSOR => SQLSET_CUR, LOAD_OPTION => 'MERGE', UPDATE_OPTION => 'ACCUMULATE'); CLOSE SQLSET_CUR; END; /
依據個人實驗環境,真實的示例爲:
DECLARE SQLSET_CUR DBMS_SQLTUNE.SQLSET_CURSOR; BEGIN OPEN SQLSET_CUR FOR SELECT VALUE(P) FROM TABLE( DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY( 2755, 2848, 'PARSING_SCHEMA_NAME NOT IN (''SYS'', ''SYSTEM'')', NULL, NULL, NULL, NULL, 1, NULL, 'ALL')) P; DBMS_SQLTUNE.LOAD_SQLSET( SQLSET_NAME => 'JYZHAO_SQLSET_20180106', SQLSET_OWNER => 'SPA', POPULATE_CURSOR => SQLSET_CUR, LOAD_OPTION => 'MERGE', UPDATE_OPTION => 'ACCUMULATE'); CLOSE SQLSET_CUR; END; /
4.4 打包SQL Set(可不作)
參考規範:
DROP TABLE SPA.${DBNAME}_SQLSETTAB_${YYYYMMDD}; EXEC DBMS_SQLTUNE.CREATE_STGTAB_SQLSET ('${DBNAME}_SQLSETTAB_${YYYYMMDD}', ‘SPA’, 'SYSAUX'); EXEC DBMS_SQLTUNE.PACK_STGTAB_SQLSET ( - SQLSET_NAME => '${DBNAME}_SQLSET_${YYYYMMDD}', - SQLSET_OWNER => ‘SPA’, - STAGING_TABLE_NAME => '${DBNAME}_SQLSETTAB_${YYYYMMDD}', - STAGING_SCHEMA_OWNER => ‘SPA’);
依據個人實驗環境,真實的示例爲:
DROP TABLE SPA.JYZHAO_SQLSETTAB_20180106; EXEC DBMS_SQLTUNE.CREATE_STGTAB_SQLSET ('JYZHAO_SQLSETTAB_20180106', 'SPA', 'SYSAUX'); EXEC DBMS_SQLTUNE.PACK_STGTAB_SQLSET ( - SQLSET_NAME => 'JYZHAO_SQLSET_20180106', - SQLSET_OWNER => 'SPA', - STAGING_TABLE_NAME => 'JYZHAO_SQLSETTAB_20180106', - STAGING_SCHEMA_OWNER => 'SPA');
說明:其實在我這裏的測試場景下,這一步是不須要作的。由於備庫的SQL Set能夠直接在後面引用,不須要像SPA經典場景中,是從生產源環境打包導出來後,在測試環境再導入進去,再解包爲SQL Set。
5.1 建立SPA分析任務
參考規範:
VARIABLE SPA_TASK VARCHAR2(64); EXEC :SPA_TASK := DBMS_SQLPA.CREATE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_${YYYYMMDD}', - DESCRIPTION => 'SPA Analysis task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), - SQLSET_NAME => '${DBNAME}_SQLSET_${YYYYMMDD}', - SQLSET_OWNER => ‘SPA’);
依據個人實驗環境,真實的示例爲:
--建立SPA分析任務: VARIABLE SPA_TASK VARCHAR2(64); EXEC :SPA_TASK := DBMS_SQLPA.CREATE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - DESCRIPTION => 'SPA Analysis task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), - SQLSET_NAME => 'JYZHAO_SQLSET_20180106', - SQLSET_OWNER => 'SPA');
5.2 獲取變動前的SQL執行效率
參考規範:
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_${YYYYMMDD}', - EXECUTION_NAME => 'EXEC_10G_${YYYYMMDD}', - EXECUTION_TYPE => 'CONVERT SQLSET', - EXECUTION_DESC => 'Convert 10g SQLSET for SPA Task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
依據個人實驗環境,真實的示例爲:
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - EXECUTION_NAME => 'EXEC_BEFORE_20180106', - EXECUTION_TYPE => 'CONVERT SQLSET', - EXECUTION_DESC => 'Convert Before gathering stats SQLSET for SPA Task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
5.3 開啓變動操做
變動內容:開啓統計信息自動收集並確認已經成功收集了最新的統計信息。
這裏首先須要開啓統計信息自動收集,並能夠把自動收集的窗口時間提早到如今,減小等待的時間。
--檢查自動統計信息的開啓狀態: select client_name,status from dba_autotask_client; --啓動自動統計信息收集 BEGIN DBMS_AUTO_TASK_ADMIN.enable( client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL); END; /
查看窗口任務和有關統計信息自動收集的任務執行狀態:
select window_name,repeat_interval,duration,enabled from dba_scheduler_windows; select owner, job_name, status, ACTUAL_START_DATE, RUN_DURATION from dba_scheduler_job_run_details where job_name like 'ORA$AT_OS_OPT_S%' order by 4;
調整窗口任務的下一次執行時間:
--須要確認JOB能夠啓動 alter system set job_queue_processes=1000; --調整窗口任務的下一次執行時間 EXEC DBMS_SCHEDULER.SET_ATTRIBUTE('SATURDAY_WINDOW','repeat_interval','freq=daily;byday=SAT;byhour=17;byminute=10;bysecond=0');
更多有關調整窗口和自動任務的內容可參考文章:
5.4 變動後再次分析性能
測試運行SQL Tuning Set中的SQL語句,分析全部語句在收集統計信息以後的執行效率:
參考規範:
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_${YYYYMMDD}', - EXECUTION_NAME => 'EXEC_11G_${YYYYMMDD}', - EXECUTION_TYPE => 'TEST EXECUTE', - EXECUTION_DESC => 'Execute SQL in 11g for SPA Task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
依據個人實驗環境,真實的示例爲:
EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - EXECUTION_NAME => 'EXEC_AFTER_20180106', - EXECUTION_TYPE => 'TEST EXECUTE', - EXECUTION_DESC => 'Execute SQL After gathering stats for SPA Task at : '||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
5.5 變動先後性能對比
獲得兩次SQL Trail以後,能夠對比兩次Trial之間的SQL執行性能,能夠從不一樣的維度對兩次Trail中的全部SQL進行對比分析,主要關注的維度有:SQL執行時間,SQL執行的CPU時間,SQL執行的邏輯讀。
參考規範:
1). 對比兩次Trail中的SQL執行時間 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_${YYYYMMDD}', - EXECUTION_NAME => 'COMPARE_ET_${YYYYMMDD}', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'ELAPSED_TIME', - 'EXECUTE_FULLDML', 'TRUE', - 'EXECUTION_NAME1','EXEC_10G_${YYYYMMDD}', - 'EXECUTION_NAME2','EXEC_11G_${YYYYMMDD}'), - EXECUTION_DESC => 'Compare SQLs between 10g and 11g at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 2). 對比兩次Trail中的SQL執行的CPU時間 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_${YYYYMMDD}', - EXECUTION_NAME => 'COMPARE_CT_${YYYYMMDD}', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'CPU_TIME', - 'EXECUTION_NAME1','EXEC_10G_${YYYYMMDD}', - 'EXECUTION_NAME2','EXEC_11G_${YYYYMMDD}'), - EXECUTION_DESC => 'Compare SQLs between 10g and 11g at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 3). 對比兩次Trail中的SQL執行的邏輯讀 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_D', - EXECUTION_NAME => 'COMPARE_BG_D', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'BUFFER_GETS', - 'EXECUTION_NAME1','EXEC_10G_${YYYYMMDD}', - 'EXECUTION_NAME2','EXEC_11G_${YYYYMMDD}'), - EXECUTION_DESC => 'Compare SQLs between 10g and 11g at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
依據個人實驗環境,真實的示例爲:
1). 對比兩次Trail中的SQL執行時間 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - EXECUTION_NAME => 'COMPARE_ET_20180106', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'ELAPSED_TIME', - 'EXECUTE_FULLDML', 'TRUE', - 'EXECUTION_NAME1','EXEC_BEFORE_20180106', - 'EXECUTION_NAME2','EXEC_AFTER_20180106'), - EXECUTION_DESC => 'Compare SQLs between 10g and 11g at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 2). 對比兩次Trail中的SQL執行的CPU時間 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - EXECUTION_NAME => 'COMPARE_CT_20180106}', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'CPU_TIME', - 'EXECUTION_NAME1','EXEC_BEFORE_20180106', - 'EXECUTION_NAME2','EXEC_AFTER_20180106'), - EXECUTION_DESC => 'Compare SQLs between 10g and 11g at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 3). 對比兩次Trail中的SQL執行的邏輯讀 EXEC DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( - TASK_NAME => 'SPA_TASK_20180106', - EXECUTION_NAME => 'COMPARE_BG_20180106', - EXECUTION_TYPE => 'COMPARE PERFORMANCE', - EXECUTION_PARAMS => DBMS_ADVISOR.ARGLIST( - 'COMPARISON_METRIC', 'BUFFER_GETS', - 'EXECUTION_NAME1','EXEC_BEFORE_20180106', - 'EXECUTION_NAME2','EXEC_AFTER_20180106'), - EXECUTION_DESC => 'Compare SQLs between Before_STATS and After_STATS at :'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'));
參考規範:
--a) 獲取執行時間所有報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL elapsed_all.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','ALL','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_ET')).GETCLOBVAL(0,0) FROM DUAL; --b) 獲取執行時間降低報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL elapsed_regressed.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','REGRESSED','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_ET')).GETCLOBVAL(0,0) FROM DUAL; --c) 獲取邏輯讀所有報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL buffer_all.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','ALL','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_BG')).GETCLOBVAL(0,0) FROM DUAL; --d) 獲取邏輯讀降低報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL buffer_regressed.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','REGRESSED','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_BG')).GETCLOBVAL(0,0) FROM DUAL; --e) 獲取錯誤報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL error.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','ERRORS','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_ET')).GETCLOBVAL(0,0) FROM DUAL; --f) 獲取不支持報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL unsupported.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','UNSUPPORTED','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_ET')).GETCLOBVAL(0,0) FROM DUAL; --g) 獲取執行計劃變化報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL changed_plans.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_${YYYYMMDD}','HTML','CHANGED_PLANS','ALL',NULL,1000,'SPA_TASK_${YYYYMMDD}_COMP_ET')).GETCLOBVAL(0,0) FROM DUAL;
依據個人實驗環境,真實的示例爲:
--a) 獲取執行時間所有報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL elapsed_all.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','ALL','ALL',NULL,1000,'COMPARE_ET_20180106')).GETCLOBVAL(0,0) FROM DUAL; --b) 獲取執行時間降低報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL elapsed_regressed.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','REGRESSED','ALL',NULL,1000,'COMPARE_ET_20180106')).GETCLOBVAL(0,0) FROM DUAL; --c) 獲取邏輯讀所有報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL buffer_all.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','ALL','ALL',NULL,1000,'COMPARE_BG_20180106')).GETCLOBVAL(0,0) FROM DUAL; --d) 獲取邏輯讀降低報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL buffer_regressed.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','REGRESSED','ALL',NULL,1000,'COMPARE_BG_20180106')).GETCLOBVAL(0,0) FROM DUAL; --e) 獲取錯誤報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL error.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','ERRORS','ALL',NULL,1000,'COMPARE_ET_20180106')).GETCLOBVAL(0,0) FROM DUAL; --f) 獲取不支持報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL unsupported.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','UNSUPPORTED','ALL',NULL,1000,'COMPARE_ET_20180106')).GETCLOBVAL(0,0) FROM DUAL; --g) 獲取執行計劃變化報告 ALTER SESSION SET EVENTS='31156 TRACE NAME CONTEXT FOREVER, LEVEL 0X400'; SET LINES 1111 PAGES 50000 LONG 1999999999 TRIM ON TRIMS ON SERVEROUTPUT ON SIZE UNLIMITED SPOOL changed_plans.html SELECT XMLTYPE(DBMS_SQLPA.REPORT_ANALYSIS_TASK('SPA_TASK_20180106','HTML','CHANGED_PLANS','ALL',NULL,1000,'COMPARE_ET_20180106')).GETCLOBVAL(0,0) FROM DUAL;
這樣就獲得了各種的性能對比報告,以執行時間的所有報告爲例,生成的報告概要頭部相似這樣:
固然,具體獲取到的這些性能對比報告,針對那些有性能降低的SQL,還須要人工干預,評估如何優化處理那些性能降低的SQL。