Oracle 11g中直接路徑讀取對於延遲塊清除的影響

來源:互聯網
上載者:User

在Oracle 11g版本中串列的全表掃描可能使用直接路徑讀取(direct path read)的方式取代之前版本中一直使用的DB FILE SCATTERED READ, 顯然direct path read具備更多的優勢:

1. 減少了對栓的使用,避免可能的栓爭用

2.物理IO的大小不再取決於buffer_cache中所存在的塊;試想某個8個塊的extent中1,3,5,7號塊在快取中,而2,4,6,8塊沒有被緩衝,傳統的方式在讀取該extent時將會是對2,4,6,8塊進行4次db file sequential read,這是一種十分可怕的狀況,其效率往往要比單次讀取這個區間的所有8個塊還要低得多,雖然Oracle為了避免這種情況總是儘可能的不緩衝大表的塊(讀入後總是放在隊列最冷的一端);而direct path read則可以完全避免這類問題,儘可能地單次讀入更多的物理塊。

當然直接路徑讀取也會引入一些缺點:

1.在直接路徑讀取某段前需要對該對象進行一次段級的檢查點(A segment checkpoint).

2.可能導致重複的延遲塊清除操作(我們假設你瞭解delayed block cleanout是什麼).


http://www.oracledatabase12g.com/archives/direct-read-impact-on-delayed-block-read.html


metalink 文檔[ID 793845.1] 對該新版本中的變化進行了描述:

    Applies to:

    Oracle Server – Enterprise Edition – Version: 11.1.0.6 to 11.1.0.7
    This problem can occur on any platform.
    Symptoms

    After migrating an 11g database from a standalone to a 4-node RAC,  a noticeable
    increase of 'direct path read' waits were observed at times.

    Here are the Cache sizes and Top 5 events.

    waits

    Cache Sizes                       Begin        End
    ~~~~~~~~~~~                  ---------- ----------
                   Buffer Cache:     3,232M     3,616M  Std Block Size:         8K
               Shared Pool Size:     6,736M     6,400M      Log Buffer:     8,824K
    Top 5 Timed Foreground Events
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                               Avg
                                                              wait   % DB
    Event                                 Waits     Time(s)   (ms)   time Wait Class
    ------------------------------ ------------ ----------- ------ ------ ----------
    DB CPU                                           13,916          42.1
    direct path read                  1,637,344      13,359      8   40.4 User I/O
    db file sequential read              47,132       1,111     24    3.4 User I/O
    DFS lock handle                     301,278       1,028      3    3.1 Other
    db file parallel read                14,724         554     38    1.7 User I/O

    Changes

    Migrated from a standalone database to a 4-node RAC.
    Moved from Unix file system storage to ASM.

    Using Automatic Shared Memory Management (ASMM).
    The setting of db_cache_size in spfile/pfile is low compared to normal workload requirements.
    Cause

    There have been changes in 11g in the heuristics to choose between direct path reads or reads through buffer cache for serial table scans.
    In 10g, serial table scans for “large” tables used to go through cache (by default) which is not the case anymore.  In 11g, this decision to read via direct path or through cache is based on the size of the table, buffer cache size and various other stats.
    Direct path reads are faster than scattered reads and have less impact on other processes because they avoid latches.
    Solution

    When using Automatic Shared Memory Management (ASMM) and with buffer cache low limit set at a low end compared to the normal workload requirements and usually after startup, 11g might choose to do serial direct path read scans for large tables that do not fit in the SGA. When ASMM increases the buffer cache due to increased demand, 11g might not again do serial direct path read scans for these same large tables.  If you like to avoid this from happening, you should note the buffer cache and share pool requirements for a normal workload and set the low limits of buffer cache and shared pool in spfile/pfile close to these normal workload values.
    db_cache_size
    shared_pool_size

下面我們對直接路徑讀取對於延遲塊清除造成的影響進行測試:

SQL> create table tv as select rownum rn,rpad('A',600,'Z') rp from dual
2       connect by level <=300000;

表已建立。

建立一個會話a:

SQL> set linesize 200 pagesize 1400;
SQL> select count(*) from tv;

COUNT(*)
----------
300000

SQL> select vm.sid, vs.name, vm.value
2    from v$mystat vm, v$sysstat vs
3   where vm.statistic# = vs.statistic#
4     and vs.name in ('cleanouts only - consistent read gets',
5                     'session logical reads',
6                     'physical reads',
7                     'physical reads direct');

SID NAME                                                                  VALUE
---------- ---------------------------------------------------------------- ----------
25 session logical reads                                          27281
25 physical reads                                                 27273
25 physical reads direct                                          27273         
25 cleanouts only - consistent read gets                            0

-- 顯然查詢採用了直接路徑讀取方式

SQL> update tv set rn=rn+1;                        -- 嘗試批次更新

SQL> alter system flush buffer_cache;             
-- 重新整理快取,造成延遲塊清除的情景,並提交

系統已更改。

SQL> commit;

提交完成。

建立一個會話b:

SQL> set linesize 200 pagesize 1400;
SQL> select count(*) from tv;

COUNT(*)
----------
300000

SQL> select vm.sid, vs.name, vm.value
2    from v$mystat vm, v$sysstat vs
3   where vm.statistic# = vs.statistic#
4     and vs.name in ('cleanouts only - consistent read gets',
5                     'session logical reads',
6                     'physical reads',
7                     'physical reads direct','redo size');

SID NAME                                                                  VALUE
---------- ---------------------------------------------------------------- ----------
25 session logical reads                                                 54554
25 physical reads                                                        27273
25 physical reads direct                                                 27273
25 redo size                                                                 0
25 cleanouts only - consistent read gets                           27273      
--查詢採用direct path read時產生了延遲塊清除操作,但不產生redo
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.