使用SQL TRACE和TKPROF觀察SQL語句執行結果
SQL TRACE檔案存放於
show parameter user_dump下
檔名為_ora_.trc。
預設情況下,使用者SQL不會寫入TRACE檔案,可以在會話級別更改相關引數
ALTER SESSION SET SQL_TRACE=TRUE;
要查詢當前會話的程式ID:
SPID SID SERIAL# USERNAME
------------------------ ---------- ---------- ------------------------------
PROGRAM
--------------------------------------------------------------------------------
1711 145 2 oracle
oracle@ocp.demo.com (TNS V1-V3)
如上例,當前會話的TRACE檔名就應為:user_dump_dest目錄下的OCP_ORCL_1711.trc。
還有一個更簡便的方法:
TKPROF是用來將TRACE檔案轉換成可以閱讀的格式:
SHELL$ tkprof ocp_ora_1711.trc mike.prf explain=user/password
讀取mike.prf即可。
觀察mike.prf的輸出:
********************************************************************************
select count(id)
from
bom
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 2 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 1.67 1.63 72061 72093 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 1.68 1.64 72061 72095 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 61 (HK)
Rows Row Source Operation
------- ---------------------------------------------------
1 SORT AGGREGATE (cr=72093 pr=72061 pw=0 time=1639929 us)
33011000 INDEX FAST FULL SCAN BOM_PK_ID (cr=72093 pr=72061 pw=0 time=84 us)(object id 52507)
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT MODE: ALL_ROWS
1 SORT (AGGREGATE)
33011000 INDEX MODE: ANALYZED (FAST FULL SCAN) OF 'BOM_PK_ID' (INDEX
(UNIQUE))
********************************************************************************
Disk表示讀取的磁碟統計,Query表示讀取的記憶體統計。
以下是部分問題和解決措施的彙總:
show parameter user_dump下
檔名為_ora_.trc。
預設情況下,使用者SQL不會寫入TRACE檔案,可以在會話級別更改相關引數
ALTER SESSION SET SQL_TRACE=TRUE;
要查詢當前會話的程式ID:
點選(此處)摺疊或開啟
-
Select spid, s.sid,s.serial#, p.username, p.program
-
from v$process p, v$session s
-
where p.addr = s.paddr
- and s.sid = (select sid from v$mystat where rownum=1);
SPID SID SERIAL# USERNAME
------------------------ ---------- ---------- ------------------------------
PROGRAM
--------------------------------------------------------------------------------
1711 145 2 oracle
oracle@ocp.demo.com (TNS V1-V3)
還有一個更簡便的方法:
點選(此處)摺疊或開啟
-
SQL> select value from v$diag_info where name='Default Trace File';
-
-
VALUE
-
--------------------------------------------------------------------------------
- /u01/app/oracle/diag/rdbms/apr/apr/trace/apr_ora_4734.trc
TKPROF是用來將TRACE檔案轉換成可以閱讀的格式:
SHELL$ tkprof ocp_ora_1711.trc mike.prf explain=user/password
讀取mike.prf即可。
觀察mike.prf的輸出:
********************************************************************************
select count(id)
from
bom
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 2 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 1.67 1.63 72061 72093 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 1.68 1.64 72061 72095 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 61 (HK)
Rows Row Source Operation
------- ---------------------------------------------------
1 SORT AGGREGATE (cr=72093 pr=72061 pw=0 time=1639929 us)
33011000 INDEX FAST FULL SCAN BOM_PK_ID (cr=72093 pr=72061 pw=0 time=84 us)(object id 52507)
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT MODE: ALL_ROWS
1 SORT (AGGREGATE)
33011000 INDEX MODE: ANALYZED (FAST FULL SCAN) OF 'BOM_PK_ID' (INDEX
(UNIQUE))
********************************************************************************
Disk表示讀取的磁碟統計,Query表示讀取的記憶體統計。
以下是部分問題和解決措施的彙總:
The parsing numbers are high | The SHARED_POOL_SIZE may need to be increased |
The disk reads are very high | Indexes are not being used or may not exist |
The query and/or current (memory reads) are very high |
Indexes may be on columns with
low cardinality (columns where an individual value generally makes up a large percentage of the table; like a y/n field). Removing/suppressing the index or using histograms or a bitmap index may increase performance. A poor join order of tables or bad order in a concatenated index may also cause this. |
The parse elapse time is high | There may be a problem with the number of open cursors |
The
number of rows processed by a row in the EXPLAIN PLAN is high compared to the other rows. |
This could be a sign of an index
with a poor distribution of distinct keys (unique values for a column). This could also be a sign of a poorly written statement. |
The
number of misses in the library cache during parse is greater than 1. |
This indicates that the
statement had to be reloaded. You may need to increase the SHARED_POOL_SIZE in the init.ora file or do a better job of sharing SQL. |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22621861/viewspace-1279733/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE中SQL TRACE和TKPROF的使用OracleSQL
- Oracle執行語句跟蹤 使用sql trace實現語句追蹤OracleSQL
- 使用sql trace工具和tkprof來跟會話SQL會話
- SQL TRACE和TKPROF,10046的使用步驟SQL
- sql_trace生成及使用tkprof檢視trace fileSQL
- SQL_TRACE與tkprof分析SQL
- sql_trace 及 tkprof 工具SQL
- 使用SQL TRACE和TKPROF——效能調整手冊和參考SQL
- sql語句執行過程小結SQL
- 【實驗】【SQL_TRACE】使用sql_trace功能獲得show parameter的sql語句SQL
- sql語句批量執行SQL
- 分析後sql語句很快返回結果SQL
- SQL Server SQL語句執行順序SQLServer
- Maclean教你讀SQL TRACE TKProf報告MacSQL
- sql語句如何執行的SQL
- SQL語句執行順序SQL
- 執行大的sql語句SQL
- toad執行sql語句SQL
- [sql 優化]使用TKPROF格式化TRACE輸出SQL優化
- 【MySQL】如何對SQL語句進行跟蹤(trace)?MySql
- 使用預處理PreparedStatement執行Sql語句SQL
- Laravel 使用 sql 語句 和 sql 檔案 來建立執行資料庫遷移LaravelSQL資料庫
- 查詢Oracle正在執行和執行過的SQL語句OracleSQL
- mysql執行sql語句過程MySql
- Mybatis 動態執行SQL語句MyBatisSQL
- mysql的sql語句執行流程MySql
- sql語句執行緩慢分析SQL
- SQL 語句的執行順序SQL
- 後臺執行SQL語句(oracle)SQLOracle
- Hibernate 執行原始SQL語句SQL
- Oracle SQL語句執行步驟OracleSQL
- SQL語句使用總結(一)SQL
- 通過分析SQL語句的執行計劃優化SQL語句SQL優化
- SQL跟蹤工具和TKPROF使用SQL
- 通過分析SQL語句的執行計劃優化SQL(總結)SQL優化
- 查詢Oracle正在執行的sql語句及執行該語句的使用者OracleSQL
- SQL Server 查詢歷史執行的SQL語句SQLServer
- SQL SERVER 中構建執行動態SQL語句SQLServer