会员登录 - 用户注册 - 设为首页 - 加入收藏 - 网站地图 Oracle归档日志比联机重做日志小很多的情况总结!

Oracle归档日志比联机重做日志小很多的情况总结

时间:2025-11-05 16:04:33 来源:益强数据堂 作者:数据库 阅读:111次

本文转载自微信公众号「DBA闲思杂想录」,归档作者潇湘隐者 。日志转载本文请联系DBA闲思杂想录公众号。比联

Oracle归档日志比联机重做日志小很多,机重出现这种情况的做日志小总结原因有很多,我们可以从下面这几方面着手检查,情况一一排除确认。归档

1:检查参数ARCHIVE_LAG_TARGET

ARCHIVE_LAG_TARGET参数可以设置一个时间,日志通过时间限制,比联指定数据库强制进行Log Switch进行归档。机重如果这个参数设置过小,做日志小总结有可能导致联机重做日志还没有写满就切换了,情况这样就有可能导致归档日志远小于联机重做日志(redo log)。归档

SQL> show parameter archive_lag_target; NAME                                 TYPE        VALUE ------------------------------------ ----------- ------------------------------ archive_lag_target                   integer     0 SQL>

如果参数archive_lag_target为0,日志那么可以排除这方面的比联因素。

2:检查是否存在人为切换redo log的可能性。

一些命令可以引起重做日志的切换,具体请见下面

SQL> alter system archive log current; #归档命令也会造成日志切换 SQL> alter system switch logfile;      #直接切换日志组 RMAN> backup archivelog all; RMAN> backup database plus archivelog; SELECT TO_CHAR(FIRST_TIME, YYYY-MM-DD HH24:MI:SS),         BLOCKS * BLOCK_SIZE / 1024 / 1024,         COMPRESSED  FROM   V$ARCHIVED_LOG;

如下案例的截图如下所示,从截图看归档日志的大小在31M左右徘徊。另外,可以看到没有启用归档日志压缩选项(其实ORACLE不支持归档日志压缩,这个后面说明)。从归档日志大小的规律可以看出,这个不是某个重做日志切换命令引起的。IT技术网

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

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

4:跟CPU个数CPU_COUNT以及log_buffer、redo log size有关。

归档日志的大小是真实的在线日志文件的使用量,也就是在线日志文件切换前其中写入的内容的大小。为了更好的并行,减少冲突,提高并发,减少redo allocation latch的等待,ORACLE会将redo buffer分成若干小的buffer,每份小的buffer叫strand。按每16个CPU分一股(strand),每一股独立从redo buffer以及redo log中分配一块空间,当这一块redo buffer用完,会写入redo log并且继续从redo log中分配相同大小的空间,如果无法分配空闲空间就会进行日志切换,而不管其他strand是否写完。

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

SQL>  select 112.0/16 from dual;   112.0/16 ----------          7 SQL>  select 341655552/1024/1024/7 from dual;   --log buffer 341655552/1024/1024/7 ---------------------             46.546875 SQL> select 200/7 from dual;   --redo log size      200/7 ---------- 28.5714286 SQL>

当log buffer的大小是服务器托管325.828125M(341655552),分成7股(strand)的话,每个strand还是325.828125M/7=46.546875M。而redo log的大小是200M的时候,redo log中的空间会按strand的个数平均分配,也就是每块200M/7=28.5714286M。

这样,当每个strand中的内容写到28M多左右的时候,就会日志切换,而不是46M。相当于log buffer中的一部分空间被浪费了。所以你看到的归档日志基本是30M左右大小(其中一股(strand)28.6再加上其它各股也有部分内容写入,所以归档日志的大小就是一个波动的范围)

其它各个特殊场景分析,可以参考“归档日志的大小比在线日志的大小小很多[1]”这篇文章的企商汇介绍。当然这篇文章分析过程还忽略了其它各股其实也是有部分数据的。这个需要特别注意。

如果你对这个机制不是很清楚,上面链接的这篇博客已经不可访问了,下面是我摘抄的部分内容到此,方便大家深入理解:

比如CPU的个数是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没有剩余的未分配的空间了。

每个进程产生的redo会分配到log buffer上的1,2,3,4其中的某一个strand上,单个进程只能对应一个strand, 这样当数据库中只有某些进程(比如极端的情况,只有某一个进程)产生的redo很多的时候,其中一个strand会快速写满,比如图中的strand 1:

写满之后LGWR会将log buffer中strand 1的内容写入到redo log file中,并且试图从redo log file中分配一个新的64M空间,发现没有了,则将所有strand中的内容写入日志,并作日志切换。

