[20130117]Analyzing a SQL Trace File with SQL Statements.txt
[20130117]Analyzing a SQL Trace File with SQL Statements.txt
參考連結:
As of Oracle Database 11g the DBMS_SQLTUNE package provides the SELECT_SQL_TRACE function. Its purpose is to load the
content of a SQL trace file into a SQL tuning set. But, as it often happens, a feature can be (mis)used for another purpose.
The aim of this post is to show how to take advantage of this function to display through SQL statements the content of a
SQL trace file.
重複作者的測試,我的測試環境:
SQL> select * from v$version where rownum<=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
參考連結:
As of Oracle Database 11g the DBMS_SQLTUNE package provides the SELECT_SQL_TRACE function. Its purpose is to load the
content of a SQL trace file into a SQL tuning set. But, as it often happens, a feature can be (mis)used for another purpose.
The aim of this post is to show how to take advantage of this function to display through SQL statements the content of a
SQL trace file.
重複作者的測試,我的測試環境:
SQL> select * from v$version where rownum<=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
CREATE TABLE t
AS
SELECT rownum AS id, rpad('*',1000,'*') AS pad
FROM dual
CONNECT BY level <= 10000
ORDER BY dbms_random.value;
ALTER TABLE t ADD CONSTRAINT t_pk PRIMARY KEY (id);
BEGIN
dbms_stats.gather_table_stats(
ownname => user,
tabname => 't',
estimate_percent => 100,
method_opt => 'for all columns size 1'
);
END;
/
execute dbms_monitor.session_trace_enable(binds => TRUE, plan_stat => 'ALL_EXECUTIONS');
variable id number;
EXECUTE :id := 10;
SELECT count(pad) FROM t WHERE id < :id;
EXECUTE :id := 990;
SELECT count(pad) FROM t WHERE id < :id;
SELECT count(pad) FROM t WHERE id < :id;
EXECUTE :id := 20;
SELECT count(pad) FROM t WHERE id < :id;
SELECT sum(id) FROM t;
execute dbms_monitor.session_trace_disable;
SELECT value FROM v$diag_info WHERE name = 'Default Trace File';
VALUE
--------------------------------------------------------------------------------------
/u01/app/oracle11g/diag/rdbms/test/test/trace/test_ora_8506.trc
CREATE DIRECTORY trace AS '/u01/app/oracle11g/diag/rdbms/test/test/trace/';
SELECT sql_id,
sum(elapsed_time) AS elapsed_time,
sum(executions) AS executions,
round(sum(elapsed_time)/sum(executions)) AS elapsed_time_per_execution
FROM table(dbms_sqltune.select_sql_trace(
directory => 'TRACE',
file_name => 'test_ora_8506.trc',
select_mode => 2 -- all executions
)) t
WHERE parsing_schema_name = user
GROUP BY sql_id
ORDER BY elapsed_time DESC;
SQL_ID ELAPSED_TIME EXECUTIONS ELAPSED_TIME_PER_EXECUTION
------------- ------------ ---------- --------------------------
asth1mx10aygn 24808 4 6202
6tgnxwpymddqc 1800 1 1800
SELECT sql_text
FROM table(dbms_sqltune.select_sql_trace(
directory => 'TRACE',
file_name => 'test_ora_8506.trc',
select_mode => 1 -- only first execution
)) t
WHERE sql_id = 'asth1mx10aygn';
SQL_TEXT
--------------------------------------------------------
SELECT count(pad) FROM t WHERE id < :id
SELECT plan_hash_value, executions, fetches, elapsed_time, cpu_time, disk_reads, buffer_gets, rows_processed
FROM table(dbms_sqltune.select_sql_trace(
directory => 'TRACE',
file_name => 'test_ora_8506.trc',
select_mode => 2 -- all executions
)) t
WHERE sql_id = 'asth1mx10aygn'
ORDER BY elapsed_time DESC;
PLAN_HASH_VALUE EXECUTIONS FETCHES ELAPSED_TIME CPU_TIME DISK_READS BUFFER_GETS ROWS_PROCESSED
--------------- ---------- ---------- ------------ ---------- ---------- ----------- --------------
4294967295 1 2 13677 5999 0 1434 1
4294967295 1 2 8223 3999 0 992 1
4294967295 1 2 1604 1000 0 21 1
4294967295 1 2 1304 2000 0 11 1
column value format 9999999999999
SELECT elapsed_time,
value(b).gettypename() AS type,
value(b).accessnumber() AS value
FROM table(dbms_sqltune.select_sql_trace(
directory => 'TRACE',
file_name => 'test_ora_8506.trc',
select_mode => 2 -- all executions
)) t,
table(bind_list) b
WHERE sql_id = 'asth1mx10aygn'
ORDER BY elapsed_time DESC;
ELAPSED_TIME TYPE VALUE
------------ ---------------------------------------- --------------
13677 SYS.NUMBER 990
8223 SYS.NUMBER 990
1604 SYS.NUMBER 20
1304 SYS.NUMBER 10
===========
DECLARE
c sys_refcursor;
BEGIN
dbms_sqltune.create_sqlset('TEST');
OPEN c FOR
SELECT value(t)
FROM table(dbms_sqltune.select_sql_trace(
directory => 'TRACE',
file_name => 'test_ora_8506.trc',
select_mode => 2 -- all executions
)) t;
dbms_sqltune.load_sqlset('TEST', c);
CLOSE c;
END;
/
SELECT *
FROM table(dbms_xplan.display_sqlset(
sqlset_name => 'TEST',
sql_id => 'asth1mx10aygn'
));
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-752779/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql_trace生成及使用tkprof檢視trace fileSQL
- SQL TraceSQL
- SQL_TRACESQL
- trace top sql sessionSQLSession
- Oracle sql trace用法OracleSQL
- SQL Server TRACE FLAGSQLServer
- 【轉】 sql_traceSQL
- 【實驗】【SQL_TRACE】使用sql_trace功能獲得show parameter的sql語句SQL
- Microsoft SQL Server Trace FlagsROSSQLServer
- sql_trace的使用SQL
- oracle“SQL Trace”簡介OracleSQL
- SQL on file 工具SQL
- 跟蹤SQL - SQL Trace 及 10046 事件SQL事件
- Oracle 10046 SQL TRACEOracleSQL
- SQL_TRACE與tkprof分析SQL
- 開啟/檢視 sql traceSQL
- sql trace 簡單測試SQL
- sql_trace 及 tkprof 工具SQL
- SQL 的跟蹤方法traceSQL
- Oracle SQL 跟蹤 --- dbms_system.set_sql_trace_in_sessionOracleSQLSession
- SQL效能的度量 - 會話級別的SQL跟蹤sql_traceSQL會話
- Oracle診斷案例-Sql_traceOracleSQL
- sql_trace相關指令碼SQL指令碼
- sql trace的使用說明一SQL
- sql_trace 原檔案解析SQL
- sql_trace/ 10046 整理SQL
- 跟蹤 sql 的trace檔案SQL
- sql_trace and 10046事件SQL事件
- 利用sql_trace提高自學能力SQL
- 【筆記】 sql_trace相關筆記SQL
- Oracle SQL_TRACE使用小結OracleSQL
- sql_trace跟蹤工具(轉)SQL
- Sql最佳化(十九) 調優工具(2)sql_traceSQL
- How to Run Statement Level/Java trace or a SQL Trace in Self Service ApplicationJavaSQLAPP
- 使用SQL TRACE和TKPROF觀察SQL語句執行結果SQL
- 【SQL_TRACE】SQL優化及效能診斷好幫手SQL優化
- Oracle SQL Trace 和 10046 事件OracleSQL事件
- Maclean教你讀SQL TRACE TKProf報告MacSQL