Overview of the Online Redo Log --- 在线重做日志概述

对于 oracle 恢复来说最重要的数据结构莫过于online redo log(在线重做日志), 在线重做日志包含至少两个预先分配好的,用来存储数据库变化的文件。在线重做日志记录着数据文件中的变化。



Online Redo Log有什么作用


Oracle 数据库通过在线重做日志文件来确保数据不丢失。特别是当实例失败后, oracle数据库可以通过在线重做日志文件恢复已经提交但尚未写到数据文件中的数据。

Oracle 数据库把每个事务先同步写到 redo log buffer,然后再写到在线重做日志文件中。日志的内容包括未提交的事务,undo数据,模式对象管理声明。

Oracle 数据库使用在线重做日志仅仅用于恢复。数据库管理员也可以使用 LogMiner这个工具来查询在线重做日志。在线重做日志文件是一个有用的反映数据库历史的信息源。



Oracle数据库怎样写 Online Redo Log


数据库实例的在线重做日志通常也被称为 redo线程。在单实例的环境中,仅仅只有一个实例访问数据库,因此只有一个 redo线程正在运行。而在 Oracle RAC环境中,通常有两个或者两个以上的实例并发的访问数据库,每个数据库实例拥有一个redo线程。每个实例拥有单独的redo线程是为了避免对唯一的在线重做日志文件的竞争。

在线重做日志一般包含两个或者两个以上的日志文件。Oracle数据库要求至少包含两个日志文件来保证其中一个对写可用,而另外一个用来归档(如果数据库运行在归档模式下)



Online Redo Log切换


Oracle Database uses only one online redo log file at a time to store records written from the redo log buffer. The online redo log file to which the log writer (LGWR) process is actively writing is called the current online redo log file.


Oracle 数据库同一时间只能使用一个在线重做日志文件来存储 redo log buffer 中的数据。LGWR进程正在写的在线重做日志文件称为当前的在线重做日志文件。


A log switch occurs when the database stops writing to one online redo log file and begins writing to another. Normally, a switch occurs when the current online redo log file is full and writing must continue.However, you can configure log switches to occur at regular intervals,regardless of whether the current online redo log file is filled, and force logs witches manually.


日志切换发生在数据库停止往一个在线重做日志文件并且开始往另一个日志文件写的时候。一般来说,当当前的在线重做日志文件已经满了并且还必须继续写的是偶,日志切换就会发生。然后,你可以设置日志切换定期发生,不管当前的在线重做日志文件是否已经充满,强制手动执行日志切换。


Log writer writes to online redo log files circularly. When log writer fills the last available online redo log file, the process writes to the first log file, restarting the cycle. Figure 11-6 illustrates the circular writing of the redo log.


LGWR 循环的写在线重做日志文件。当 LGWR 写满了最后一个在线重做日志文件,这个进程会重新往第一个日志文件中写新的数据。


Figure 11-6 Reuse of Online Redo Log Files




The numbers in Figure 11-6 shows the sequence in which LGWR writes to each online redo log file. The database assigns each file a new log sequence number when a log switches and log writers begins writing to it. When the database reuses an online redo log file, this file receives the next available log sequence number.

Filled online redo log files are available for reuse depending on the archiving mode:

  • If archiving is disabled, which means that the database is in NOARCHIVELOG mode, then a filled online redo log file is available after the changes recorded in it have been checkpointed (written) to disk by database writer (DBW).
  • If archiving is enabled, which means that the database is in ARCHIVELOG mode, then a filled online redo log file is available to log writer after the changes have been written to the data files and the file has been archived.

已经填充满的在线重做日志文件是否可以重用取决于是否是在归档模式下:

如果不是在归档模式下,当在线重做日志文件中的变化的记录已经被 DBW 进程写到了磁盘上之后,已经填充满的在线重做日志文件可以重用;

如果是在归档模式下,当在线重做日志文件中变化的记录已经写到数据文件中并且文件已经归档后,已经填充满的在线重做日志文件可以重用;


In some circumstances, log writer may be prevented from reusing an existing online redo log file. For example, an online redo log file may be active (required for instance recovery) rather than inactive (not required for instance recovery). Also, an online redo log file may be in the process of being cleared.



Online Redo Log Files多个备份


Oracle Database can automatically maintain two or more identical copies of the online redo log in separate locations. An online redo log group consists of an online redo log file and its redundant copies. Each identical copy is a member of the online redo log group. Each group is defined by a number, such as group 1, group 2, and so on.