这样,可能会导致redo log file只写入了一个strand的内容,其他部分几乎是空的,则产生的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的内容写入到redo log file中,并且试图从redo log file中分配一个新的64M空间,然后不断往下写。 图片

直到redo log file中再没有可分配空间了,则将所有strand中的内容写入日志,并作日志切换。

例3):当log buffer的大小是256M,而redo log file的大小是100M的时候,每个strand还是256M/4=64M。但是redo log file中的空间会按strand的个数平均分配,也就是每块100M/4=25M。 

这样,当每个strand中的内容写到25M的时候,就会日志切换,而不是64M。相当于log buffer中的一部分空间被浪费了。

5:检查是否开启归档日志压缩

此功能的目的是在归档传输到远程或者归档存储到磁盘之前进行压缩,以便减少归档日志传输的时间和占用的磁盘空间。可以使用下面脚本检查。

SELECT NAME,  ARCHIVELOG_COMPRESSION  FROM V$DATABASE; SELECT TO_CHAR(FIRST_TIME, YYYY-MM-DD HH24:MI:SS),         BLOCKS * BLOCK_SIZE / 1024 / 1024,         COMPRESSED  FROM   V$ARCHIVED_LOG;  SQL> SELECT NAME,   2         ARCHIVELOG_COMPRESSION   3  FROM V$DATABASE; NAME      ARCHIVEL --------- -------- 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)

There are 2 possible causes for this : 1. Documented and designed behaviour due to explicit forcing an archive creation before the redolog file is full SQL> alter system switch logfile; SQL> alter system archive log current; RMAN> backup archivelog all; RMAN> backup database plus archivelog; 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. >2. Undocumented, but designed behaviour : BUG 9272059 - REDO LOG SWITCH AT 1/8 OF SIZE DUE TO CMT CPUS BUG 10354739 - REDOLOGSIZE NOT COMPLETLY USED BUG 12317474 - FREQUENT REDO LOG SWITCHES GENERATING SMALL SIZED ARCHIVELOGS  BUG 5450861 - ARCHIVE LOGS ARE GENERATED WITH A SMALLER SIZE THAN THE REDO LOG FILES BUG 7016254 - DECREASE CONTROL FILE ENQUEUE WAIT AT LOG SWITCH Explanation : As per Bug: 5450861 (closed as Not a Bug): * The archive logs do not have to be even in size. This was decided a very long time ago, when blank padding the archive logs was stopped, for a very good reason - in order to save disk space. * The log switch does not occur when a redo log file is 100% full. There is an internal algorithm that determines the log switch moment. This also has a very good reason - doing the log switch at the last moment could incur performance problems (for various reasons, out of the scope of this note). As a result, after the log switch occurs, the archivers are copying only the actual information from the redo log files. Since the redo logs are not 100% full after the log switch and the archive logs are not blank padded after the copy operation has finished, this results in uneven, smaller files than the original redo log files. There are a number of factors which combine to determine the log switch frequency. These are the most relevant factors in this case: a) RDBMS parameter LOG_BUFFER_SIZE If this is not explicitly set by the DBA then we use a default; at instance startup the RDBMS  calculates the number of shared redo strands as ncpus/16, and the size of each strand is 128Kb * ncpus (where ncpus is the number of CPUs in the system). The log buffer size is the number of stands multiplied by the strand size. The calculated or specified size is rounded up to a multiple of the granule size  of a memory segment in the SGA. For 11.2 if SGA size >= 128GB then granule size is 512MB 64GB <= SGA size < 128GB then granule size is 256MB 32GB <= SGA size < 64GB then granule size is 128MB 16GB <= SGA size < 32GB then granule size is 64MB 8GB <= SGA size < 16GB then granule size is 32MB 1GB <= SGA size < 8GB then granule size is 16MB SGA size < 1GB then granule size is 4MB There are some minimums and maximums enforced. b) System load Initially only one redo strand is used, ie the number of "active" redo strands is 1, and all the processes copy their redo into that one strand. When/if there is contention for that strand then the number of active redo strands is raised to 2. As contention for the active strands increases, the number of active strands increases. The maxmum possible number of active redo strands is the number of strands initially allocated in the log buffer. (This feature is called "dynamic strands", and there is a hidden parameter to disable it which then allows processes to use all the strands from the outset). c) Log file size This is the logfile size decided by the DBA when the logfiles are created. d) The logfile space reservation algorithm When the RDBMS switches into a new online redo logfile, all the log buffer redo strand memory is "mapped" to the logfile space. If the logfile is larger than the log buffer then each strand will map/reserve its strand size worth of logfile space, and the remaining logfile space (the "log residue") is still available. If the logfile is smaller than the log buffer, then the whole logfile space is divided/mapped/reserved equally among all the strands, and there is no unreserved space (ie no log residue). When any process fills a strand such that all the reserved underlying logfile space for that strand is used, AND there is no log residue, then a log switch is scheduled. Example : 128 CPUs so the RDBMS allocates a log_buffer of size 128Mb containing 8 shared strands of size 16Mb. It may be a bit larger than 128Mb as it rounds up to an SGA granule boundary. The logfiles are 100Mb, so when the RDBMS switches into a new online redo logfile each strand reserves 100Mb/8 = 25600 blocks and there is no log residue. If there is low system load, only one of the redo strands will be active/used and when 25600 blocks of that strand are filled then a log switch will be scheduled - the created archive logs have a size around 25600 blocks. With everything else staying the same (128 cpus and low load), using a larger logfile would not really reduce the amount of unfilled space when the log switches are requested, but it would make that unfilled space less significant as a percentage of the total logfile space, eg - with a 100Mb logfile, the log switch happens with 7 x 16Mb logfile space unfilled (ie the logfile is 10% full when the log switch is requested) - with a 1Gb logfile, the log switch would happen with 7 x 16Mb logfile space unfilled (ie the logfile is 90% full when the log switch is requested) With a high CPU_COUNT, a low load and a redo log file size smaller than  the redolog buffer, you may see small archived log files because of log switches at about 1/8 of the size of the define log file size. This is because CPU_COUNT defines the number of redo strands (ncpus/16). With a low load only a single strand may be used. With redo log file size smaller than the redolog buffer, the log file space is divided over the available strands. When for instance only a single active strand is used, a log switch can already occur when that strand is filled.

