偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Oracle Redo log并行機制詳解

數(shù)據(jù)庫 Oracle 數(shù)據(jù)庫運維
Redo log是Oracle數(shù)據(jù)庫的日志,可以用于恢復和一個高級特性的重要數(shù)據(jù);這里我們通過一些實例來深入了解Oracle Redo log的并行機制。

Oracle的數(shù)據(jù)庫日志稱為Redo log,所有數(shù)據(jù)改變都記錄Redo log,可以用于修復受損的數(shù)據(jù)庫。Redo log 是用于恢復和一個高級特性的重要數(shù)據(jù),一個redo條目包含了相應操作導致的數(shù)據(jù)庫變化的所有信息,所有redo條目最終都要被寫入redo文件中去。

Redo log buffer是為了避免Redo文件IO導致性能瓶頸而在sga中分配出的一塊內存。一個redo條目首先在用戶內存(PGA)中產生,然后由oracle服務進程拷貝到log buffer中,當滿足一定條件時,再由LGWR進程寫入redo文件。由于log buffer是一塊“共享”內存,為了避免沖突,它是受到redo allocation latch保護的,每個服務進程需要先獲取到該latch才能分配redo buffer。因此在高并發(fā)且數(shù)據(jù)修改頻繁的oltp系統(tǒng)中,我們通常可以觀察到redo allocation latch的等待。Redo寫入redo buffer的整個過程如下:

在PGA中生產Redo Enrey -> 服務進程獲取Redo Copy latch(存在多個---CPU_COUNT*2) -> 服務進程獲取redo allocation latch(僅1個) -> 分配log buffer -> 釋放redo allocation latch -> 將Redo Entry寫入Log Buffer -> 釋放Redo Copy latch;

shared strand

為了減少redo allocation latch等待,在oracle 9.2中,引入了log buffer的并行機制。其基本原理就是,將log buffer劃分為多個小的buffer,這些小的buffer被成為strand(為了和之后出現(xiàn)的private strand區(qū)別,它們被稱之為shared strand)。每一個strand受到一個單獨redo allocation latch的保護。多個shared strand的出現(xiàn),使原來序列化的redo buffer分配變成了并行的過程,從而減少了redo allocation latch等待。

shared strand的初始數(shù)據(jù)量是由參數(shù)log_parallelism控制的;在10g中,該參數(shù)成為隱含參數(shù),并新增參數(shù)_log_parallelism_max控制shared strand的最大數(shù)量;_log_parallelism_dynamic則控制是否允許shared strand數(shù)量在_log_parallelism和_log_parallelism_max之間動態(tài)變化。

  1. HELLODBA.COM>select  nam.ksppinm, val.KSPPSTVL, nam.ksppdesc      
  2.   2  from    sys.x$ksppi nam,      
  3.   3          sys.x$ksppsv val      
  4.   4  where nam.indx = val.indx      
  5.   5  --AND   nam.ksppinm LIKE '_%'      
  6.   6  AND   upper(nam.ksppinm) LIKE '%LOG_PARALLE%';      
  7.      
  8. KSPPINM                    KSPPSTVL   KSPPDESC      
  9. -------------------------- ---------- ------------------------------------------      
  10. _log_parallelism           1          Number of log buffer strands      
  11. _log_parallelism_max       2          Maximum number of log buffer strands      
  12. _log_parallelism_dynamic   TRUE       Enable dynamic strands  

每一個shared strand的大小 = log_buffer/(shared strand數(shù)量)。strand信息可以由表x$kcrfstrand查到(包含shared strand和后面介紹的private strand,10g以后存在)?!?/P>

  1. HELLODBA.COM>select indx,strand_size_kcrfa from x$kcrfstrand where last_buf_kcrfa != '00';      
  2.      
  3.       INDX STRAND_SIZE_KCRFA      
  4. ---------- -----------------      
  5.          0           3514368      
  6.          1           3514368      
  7.      
  8. HELLODBA.COM>show parameter log_buffer      
  9.      
  10. NAME                                 TYPE        VALUE      
  11. ------------------------------------ ----------- ------------------------------      
  12. log_buffer                           integer     7028736    

