自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Oracle歸檔日志比聯(lián)機重做日志小很多的情況總結(jié)

數(shù)據(jù)庫 Oracle
Oracle歸檔日志比聯(lián)機重做日志小很多,出現(xiàn)這種情況的原因有很多,我們可以從下面這幾方面著手檢查,一一排除確認。

[[382235]]

本文轉(zhuǎn)載自微信公眾號「DBA閑思雜想錄」,作者瀟湘隱者 。轉(zhuǎn)載本文請聯(lián)系DBA閑思雜想錄公眾號。

Oracle歸檔日志比聯(lián)機重做日志小很多,出現(xiàn)這種情況的原因有很多,我們可以從下面這幾方面著手檢查,一一排除確認。

1:檢查參數(shù)ARCHIVE_LAG_TARGET

ARCHIVE_LAG_TARGET參數(shù)可以設置一個時間,通過時間限制,指定數(shù)據(jù)庫強制進行Log Switch進行歸檔。如果這個參數(shù)設置過小,有可能導致聯(lián)機重做日志還沒有寫滿就切換了,這樣就有可能導致歸檔日志遠小于聯(lián)機重做日志(redo log)。

  1. SQL> show parameter archive_lag_target; 
  2.  
  3. NAME                                 TYPE        VALUE 
  4. ------------------------------------ ----------- ------------------------------ 
  5. archive_lag_target                   integer     0 
  6. SQL>  

如果參數(shù)archive_lag_target為0,那么可以排除這方面的因素。

2:檢查是否存在人為切換redo log的可能性。

一些命令可以引起重做日志的切換,具體請見下面

  1. SQL> alter system archive log current; #歸檔命令也會造成日志切換 
  2.  
  3. SQL> alter system switch logfile;      #直接切換日志組 
  4.  
  5. RMAN> backup archivelog all
  6.  
  7. RMAN> backup database plus archivelog; 
  8.  
  9.  
  10. SELECT TO_CHAR(FIRST_TIME, 'YYYY-MM-DD HH24:MI:SS'),  
  11.        BLOCKS * BLOCK_SIZE / 1024 / 1024,  
  12.        COMPRESSED  
  13. FROM   V$ARCHIVED_LOG;  

如下案例的截圖如下所示,從截圖看歸檔日志的大小在31M左右徘徊。另外,可以看到?jīng)]有啟用歸檔日志壓縮選項(其實ORACLE不支持歸檔日志壓縮,這個后面說明)。從歸檔日志大小的規(guī)律可以看出,這個不是某個重做日志切換命令引起的。

3:一些Bug引起的,如下metalink文檔所示:

  1. BUG 9272059 - REDO LOG SWITCH AT 1/8 OF SIZE DUE TO CMT CPU'S 
  2. BUG 10354739 - REDOLOGSIZE NOT COMPLETLY USED 
  3. BUG 12317474 - FREQUENT REDO LOG SWITCHES GENERATING SMALL SIZED ARCHIVELOGS  
  4. BUG 5450861 - ARCHIVE LOGS ARE GENERATED WITH A SMALLER SIZE THAN THE REDO LOG FILES 
  5. BUG 7016254 - DECREASE CONTROL FILE ENQUEUE WAIT AT LOG SWITCH 

4:跟CPU個數(shù)CPU_COUNT以及l(fā)og_buffer、redo log size有關。

歸檔日志的大小是真實的在線日志文件的使用量,也就是在線日志文件切換前其中寫入的內(nèi)容的大小。為了更好的并行,減少沖突,提高并發(fā),減少redo allocation latch的等待,ORACLE會將redo buffer分成若干小的buffer,每份小的buffer叫strand。按每16個CPU分一股(strand),每一股獨立從redo buffer以及redo log中分配一塊空間,當這一塊redo buffer用完,會寫入redo log并且繼續(xù)從redo log中分配相同大小的空間,如果無法分配空閑空間就會進行日志切換,而不管其他strand是否寫完。

如上所示CPU_COUNT為112,那么 112/16=7 ,那么redo buffer和 redo log 都可以分成7部分

  1. SQL>  select 112.0/16 from dual; 
  2.  
  3.   112.0/16 
  4. ---------- 
  5.          7 
  6.  
  7. SQL>  select 341655552/1024/1024/7 from dual;   --log buffer 
  8.  
  9. 341655552/1024/1024/7 
  10. --------------------- 
  11.             46.546875 
  12.  
  13. SQL> select 200/7 from dual;   --redo log size 
  14.  
  15.      200/7 
  16. ---------- 
  17. 28.5714286 
  18.  
  19. SQL>  