Oracle 数据库能够自动管理两个或者多个不同位置的在线重做日志文件的相同备份集。一个在线重做日志文件组包含一个在线重做日志文件和它的冗余备份。每个完全相同的备份是在线重做日志文件组中的一个成员。每个组用数字来定义,例如 group 1, group 2 等等。


Maintaining multiple members of an online redo log group protects against the loss of the redo log. Ideally, the locations of the members should be on separate disks so that the failure of one disk does not cause the loss of the entire online redo log.


保存在线重做日志文件组的多个成员来保证重做日志不丢失。理论上说,日志文件组的成员的存放位置应该放在磁盘上的不同位置,这样即使一个磁盘损坏也不会导致整个在线重做日志文件丢失。


In Figure 11-7, A_LOG1 and B_LOG1 are identical members of group 1, while A_LOG2 and B_LOG2 are identical members of group 2. Each member in a group must be the same size. LGWR writes concurrently to group 1(members A_LOG1 and B_LOG1), then writes concurrently to group2 (members A_LOG2 and B_LOG2), then writes to group 1, and so on. LGWR never writes concurrently to members of different groups.


在图 11-7 中,A_LOG1 和 B_LOG1 是 group 1 中的相同的成员,而 A_LOG2 和 B_LOG2 是 group 2中的相同的成员。每个组中的成员必须大小一致。后台进程 LGWR 并发的写数据到 group 1,然后并发的写数据到 group 2,然后再并发的写数据到 group 1. LGWR 从不会并发写数据到不同的组。


Figure 11-7 Multiple Copies of Online Redo Log Files




注意: 

Oracle recommends that you multiplex the online redo log. The loss of log files can be catastrophic if recovery is required. When you multiplex the online redo log, the database must increase the amount of I/O it performs. Depending on your system, this additional I/O may impact overall database performance.

Oracle 推荐保留多份在线重做日志文件。日志文件的丢失对于恢复来说将是致命的。但是当你保留多份在线重做日志时,数据库必须增加执行 I/O 的数量。这种额外的 I/O 是否会影响数据库的整体性能取决于你的系统

 

Archived Redo Log Files(归档重做日志文件)


归档日志文件是在线重做日志文件的一个备份,也不认为是数据库的一部分,但是归档日志文件是数据库创建的在线重做日志文件的离线备份并且可以写到指定的位置。

归档日志文件是和恢复策略中非常重要的部分,你可以使用归档日志文件用来:

  • Recover a database backup (恢复数据库)
  • Update a standby database (更新备用数据库)
  • Obtain information about the history of a database using the LogMiner utility (通过logminer获取数据库的历史信息)

归档是产生归档日志文件的一个操作,归档这个操作只有在数据库运行在归档日志模式才有效,可以自动也可以手动


An archived redo log file includes the redo entries and the log sequence number of the identical member of the online redo log group. In Figure 11-7, files A_LOG1 and B_LOG1 are identical members of Group 1. If the database is in ARCHIVELOG mode, and if automatic archiving is enabled, then the archiver process (ARCn) will archive one of these files. If A_LOG1 is corrupted, then the process can archive B_LOG1. The archived redo log contains a copy of every group created since you enabled archiving.


一个归档日志文件包含redo entries(重做条目)和在线重做日志文件组相同的日志序列号。在图 11-7 中,文件 A_LOG1 和 B_LOG1 是 Group 1 相同的成员。如果数据库运行在归档日志模式下并且开启了自动归档,那么归档进程(ARCn)将他们中一个进行归档。如果 A_LOG1 损坏了,归档进程可以对 B_LOG1 进行归档。如果你开启了归档,已经归档的重做日志文件将包含每个在线重做日志文件组的备份。



Online Redo Log结构


在线重做日志中包含许多 redo records(重做记录).一条重做记录由一组改变向量组成,每个改变向量描述了对一个数据块的修改。例如,在employees表中修改salary就会产生一条redo记录,用来描述这个表的数据段发生的变化,undo段数据块以及undo段的事务表。

重做记录包含改变的所有相关的基本元数据,具体如下:

  • 改变时的SCN和时间戳
  • 产生这个变化的事务的ID
  • 事务提交的SCN和时间戳(如果已经提交)
  • 产生变化的操作类型
  • 被修改的数据段的名字和类型

 

原文来自文档:http://docs.oracle.com/cd/E11882_01/server.112/e40540/physical.htm#CNCPT1113

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值