關于shared strand的數(shù)量設置,16個cpu之內最大默認為2,當系統(tǒng)中存在redo allocation latch等待時,每增加16個cpu可以考慮增加1個strand,最大不應該超過8。并且_log_parallelism_max不允許大于cpu_count。

注意:在11g中,參數(shù)_log_parallelism被取消,shared strand數(shù)量由_log_parallelism_max、_log_parallelism_dynamic和cpu_count控制。

Private strand

為了進一步降低redo buffer沖突,在10g中引入了新的strand機制——Private strand。Private strand不是從log buffer中劃分的,而是在shared pool中分配的一塊內存空間。

  1. HELLODBA.COM>select * from V$sgastat where name like '%strand%';  
  2.  
  3.   POOL NAME BYTES  
  4.  
  5.   ------------ -------------------------- ----------  
  6.  
  7.   shared pool private strands 2684928  
  8.  
  9.   HELLODBA.COM>select indx,strand_size_kcrfa from x$kcrfstrand where last_buf_kcrfa = '00';  
  10.  
  11.   INDX STRAND_SIZE_KCRFA  
  12.  
  13.   ---------- -----------------  
  14.  
  15.   2 66560  
  16.  
  17.   3 66560  
  18.  
  19.   4 66560  
  20.  
  21.   5 66560  
  22.  
  23.   6 66560  
  24.  
  25.   7 66560  
  26.  
  27.   8 66560  
  28.  
  29.   ... 

Private strand的引入為Oracle的Redo/Undo機制帶來很大的變化。每一個Private strand受到一個單獨的redo allocation latch保護,每個Private strand作為“私有的”strand只會服務于一個活動事務。獲取到了Private strand的用戶事務不是在PGA中而是在Private strand生成Redo,當flush private strand或者commit時,Private strand被批量寫入log文件中。如果新事務申請不到Private strand的redo allocation latch,則會繼續(xù)遵循舊的redo buffer機制,申請寫入shared strand中。事務是否使用Private strand,可以由x$ktcxb的字段ktcxbflg的新增的第13位鑒定:

  1. HELLODBA.COM>select decode(bitand(ktcxbflg, 4096),0,1,0) used_private_strand, count(*)  
  2.  
  3.   2 from x$ktcxb  
  4.  
  5.   3 where bitand(ksspaflg, 1) != 0  
  6.  
  7.   4 and bitand(ktcxbflg, 2) != 0  
  8.  
  9.   5 group by bitand(ktcxbflg, 4096);  
  10.  
  11.   USED_PRIVATE_STRAND COUNT(*)  
  12.  
  13.   ------------------- ----------  
  14.  
  15.   1 10  
  16.  
  17.   0 1 

對于使用Private strand的事務,無需先申請Redo Copy Latch,也無需申請Shared Strand的redo allocation latch,而是flush或commit是批量寫入磁盤,因此減少了Redo Copy Latch和redo allocation latch申請/釋放次數(shù)、也減少了這些latch的等待,從而降低了CPU的負荷。過程如下:

事務開始 -> 申請Private strand的redo allocation latch (申請失敗則申請Shared Strand的redo allocation latch) -> 在Private strand中生產Redo Enrey -> Flush/Commit -> 申請Redo Copy Latch -> 服務進程將Redo Entry批量寫入Log File -> 釋放Redo Copy Latch -> 釋放Private strand的redo allocation latch 。#p#

注意:對于未能獲取到Private strand的redo allocation latch的事務,在事務結束前,即使已經有其它事務釋放了Private strand,也不會再申請Private strand了。