當log buffer的大小是325.828125M(341655552),分成7股(strand)的話,每個strand還是325.828125M/7=46.546875M。而redo log的大小是200M的時候,redo log中的空間會按strand的個數(shù)平均分配,也就是每塊200M/7=28.5714286M。

這樣,當每個strand中的內(nèi)容寫到28M多左右的時候,就會日志切換,而不是46M。相當于log buffer中的一部分空間被浪費了。所以你看到的歸檔日志基本是30M左右大小(其中一股(strand)28.6再加上其它各股也有部分內(nèi)容寫入,所以歸檔日志的大小就是一個波動的范圍)

其它各個特殊場景分析,可以參考“歸檔日志的大小比在線日志的大小小很多[1]”這篇文章的介紹。當然這篇文章分析過程還忽略了其它各股其實也是有部分數(shù)據(jù)的。這個需要特別注意。

如果你對這個機制不是很清楚,上面鏈接的這篇博客已經(jīng)不可訪問了,下面是我摘抄的部分內(nèi)容到此,方便大家深入理解:

比如CPU的個數(shù)是64個,則會有64/16=4個strand

例1):當log buffer的大小和redo log file的大小都是256M的時候,則每個strand都是256M/4=64M。每一個redo log file被啟用時,會預先將redo log file中的大小分配出4個64M與log buffer對應,如圖:

因為log buffer的大小和redo log file的大小都是256M,則redo log file沒有剩余的未分配的空間了。

每個進程產(chǎn)生的redo會分配到log buffer上的1,2,3,4其中的某一個strand上,單個進程只能對應一個strand, 這樣當數(shù)據(jù)庫中只有某些進程(比如極端的情況,只有某一個進程)產(chǎn)生的redo很多的時候,其中一個strand會快速寫滿,比如圖中的strand 1:

寫滿之后LGWR會將log buffer中strand 1的內(nèi)容寫入到redo log file中,并且試圖從redo log file中分配一個新的64M空間,發(fā)現(xiàn)沒有了,則將所有strand中的內(nèi)容寫入日志,并作日志切換。

這樣,可能會導致redo log file只寫入了一個strand的內(nèi)容,其他部分幾乎是空的,則產(chǎn)生的archive log會只接近64M,而不是256M。當CPU_COUNT很大時,這個差值會更大。

例2):當log buffer的大小是256M,而redo log file的大小是1G的時候,每個strand還是256M/4=64M。每一個redo log file被啟用時,會預先將redo log file中的大小分配出4個64M與log buffer對應,如圖:

這時,redo log file中還有1G-256M=768M剩余的未分配的空間。

如果strand 1寫滿之后,LGWR會將log buffer中strand 1的內(nèi)容寫入到redo log file中,并且試圖從redo log file中分配一個新的64M空間,然后不斷往下寫。 圖片

直到redo log file中再沒有可分配空間了,則將所有strand中的內(nèi)容寫入日志,并作日志切換。

例3):當log buffer的大小是256M,而redo log file的大小是100M的時候,每個strand還是256M/4=64M。但是redo log file中的空間會按strand的個數(shù)平均分配,也就是每塊100M/4=25M。 

這樣,當每個strand中的內(nèi)容寫到25M的時候,就會日志切換,而不是64M。相當于log buffer中的一部分空間被浪費了。

5:檢查是否開啟歸檔日志壓縮

此功能的目的是在歸檔傳輸?shù)竭h程或者歸檔存儲到磁盤之前進行壓縮,以便減少歸檔日志傳輸?shù)臅r間和占用的磁盤空間??梢允褂孟旅婺_本檢查。

  1. SELECT NAME
  2.  ARCHIVELOG_COMPRESSION  
  3. FROM V$DATABASE
  4.  
  5.  
  6. SELECT TO_CHAR(FIRST_TIME, 'YYYY-MM-DD HH24:MI:SS'),  
  7.        BLOCKS * BLOCK_SIZE / 1024 / 1024,  
  8.        COMPRESSED  
  9. FROM   V$ARCHIVED_LOG;  
  10.  
  11.  
  12.  
  13. SQL> SELECT NAME
  14.   2         ARCHIVELOG_COMPRESSION 
  15.   3  FROM V$DATABASE
  16.  
  17. NAME      ARCHIVEL 
  18. --------- -------- 
  19. GSPP      DISABLED 

