|
1. 从cursor cache中收集tuning set, 持续12分钟,间隔5秒钟:
- begin
- dbms_sqltune.create_sqlset(sqlset_name => 'SQLTUNINGSET1');
- dbms_sqltune.capture_cursor_cache_sqlset(
- sqlset_name => 'SQLTUNINGSET1' ,
- time_limit => 12*60,
- repeat_interval => 5,
- basic_filter=> q'# ((module like 'DWH_TEST%' and sql_text not like '%applicat%') or
- sql_text LIKE '%fact_pd_out_itm_293%')
- and parsing_schema_name in ('APPS')
- #');
- end;
- /
复制代码
2. 查看SQLTUNING SET的方法:
- select owner,name from dba_sqlset;
复制代码 SYS $$SQLA$$_1
SYS $$SQLA$$_2
SYS $$SQLA$$_3
SYS $$SQLA$$_4
SYS $$SQLA$$_5
SYS $$SQLA$$_6
SYS SQLTUNINGSET1
SYS SYS_AUTO_STS
- select sql_id , sql_text from dba_sqlset_statements
- where sqlset_name='SQLTUNINGSET1';
复制代码 0mcv88ft7fwdj "SELECT /* ORDERED INDEX(t1) USE_HASH(t1) */
'B' || t2.pg_featurevalue_13_id pg_featurevalue_13_id,
'B' || t2.pg_featurevalue_02_id pg_featurevalue_02_id,
'r' || t4.elementrange_id pg_featurevalue_15_id,
'B' || t2.pg_featurevalue_08_id pg_featurevalue_08_id,
'B' || t2.pg_featurevalue_01_id pg_featurevalue_01_id,
'r' || t5.elementrange_id price_eur_id,
'B' || t2.productgroup_id productgroup_id,
'G' || t6.elementgroup_id period_id,
SUM(t1.pd_sales_units*t1.pd_projection_factor*t1.pd_price_units_eur) salesvalueeur
FROM
lu_item_293 t2,
lu_pg_featurevalue_15 t3,
lu_elementrange_rel t4,
fact_pd_out_itm_293 t1,
lu_elementgroup_rel t6,
lu_elementrange_rel t5
WHERE
/* Attribute Joins */
((t1.item_id = t2.item_id
/* Customizing Begin */
AND t1.productgroup_id = t2.productgroup_id)
/* Customizing End */
AND (t2.pg_featurevalue_15_id = t3.pg_featurevalue_15_id)
AND (t3.pg_featurevalue_15_num BETWEEN t4.lbound AND t4.ubound)
AND (t1.pd_price_units_eur BETWEEN t5.lbound AND t5.ubound)
AND (t1.period_id = t6.value_id)
)
/* Attribute Filters */
AND ((t2.productgroup_id = 15520)
AND (t1.productgroup_id = 15520) /* Push Down Filters */
AND (t2.pg_featurevalue_01_id IN (103,104,107,110,113,134,148,167,171,186,192,216,2259,236,241,2477,24958,27445,297,3891,71,76,89,92,95))
AND (t2.pg_featurevalue_08_id IN (716,717))
AND (t2.pg_featurevalue_02_id IN (4165,4166))
AND (t2.pg_featurevalue_13_id = 5424)
AND (t4.elementrange_id IN (3091,3092))
AND (t5.elementrange_id IN (8693,8694,8695,8696,8697,8698,8699))
AND (t6.elementgroup_id = 14659)
AND (t1.period_id IN (20030699999060,20030799999030,20030799999060,20030799999120)) /* Resolved ElementGroup Filters */
)
/* Fact Filters */
AND (t1.project_type_id = '1'
)
GROUP BY
t2.pg_featurevalue_13_id,
t2.pg_featurevalue_02_id,
t4.elementrange_id,
t2.pg_featurevalue_08_id,
t2.pg_featurevalue_01_id,
t5.elementrange_id,
t2.productgroup_id,
t6.elementgroup_id"
3. 转移SQLTUNIUNG SET的方法:
3.1 创建存放sqlset的中间表:
- SQL> conn / as sysdba
- Connected.
- SQL> drop table pack_sqlset purge;
- drop table pack_sqlset purge
- *
- ERROR at line 1:
- ORA-00942: table or view does not exist
- Elapsed: 00:00:00.03
- SQL> exec DBMS_SQLTUNE.CREATE_STGTAB_SQLSET('PACK_SQLSET','APPS');
- PL/SQL procedure successfully completed.
- Elapsed: 00:00:00.29
复制代码- SQL> select sql_id from apps.PACK_SQLSET;
- no rows selected
- Elapsed: 00:00:00.00
复制代码 3.2 转移SQLSET到sqlset的中间表:
- SQL> exec DBMS_SQLTUNE.PACK_STGTAB_SQLSET('SQLTUNINGSET1','SYS','PACK_SQLSET','APPS');
- PL/SQL procedure successfully completed.
- Elapsed: 00:00:03.48
复制代码 查看里面的数据:
- SQL> select sql_id from apps.PACK_SQLSET;
- SQL_ID
- -------------
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- SQL_ID
- -------------
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- SQL_ID
- -------------
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 0mcv88ft7fwdj
- 28 rows selected.
- Elapsed: 00:00:00.00
- SQL>
复制代码 为了转移SQLTUNING SET(当然还包括整个方案设计),为了防止版本冲突,建议先删除apps用户方案的plan_table后导出该用户方案(expdp数据泵操作略)。然后将apps用户方案倒入另外一个数据库(impdp数据泵操作略)。此处模拟在原库删除SQLTUNINGSET1,再在原库从apps.pack_sqlset导出SQLTUNINGSET1:
- SQL> begin
- dbms_sqltune.drop_sqlset(sqlset_name => 'SQLTUNINGSET1');
- end;
- /
复制代码
- SQL> exec DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET('SQLTUNINGSET1','SYS',true,'PACK_SQLSET','APPS');
复制代码
4. 各种查找顶级SQL的方法:
- SELECT *
- FROM table(DBMS_SQLTUNE.SELECT_CURSOR_CACHE('sql_text like ''update%'''))
- ORDER BY sql_id;
复制代码- SELECT *
- FROM table(DBMS_SQLTUNE.SELECT_CURSOR_CACHE('buffer_gets > 500'));
复制代码- SELECT *
- FROM table(DBMS_SQLTUNE.SELECT_CURSOR_CACHE('CPU_TIME>29000000')); --单位为10的-6次方秒
复制代码
|
|