每個Private strand的大小為65K。10g中,shared pool中的Private strands的大小就是活躍會話數(shù)乘以65K,而11g中,在shared pool中需要為每個Private strand額外分配4k的管理空間,即:數(shù)量*69k。

  1. --10g:  
  2.  
  3.   SQL> select * from V$sgastat where name like '%strand%';  
  4.  
  5.   POOL NAME BYTES  
  6.  
  7.   ------------ -------------------------- ----------  
  8.  
  9.   shared pool private strands 1198080  
  10.  
  11.   HELLODBA.COM>select trunc(value * KSPPSTVL / 100) * 65 * 1024  
  12.  
  13.   2 from (select value from v$parameter where name = 'transactions') a,  
  14.  
  15.   3 (select val.KSPPSTVL  
  16.  
  17.   4 from sys.x$ksppi nam, sys.x$ksppsv val  
  18.  
  19.   5 where nam.indx = val.indx  
  20.  
  21.   6 AND nam.ksppinm = '_log_private_parallelism_mul') b;  
  22.  
  23.   TRUNC(VALUE*KSPPSTVL/100)*65*1024  
  24.  
  25.   -------------------------------------  
  26.  
  27.   1198080  
  28.  
  29.   --11g:  
  30.  
  31.   HELLODBA.COM>select * from V$sgastat where name like '%strand%';  
  32.  
  33.   POOL NAME BYTES  
  34.  
  35.   ------------ -------------------------- ----------  
  36.  
  37.   shared pool private strands 706560  
  38.  
  39.   HELLODBA.COM>select trunc(value * KSPPSTVL / 100) * (65 + 4) * 1024  
  40.  
  41.   2 from (select value from v$parameter where name = 'transactions') a,  
  42.  
  43.   3 (select val.KSPPSTVL  
  44.  
  45.   4 from sys.x$ksppi nam, sys.x$ksppsv val  
  46.  
  47.   5 where nam.indx = val.indx  
  48.  
  49.   6 AND nam.ksppinm = '_log_private_parallelism_mul') b;  
  50.  
  51.   TRUNC(VALUE*KSPPSTVL/100)*(65+4)*1024  
  52.  
  53.   -------------------------------------  
  54.  
  55.   706560 

Private strand的數(shù)量受到2個方面的影響:logfile的大小和活躍事務數(shù)量。

參數(shù)_log_private_mul指定了使用多少logfile空間預分配給Private strand,默認為5。我們可以根據(jù)當前l(fā)ogfile的大小(要除去預分配給log buffer的空間)計算出這一約束條件下能夠預分配多少個Private strand:

  1. HELLODBA.COM>select bytes from v$log where status = 'CURRENT';  
  2.  
  3.   BYTES  
  4.  
  5.   ----------  
  6.  
  7.   52428800  
  8.  
  9.   HELLODBA.COM>select trunc(((select bytes from v$log where status = 'CURRENT') - (select to_number(value) from v$parameter where name = 'log_buffer'))*  
  10.  
  11.   2 (select to_number(val.KSPPSTVL)  
  12.  
  13.   3 from sys.x$ksppi nam, sys.x$ksppsv val  
  14.  
  15.   4 where nam.indx = val.indx  
  16.  
  17.   5 AND nam.ksppinm = '_log_private_mul') / 100 / 66560)  
  18.  
  19.   6 as "calculated private strands" 
  20.  
  21.   7 from dual;  
  22.  
  23.   calculated private strands  
  24.  
  25.   --------------------------  
  26.  
  27.   5  
  28.  
  29.   HELLODBA.COM>select count(1) "actual private strands" from x$kcrfstrand where last_buf_kcrfa = '00';  
  30.  
  31.   actual private strands  
  32.  
  33.   ----------------------  
  34.  
  35.   5 

當logfile切換后(和checkpoint一樣,切換之前必須要將所有Private strand的內容flush到logfile中,因此我們在alert log中可能會發(fā)現(xiàn)日志切換信息之前會有這樣的信息:"Private strand flush not complete",這是可以被忽略的),會重新根據(jù)切換后的logfile的大小計算對Private strand的限制:

  1. HELLODBA.COM>alter system switch logfile;  
  2.  
  3.   System altered.  
  4.  
  5.   HELLODBA.COM>select bytes from v$log where status = 'CURRENT';  
  6.  
  7.   BYTES  
  8.  
  9.   ----------  
  10.  
  11.   104857600  
  12.  
  13.   HELLODBA.COM>select trunc(((select bytes from v$log where status = 'CURRENT') - (select to_number(value) from v$parameter where name = 'log_buffer'))*  
  14.  
  15.   2 (select to_number(val.KSPPSTVL)  
  16.  
  17.   3 from sys.x$ksppi nam, sys.x$ksppsv val  
  18.  
  19.   4 where nam.indx = val.indx  
  20.  
  21.   5 AND nam.ksppinm = '_log_private_mul') / 100 / 66560)  
  22.  
  23.   6 as "calculated private strands" 
  24.  
  25.   7 from dual;  
  26.  
  27.   calculated private strands  
  28.  
  29.   --------------------------  
  30.  
  31.   13  
  32.  
  33.   HELLODBA.COM>select count(1) "actual private strands" from x$kcrfstrand where last_buf_kcrfa = '00';  
  34.  
  35.   actual private strands  
  36.  
  37.   ----------------------  
  38.  
  39.   13 