起初,估計很多人都會被這個所迷惑,其實ORACLE 10g 、 11g都是不支持歸檔日志壓縮的,也沒有明確的官方文檔說明,其實歸檔日志壓縮本來是ORACLE 10g計劃引入的新特性,不幸的是這個計劃放棄了,而且ORACLE 11g也不支持。

Archive compression was a planned new feature for 10G, but unfortunately it was withdrawn and it is still not available in 11g .This feature is expected in future releases

最后大家可以去metalink上看看Archived redolog is (significant) smaller than the redologfile. (文檔 ID 1356604.1)這篇文章,官方文檔不愧是官方文檔,最全面的闡述了歸檔日志比重做日志小的原因。

Archived redolog is (significant) smaller than the redologfile. (文檔 ID 1356604.1)

  1. There are 2 possible causes for this : 
  2.  
  3. 1. Documented and designed behaviour due to explicit forcing an archive creation before the redolog file is full 
  4. SQL> alter system switch logfile; 
  5. SQL> alter system archive log current
  6. RMAN> backup archivelog all
  7. RMAN> backup database plus archivelog; 
  8. ARCHIVE_LAG_TARGET : limits the amount of data that can be lost and effectively increases the availability of the standby database by forcing a log switch after the specified amount of time elapses. you can see this aswell in RAC with an idle/low-load instance. 
  9.  
  10. >2. Undocumented, but designed behaviour : 
  11. BUG 9272059 - REDO LOG SWITCH AT 1/8 OF SIZE DUE TO CMT CPU'S 
  12. BUG 10354739 - REDOLOGSIZE NOT COMPLETLY USED 
  13. BUG 12317474 - FREQUENT REDO LOG SWITCHES GENERATING SMALL SIZED ARCHIVELOGS  
  14. BUG 5450861 - ARCHIVE LOGS ARE GENERATED WITH A SMALLER SIZE THAN THE REDO LOG FILES 
  15. BUG 7016254 - DECREASE CONTROL FILE ENQUEUE WAIT AT LOG SWITCH 
  16.  
  17. Explanation : 
  18. As per Bug: 5450861 (closed as 'Not a Bug'): 
  19. * The archive logs do not have to be even in size. This was decided a very long time ago, 
  20. when blank padding the archive logs was stopped, for a very good reason - in order to save disk space
  21. * The log switch does not occur when a redo log file is 100% full. There is an internal algorithm 
  22. that determines the log switch moment. This also has a very good reason - doing the log switch 
  23. at the last moment could incur performance problems (for various reasons, out of the scope of this note). 
  24. As a result, after the log switch occurs, the archivers are copying only the actual information from the 
  25. redo log files. Since the redo logs are not 100% full after the log switch and the archive logs are 
  26. not blank padded after the copy operation has finished, this results in uneven, smaller files than 
  27. the original redo log files. 
  28. There are a number of factors which combine to determine the log 
  29. switch frequency. These are the most relevant factors in this case
  30.  
  31. a) RDBMS parameter LOG_BUFFER_SIZE 
  32. If this is not explicitly set by the DBA then we use a default
  33. at instance startup the RDBMS  calculates the number of shared redo 
  34. strands as ncpus/16, and the size of each strand is 128Kb * ncpus 
  35. (where ncpus is the number of CPUs in the system). The log buffer 
  36. size is the number of stands multiplied by the strand size
  37. The calculated or specified size is rounded up to a multiple of the granule size  
  38. of a memory segment in the SGA. For 11.2 if 
  39. SGA size >= 128GB then granule size is 512MB 
  40. 64GB <= SGA size < 128GB then granule size is 256MB 
  41. 32GB <= SGA size < 64GB then granule size is 128MB 
  42. 16GB <= SGA size < 32GB then granule size is 64MB 
  43. 8GB <= SGA size < 16GB then granule size is 32MB 
  44. 1GB <= SGA size < 8GB then granule size is 16MB 
  45. SGA size < 1GB then granule size is 4MB 
  46. There are some minimums and maximums enforced. 
  47.  
  48. b) System load 
  49. Initially only one redo strand is used, ie the number of "active" 
  50. redo strands is 1, and all the processes copy their redo into 
  51. that one strand. When/if there is contention for that strand then 
  52. the number of active redo strands is raised to 2. As contention 
  53. for the active strands increases, the number of active strands 
  54. increases. The maxmum possible number of active redo strands is 
  55. the number of strands initially allocated in the log buffer. 
  56. (This feature is called "dynamic strands"and there is a hidden 
  57. parameter to disable it which then allows processes to use all 
  58. the strands from the outset). 
  59.  
  60.  
  61. c) Log file size 
  62. This is the logfile size decided by the DBA when the logfiles are created. 
  63.  
  64. d) The logfile space reservation algorithm 
  65. When the RDBMS switches into a new online redo logfile, all the 
  66. log buffer redo strand memory is "mapped" to the logfile space
  67. If the logfile is larger than the log buffer then each strand 
  68. will map/reserve its strand size worth of logfile spaceand the 
  69. remaining logfile space (the "log residue"is still available. 
  70. If the logfile is smaller than the log buffer, then the whole 
  71. logfile space is divided/mapped/reserved equally among all the 
  72. strands, and there is no unreserved space (ie no log residue). 
  73. When any process fills a strand such that all the reserved 
  74. underlying logfile space for that strand is used, AND there is 
  75. no log residue, then a log switch is scheduled. 
  76.  
  77. Example : 128 CPU's so the RDBMS allocates a 
  78. log_buffer of size 128Mb containing 8 shared strands of size 16Mb. 
  79. It may be a bit larger than 128Mb as it rounds up to an SGA granule boundary. 
  80. The logfiles are 100Mb, so when the RDBMS switches into a 
  81. new online redo logfile each strand reserves 100Mb/8 = 25600 blocks 
  82. and there is no log residue. If there is low system loadonly one 
  83. of the redo strands will be active/used and when 25600 blocks of 
  84. that strand are filled then a log switch will be scheduled - the created 
  85. archive logs have a size around 25600 blocks. 
  86.  
  87. With everything else staying the same (128 cpu's and low load), 
  88. using a larger logfile would not really reduce the amount of 
  89. unfilled space when the log switches are requested, but it would 
  90. make that unfilled space less significant as a percentage of the 
  91. total logfile space, eg 
  92.  
  93. with a 100Mb logfile, the log switch happens with 7 x 16Mb 
  94. logfile space unfilled (ie the logfile is 10% full when the 
  95. log switch is requested) 
  96.  
  97. with a 1Gb logfile, the log switch would happen with 7 x 16Mb 
  98. logfile space unfilled (ie the logfile is 90% full when the 
  99. log switch is requested) 
  100. With a high CPU_COUNT, a low load and a redo log file size smaller than  
  101. the redolog buffer, you may see small archived log files because of log switches 
  102. at about 1/8 of the size of the define log file size
  103. This is because CPU_COUNT defines the number of redo strands (ncpus/16). 
  104. With a low load only a single strand may be used. With redo log file size smaller 
  105. than the redolog buffer, the log file space is divided over the available strands. 
  106. When for instance only a single active strand is used, a log switch can already occur 
  107. when that strand is filled. 

參考資料

[1]

鏈接已經(jīng)無效: http://www.ctonote.com/oracle/3236/

 

責任編輯:武曉燕 來源: DBA閑思雜想錄
相關推薦

2010-10-29 14:29:55

Oracle移動重做日

2010-11-19 13:42:38

2009-11-16 17:33:21

重做Oracle日志文

2010-10-29 15:07:33

oracle日志

2023-03-31 17:33:06

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

2010-10-29 14:44:35

ORACLE歸檔日志

2010-10-29 15:26:29

Oracle日志文件

2010-04-19 15:53:20

Oracle重做日志

2011-04-12 10:42:41

Oracle日志文件管理

2010-11-19 13:19:26

Oracle歸檔日志

2010-11-19 13:14:21

Oracle刪除歸檔日

2010-04-14 16:09:51

Oracle 10g歸

2018-03-12 14:33:49

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

2021-05-20 08:23:13

Oracle數(shù)據(jù)庫rac啟用

2010-10-29 13:30:33

Oracle歸檔日志

2010-04-20 12:09:31

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

2011-08-02 11:16:08

Oracle數(shù)據(jù)庫歸檔日志

2015-10-28 15:20:13

oracle歸檔日志ORA-00257

2011-08-09 18:40:21

Oracle控制文件重做日志文件

2010-11-19 13:28:13

點贊
收藏

51CTO技術(shù)棧公眾號