关于Oracle开启自动收集统计信息的SPA测试(2)

依据我的实验环境,真实的示例为:

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.SPA分析比较

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; /

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a9160c254e58e1e4c951511594966d51.html