oracle11g有DBMS_MONITOR跟蹤TRUNCATE操作

wisdomone1發表於2012-09-14
1,小表1W,中表100W與大表1000W的區別
          1,分別建立小中大表
             CREATE TABLE T_SMALL(A NUMBER);
             CREATE TABLE T_MIDDLE(A NUMBER);
             CREATE TABLE T_BIG(A NUMBER);
          2,此期僅對比測試小中大表TRUNCATE內部有何不同,故只能TRUNCATE
             跟蹤,不用跟蹤INSERT操作
          3,小表
               --1,插入
                   DECLARE
                    TYPE TYP_TAB_V_UPPER IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
                    V_UPPER TYP_TAB_V_UPPER;
                    V_END PLS_INTEGER:=&END;
                   BEGIN
                    FOR I IN 1..V_END LOOP
                      V_UPPER(I):=I;
                    END LOOP;
                  
                   
                    FORALL I IN 1..V_END
                      INSERT INTO T_SMALL VALUES(V_UPPER(I));
                      COMMIT;
                   END;
               --2,10046跟蹤
                 ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT FOREVER,LEVEL 12';
                
               --3,TRUNCATE表操作
                 TRUNCATE TABLE T_SMALL; 
              
               --4,停止10046跟蹤
                 ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT OFF';
                
               --5,提取TRC檔案,並複製到另一個檔案中
                  位置:D:\oracle\diag\rdbms\orcl\orcl\trace
                  新位置:D:\10046
                  刪除原位置TRC檔案,為了重新生成新的TRC檔案
                  問題:在11G對應的USER_DUMP_DEST未發現產生的TRC檔案,怪了
                   解決:
                       --以SYSDBA開啟SCOTT會話監控
                       SQL> exec dbms_monitor.session_trace_enable(132,21);
                      
                       SQL> exec dbms_monitor.session_trace_disable(132);
                       --小結:
                          USER_DUMP_DEST生成的追蹤檔案orcl_ora_7112,7112對應V$PROCESS的SPID
               --6,格式化TRC檔案(複製)
            
             中表插入
               --1,插入
                   DECLARE
                    TYPE TYP_TAB_V_UPPER IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
                    V_UPPER TYP_TAB_V_UPPER;
                    V_END PLS_INTEGER:=&END;
                   BEGIN
                    FOR I IN 1..V_END LOOP
                      V_UPPER(I):=I;
                    END LOOP;
                  
                   
                    FORALL I IN 1..V_END
                      INSERT INTO T_MIDDLE VALUES(V_UPPER(I));
                      COMMIT;
                   END;
               --2,追蹤SCOTT會話
                 exec dbms_monitor.session_trace_ENABLE(132);
                
               --3,TRUNCATE表操作
                 TRUNCATE TABLE T_MIDDLE; 
              
               --4,關閉追蹤SCOTT會話
                 exec dbms_monitor.session_trace_disable(132);
                
               --5,提取TRC檔案,並複製到另一個檔案中
                  位置:D:\oracle\diag\rdbms\orcl\orcl\trace
                  新位置:D:\10046
                  刪除原位置TRC檔案,為了重新生成新的TRC檔案
                  問題:在11G對應的USER_DUMP_DEST未發現產生的TRC檔案,怪了
                   解決:
                       --以SYSDBA開啟SCOTT會話監控
                       SQL> exec dbms_monitor.session_trace_enable(132,21);
                      
                       SQL> exec dbms_monitor.session_trace_disable(132);
                       --小結:
                          USER_DUMP_DEST生成的追蹤檔案orcl_ora_7112,7112對應V$PROCESS的SPID
               --6,格式化TRC檔案(複製)
             大表插入  
               --1,插入
                   DECLARE
                    TYPE TYP_TAB_V_UPPER IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
                    V_UPPER TYP_TAB_V_UPPER;
                    V_END PLS_INTEGER:=&END;
                   BEGIN
                    FOR I IN 1..V_END LOOP
                      V_UPPER(I):=I;
                    END LOOP;
                  
                   
                    FORALL I IN 1..V_END
                      INSERT INTO T_BIG VALUES(V_UPPER(I));
                      COMMIT;
                   END;
               --2,10046跟蹤
                 exec dbms_monitor.session_trace_enable(132,21);
                
               --3,TRUNCATE表操作
                 TRUNCATE TABLE T_BIG; 
              
               --4,停止10046跟蹤
                 exec dbms_monitor.session_trace_disable(132);
                
               --5,提取TRC檔案,並複製到另一個檔案中
                  位置:D:\oracle\diag\rdbms\orcl\orcl\trace
                  新位置:D:\10046
                  刪除原位置TRC檔案,為了重新生成新的TRC檔案
                  問題:在11G對應的USER_DUMP_DEST未發現產生的TRC檔案,怪了
                   解決:
                       --以SYSDBA開啟SCOTT會話監控
                       SQL> exec dbms_monitor.session_trace_enable(132,21);
                      
                       SQL> exec dbms_monitor.session_trace_disable(132);
                       --小結:
                          USER_DUMP_DEST生成的追蹤檔案orcl_ora_7112,7112對應V$PROCESS的SPID
               --6,格式化TRC檔案(複製)
              
              
               小結:1,對於TRUNCATE而言,大中小表的內部操作(ORACLE內部)差不多,故每個TRC檔案
                        TKPROF之後差不多大小
              
      2,10046診斷TRC如何分析
          1,10046 TRC檔案示例,重複部分略去
             TKPROF: Release 11.2.0.1.0 - Development on 星期五 9月 14 13:45:52 2012
               Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
              
               Trace file: d:\10046\orcl_ora_t_middle.trc
               Sort options: default
              
               ********************************************************************************
               count    = number of times OCI procedure was executed
               cpu      = cpu time in seconds executing
               elapsed  = elapsed time in seconds executing
               disk     = number of physical reads of buffers from disk
               query    = number of buffers gotten for consistent read
               current  = number of buffers gotten in current mode (usually for update)
               rows     = number of rows processed by the fetch or execute call
               ********************************************************************************
              
               SQL ID: c2wk6dy1akjbs
               Plan Hash: 1537128132
               select count(FA#)
               from
                SYS_FBA_TRACKEDTABLES where OBJ# = 73333 and DROPSCN = 0
              
              
               call     count       cpu    elapsed       disk      query    current        rows
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               Parse        2      0.00       0.00          0          0          0           0
               Execute      2      0.00       0.00          0          0          0           0
               Fetch        2      0.00       0.00          0          2          0           2
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               total        6      0.00       0.00          0          2          0           2
              
               Misses in library cache during parse: 1
               Optimizer mode: CHOOSE
               Parsing user id: SYS   (recursive depth: 1)
              
               Rows     Row Source Operation
               -------  ---------------------------------------------------
                     1  SORT AGGREGATE (cr=1 pr=0 pw=0 time=0 us)
                     0   TABLE ACCESS BY INDEX ROWID SYS_FBA_TRACKEDTABLES (cr=1 pr=0 pw=0 time=0 us cost=1 size=6 card=1)
                     0    INDEX UNIQUE SCAN SYS_C001432 (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 1214)
              
               ********************************************************************************
              
               SQL ID: 65r8rs8x7bnhf
               Plan Hash: 0
               LOCK TABLE "T_MIDDLE" IN EXCLUSIVE MODE  NOWAIT
              
              
               call     count       cpu    elapsed       disk      query    current        rows
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               Parse        1      0.01       0.02          0          0          0           0
               Execute      1      0.00       0.00          0          0          0           0
               Fetch        0      0.00       0.00          0          0          0           0
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               total        2      0.01       0.02          0          0          0           0
              
               Misses in library cache during parse: 1
               Optimizer mode: ALL_ROWS
               Parsing user id: 84     (recursive depth: 1)
               ********************************************************************************
              
               SQL ID: 4nackmz96wbrb
               Plan Hash: 3777519066
               TRUNCATE TABLE T_MIDDLE
              
              
               call     count       cpu    elapsed       disk      query    current        rows
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               Parse        1      0.01       0.02          0          2          0           0
               Execute      1      0.00       0.01          5         96        181           0
               Fetch        0      0.00       0.00          0          0          0           0
               ------- ------  -------- ---------- ---------- ---------- ----------  ----------
               total        2      0.01       0.04          5         98        181           0
              
               Misses in library cache during parse: 1
               Optimizer mode: ALL_ROWS
               Parsing user id: 84 
              
               Elapsed times include waiting on following events:
                 Event waited on                             Times   Max. Wait  Total Waited
                 ----------------------------------------   Waited  ----------  ------------
                 reliable message                                3        0.00          0.00
                 enq: RO - fast object reuse                     2        0.01          0.01
                 db file sequential read                         5        0.00          0.00
                 local write wait                                3        0.00          0.00
                 log file sync                                   1        0.02          0.02
                 SQL*Net message to client                       1        0.00          0.00
                 SQL*Net message from client                     1        0.00          0.00
               ********************************************************************************
          2,10046檔案的結構;
              
               1,每個SQL的語句,這個SQL包括使用者執行的SQL以及遞迴呼叫ORACLE的SQL
                  是否包括遞迴呼叫ORACLE的SQL可由TKPROF選項控制
               2,每個SQL的解析,執行,提取三個階段各項指標的效能資料,比如:
                  COUNT,CPU,ELAPSED等  
               3,每個SQL的執行計劃
               4,在執行這些SQL時資料庫的等待事件   
            小結:1,TRUNCATE操作在底層會呼叫ORACLE內部的一些字典表如:OBJ#,SEG#,MLOG$
                     以及一些底層包如:DBMS_STANDARD和SED打頭的包
                  2,如何你要深入研究這些底層操作之間內部的流程,就要詳細看這個TRC檔案,
                    即:每個內部表的含義,
                        TRC檔案中執行內部SQL的順序
                        內部SQL之間如何發生關係
                        這是另一個話題了

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-743454/,如需轉載,請註明出處,否則將追究法律責任。

相關文章