参考资料

[1]

链接已经无效: http://www.ctonote.com/oracle/3236/

(责任编辑:数据库)

上一篇:创建的热点手机也是可以连接的,这里将分享两个方法一,kde-nm-connection-editor工具开启热点在ubuntu软件中心搜索kde nm connection注意搜索的关键词,不要出现横杠“-”,结果中出现kde-nm-connection-editor安装即可配置终端输入kde-nm-connection-editor跳出连接编辑器的图形界面在图形界面点击 添加-->Wireless(shared)弹出New Connection (New 802-11-wireless connection)图形界面Connection name:更改为mywifi(默认为New 802-11-wireless connection)SSID:更改为mywifi(默认为my_shared_connection)模式:选择Access PointRestrict to device:选择你的无线网卡点击无线安全选项卡安全:选择WPA & WPA2 Personal密码:填入你要设置的密码(至少8位)(这里就不上图了,相信大家看着提示可以设置成功!)连接刚才wifi,只有这样才能建立热点我们点击最上方网络管理的图标,选择 连接到隐藏的Wi-Fi网络Wifi适配器:选择我们设置了的无线网络连接:选择我们刚刚建立的连接名称(mywifi)之后网络名称(SSID),Wi-Fi安全性,密码会自动填写并变成灰色点击确定(这一步可能会出现解锁钥匙环的提示,输入你的电脑登陆密码就能解锁了)现在wifi热点就建立好了,试试你的手机能不能连上吧二,修改配置文件点右上角图标NetworkManager-->编辑连接在弹出的网络连接窗口中点添加在弹出的选择连接类型窗口中选择Wi-Fi,点击新建连接名称:填wifitestconfSSID:填wifitestconf模式:选择架构(注意不要选Ad-hoc)设备MAC地址:选择你要建立AP的网卡切换到Wi-Fi安全性选项卡安全:选WPA及WAP2个人密码:自己设置切换到IPv4设置选项卡方法:选与其它计算机共享点击保存更改配置文件然后我们来到刚才这个连接对应的配置文件终端执行命令ls -l /etc/NetworkManager/system-connections/-rw------- 1 root root 314  9月 19 15:34 360ap -rw------- 1 root root 215  9月 18 09:40 i-LiaoNing -rw------- 1 root root 316  9月 19 18:05 mywifi-rw-r--r-- 1 root root 318  9月 19 19:33 mywifi2-rw------- 1 root root 295  9月 19 19:46 Wi-Fitest -rw------- 1 root root 307  9月 19 19:45 Wi-Fitest~ -rw------- 1 root root 313  9月 19 20:07 wifitestconf-rw------- 1 root root 365  9月 19 19:39 Wi-Fi 连接 1-rw------- 1 root root 337  9月 19 19:37 Wi-Fi 连接 1~-rw------- 1 root root 252  9月 19 19:28 自动以太网可以看到第7个就是我们刚才的配置文件,我们打开它命令输入 sudo gedit /etc/NetworkManager/system-connections/wifitestconf在[802-11-wireless]下面找到mode=infrastructure把它改为mode=ap这里有两个需要注意的问题(1)假如保存之后在退出时仍然提示在关闭前将更改保存到文档“XXX”吗?说明此时文件已经被锁定:强制保存会导致关联的配置文件丢失解决方法如下:断开这个网卡的连接,继续保存。另一个解决方法,前面的编辑连接界面不关闭,完成后续更改,但是大多数人都会关闭的吧。假如保存之后从网络连接界面和连接隐藏的Wi-Fi网络的界面找不到这个连接的名字,说明关联的配置文件丢失解决方法。:编辑配置文件的时候请务必确保网络连接界面是打开的3.连接刚才wifi,只有这样才能建立热点我们点击最上方网络管理的图标,选择 连接到隐藏的Wi-Fi网络Wifi适配器:选择我们设置了的无线网络连接:选择我们刚刚建立的连接名称(wifitestconf)之后网络名称(SSID),Wi-Fi安全性,密码会自动填写并变成灰色点击确定,试试你的手机能不能连上吧。
下一篇:AOCG2770PF(细腻画质、流畅画面、不可忽视的价格)
推荐内容
  • 图解演示环境版本:本机系统: WIN7虚拟机:VMware Workstation 8 (英文版)安装目标:Ubuntu Desktop 12.04 LTS  (请点击这里)先下载好iso镜像文件详细过程图解:0. 初始画面,点击“Create a New Virtual Machine”(左上Ubuntu为本人已有开发环境机,请忽略)1. 点击“Custom(自定义)”2. 无需选择,直接Next(上面是选Workstation版本的兼容性的,这里默认为当前版本8.0,之前版本的不同在于Limitations(局限),如内存更少,不支持HD Audio等)3. 选择“I will install the operating system later”这里无严格要求的同学,是可以选择第二项“Installer disc image file (ios)”的,之后会VMware会自动得知你的iso是Linux(Ubuntu),只要求你输入Full name,和用户名密码等简单的用户设定,但是这是一个Easy install,如VMware原文所说“When the New Virtual Wizard detects an operating system that supports Easy Install, the wizard prompts you for information about the guest operating system. After the virtual machine is created, the guest operating system installation is automated and VMware Tools is installed.” 我觉得是因为这个OS的自动安装,不完全,导致一些核心命令无法使用、无反应等一些问题。所以有更高要求的同学,不能选这项,需要完全、自定义的安装。4. 在Version下选择“Ubuntu”,注:64位Ubuntu需要选下面那个“Ubuntu 64-bit”5. 设置虚拟机名称(即每次启动VMware左上方显示的名字),之后选择你想的在WIN7里的安装路径(默认在C盘,很不方便)。6. Number of processors(处理器个数)选择为2我是i7处理器,配置较好无压力的,感觉双核比单核好一些(假如没用VMware不会这么设计,但是对于更多的,没必要),下面那个应该没必要选,有非常懂的同学,请留言赐教。7. 内存大小选择,使用自动推荐的1G内存(本机内存8G)。同学们在虚拟机里,应该不会跑什么惊天地泣鬼神的大程序,内存大不等于快,而是更多的数据放在内存里而非硬盘里,对于内存消耗大的程序、系统会变快。去年做本科毕设的时候,调整过虚拟机的内存从1G为2G,结果竟然变慢了,应该是外面WIN7被占用了的问题。8. Network Type网络类型选择,本次选择默认的“NAT”注:这里有一点本人经历的非常重要需要说明,使用“NAT”的话,需要外面的WIN7使用一根线连接上网,才能在Ubuntu里上网(如同Ubuntu是你的真正OS的感觉,不需要手工配置任何IP信息),不能默认使用无线连接。这点对有些笔记本同学可能会造成麻烦。当然不是说不能通过手动配置IP相关解决,但是为了避免每次都配置的麻烦,请直接使用“bridged”桥接手动配置。9. 默认即可,直接“Next”10. 默认即可,直接“Next”第三项为直接划分硬盘给该虚拟机使用,意思应为绕过WIN7的那个文件夹管理,直接给虚拟机只用一块硬盘空间,有高级需要的同学可以选择。所以,注:默认的那个可以轻松实现copy,move,当你想拷给另外一个人,或者换机器的时候。11. 磁盘选择,默认即可,直接“Next”12. 选择“Store virtual disk as a single file”上面那个方框,是说现在就立即分20G给这个虚拟机,假如不够,还是会一点一点随着你的使用增加(跟不选一样)。假如同时没有很多个虚拟机装在WIN7上,或者硬盘空间太大又不放东西,可选。13. 虚拟机文件的存放地址,选个D盘的位置就行了。14. 点击“Finish”,完成了虚拟机的配置工作这里点击“Customize Hardware”的话,有机会对前面不满意的虚拟机硬件设置(处理器个数,内存大小等)重新设置,所以前面不满意的同学,不用点cancel重来,实际上在以后的使用过程,也是可以随时改变虚拟机的配置的,这点不用担心。15. 完成后,可以看到左上角多出了“Ubuntu 12.04”,先别急着Power on,还没装ubuntu呢。。。点击“Edit virtual machine settings”16. 在弹出的settings里,点击“CD/DVD(IDE)”,然后在右侧点击“Use ISO image file”,再选择你开始下载好的Ubuntu 12.04的iso镜像文件的路径然后点“OK”。17. 启动虚拟机,即点击step 15里的“Power on this virtual machine”,之后Ubuntu 12.04开始了安装,先选择语言,然后点击“Install Ubuntu”18. 假如选择“Download updates while installing”为安装过程直接安装最近的更新,假如选择“Install this third-party software”为安装第三方软件19. 选择“Something else”,将要对虚拟机的20G硬盘做手动分区20. 点击“New Partation Table”(新建分区表)21. 在弹出的对话框里,选择“Contunie”22. 选中新出现的“free space”(空闲空间),点击“Add”23. 注意下图中的“Primary”,“Beginning”, “Ext4 ...”均为默认,不需要修改;数字为大小,以MB为单位(注:不用追求1024凑整,硬盘实际上是凑不整的。。。),这里选择10000=10G;最后的“Mount point(挂载点)”下拉列表中,选中“/”,完成该步,点“OK”注意:“/ ” 建议大小在5GB以上。(根据关于“Ubuntu手动分区”的多个相关文章一致得来)非常注意:本人上次弄了个6G,结果进去下libraries,一下就满了,那叫一个悲剧!所以,同学们千万别抱着“5G以上”来想,ubuntu应该自己就占了4、5G,不想悲剧的同学至少8G以上吧,20G确实不大,但是假如打算长期的同学,应该不会使用虚拟机了,20G跑程序,绰绰有余,等喜欢了熟悉了,再来个真的吧。24. 再次选中“free space”(同step 22图中),点击“Add”;注意下图中“Logical”,“Beginning”均为默认,大小选择1000(1G);在Use as的下拉列表中选择“swap area”,注:最后的下拉列表为灰色,意为swap area不用选择挂载点;完成该步,点“OK”注意:“swap area” 即交换分区,建议大小是物理内存的1~2倍。(根据关于“Ubuntu手动分区”的多个相关文章一致得来)不需要太大,1G足以。25. 再次选中“free space”(同step 22图中),点击“Add”;注意下图中“Logical”,“Beginning”, “Ext4 ...”均为默认;注:大小选择也为默认,即所有的剩余空间;最后的“Mount point”下拉列表中,选中“/home”;完成该步,点“OK”注意:“/home” 存放普通用户的数据,是普通用户的宿主目录,建议大小为剩下的空间。(根据关于“Ubuntu手动分区”的多个相关文章一致得来)注:三个分区的顺序不要变,因为/home在最后便于默认选择“剩余的空间”,避免手工分配。26. 至此,所有分区工作已经完成,如下图所示。注:假如不满意可以点击“Revert(还原)”来重新分区,直到满意和准确无误为止。假如感到满意,点击“Install Now”注:上图为悲剧图,6G的/是不够的,这个图没有更新,仅供参考,不比看数字。27. 选择你所在的时区,自动调整时间,夏令时什么的手动调不方便,之后都点击“Continue”以继续28. 键盘选择US,一般国内买的电脑都是这样的,可根据情况自己选择29. Ubuntu的个人设置,根据自己需要填写用户名密码等30. 最后安装完成,点击“Restart Now”重启Ubuntu即可31. 停止在如下画面,按“回车”即可至此,全部安装过程完毕,我们可以进入到Ubuntu 12.04的桌面工作了。一定要注意:由于未使用自动安装,所以现在我们的虚拟机不含有VM Tools,导致无法全屏虚拟机等等问题,需要安装VM tools,详情请搜索即可。
  • 大规模MySQL运维陷阱:使用MyCat踩坑篇
  • Nim语言在蓝军实战中的研究总结
  • Tekton系列之实践篇-使用Tekton Trigger让Tekton使用更简单
  • 优化麦本本散热,提升性能体验(有效降温,提高散热效果)
  • 这样做数据清理,可以避免引发MySQL故障
热点内容