參數(shù)_log_private_parallelism_mul用于推算活躍事務數(shù)量在最大事務數(shù)量中的百分比,默認為10。Private strand的數(shù)量不能大于活躍事務的數(shù)量。

  1. HELLODBA.COM>show parameter transactions  
  2.  
  3.   NAME TYPE VALUE  
  4.  
  5.   ------------------------------------ ----------- ------------------------------  
  6.  
  7.   transactions integer 222  
  8.  
  9.   transactions_per_rollback_segment integer 5  
  10.  
  11.   HELLODBA.COM>select trunc((select to_number(value) from v$parameter where name = 'transactions') *  
  12.  
  13.   2 (select to_number(val.KSPPSTVL)  
  14.  
  15.   3 from sys.x$ksppi nam, sys.x$ksppsv val  
  16.  
  17.   4 where nam.indx = val.indx  
  18.  
  19.   5 AND nam.ksppinm = '_log_private_parallelism_mul') / 100 )  
  20.  
  21.   6 as "calculated private strands" 
  22.  
  23.   7 from dual;  
  24.  
  25.   calculated private strands  
  26.  
  27.   --------------------------  
  28.  
  29.   22  
  30.  
  31.   HELLODBA.COM>select count(1) "actual private strands" from x$kcrfstrand where last_buf_kcrfa = '00';  
  32.  
  33.   actual private strands  
  34.  
  35.   ----------------------  
  36.  
  37.   22 

注:在預分配Private strand時,會選擇上述2個條件限制下最小一個數(shù)量。但相應的shared pool的內存分配和redo allocation latch的數(shù)量是按照活躍事務數(shù)預分配的。

因此,如果logfile足夠大,_log_private_parallelism_mul與實際活躍進程百分比基本相符的話,Private strand的引入基本可以消除redo allocation latch的爭用問題。

【編輯推薦】

  1. 淺談在Oracle中如何利用REDO實現(xiàn)故障恢復
  2. 簡析REDO LOGFILE
  3. 詳解Oracle中數(shù)字與大寫交換
  4. 淺析Oracle對象和數(shù)據(jù)的導入導出
  5. 分析探討Oracle Data Guard
責任編輯:佚名 來源: HelloDBA
相關推薦

2010-04-30 13:44:36

Oracle Redo

2019-05-06 15:27:48

Oracle數(shù)據(jù)庫數(shù)據(jù)

2025-06-06 07:02:43

2024-06-11 00:00:02

MySQL數(shù)據(jù)庫系統(tǒng)

2023-11-23 13:17:39

MySQL?數(shù)據(jù)庫

2021-07-28 08:32:03

MySQLRedo存儲

2021-10-04 09:23:30

Redo日志內存

2025-01-20 08:20:00

redo logMySQL數(shù)據(jù)庫

2009-09-02 18:52:38

Oracle數(shù)據(jù)庫并行

2010-04-07 14:22:46

2021-05-28 11:18:50

MySQLbin logredo log

2021-01-26 13:47:08

MySQL存儲數(shù)據(jù)

2011-05-26 09:36:07

Oracle數(shù)據(jù)庫Redo故障

2024-05-28 00:10:00

JavaMySQL數(shù)據(jù)庫

2020-08-20 12:10:42

MySQL日志數(shù)據(jù)庫

2019-12-03 09:00:59

Oracle數(shù)據(jù)庫等待事件

2024-05-30 08:03:17

2010-05-07 12:46:08

Oracle redo

2025-01-15 13:19:09

MySQL日志事務

2011-03-24 17:21:42

Oracle數(shù)據(jù)庫Redo故障
點贊
收藏

51CTO技術棧公眾號