Maintain redo log file

Object

After complete this lesson, you should be able to do the following :

  • Explain the purpose of online redo log files
  • Outline the structure of online redo log files
  • Control log switches and checkpoints
  • Multiplex and maintain online redo log files
  • Manage online redo logs files with OMF

 Every transaction is written synchronously to the redo log files in order to provide a recovery mechanism in case of media failure. ( With exception such as: direct loads and direc reads done with the NOLOGGING option. ) 这里的 with NOLOGGING 就是不写日志文件的意思.

1.Redo log file 作用

Redo log files provide the means to redo transactions in the event of a database failure. The redo log files are userd only for recovery .

2.Structure of the Redo Log Files


  • Online Redo Log Groups
    • A set of identical copies of online redo log files is called an online redo log group .
    • The LGWR background process concurrently writes the same information to all online redo log files in a group . ( 同时向组内成员写数据,所以组内数据一样)
    • The Oracle server needs a minimum of two online redo log file groups for the normal operation of a database .
  • Online Redo Log Members
    • Each online redo log file in a group is called a member .
    • Each member in a group has identical log sequence numbers and the same size . The log sequence number(LSN group为单位) is assigned each time the Oracle server starts writing to a log group to identify each redo log file uniquely . The current log sequence number is stored in the control file and in the header of all data files .
  • The MAXLOGFILES parameter in the CREATE DATABASE 确定了最大的groups.
  • The MAXLOGMEMBERS parameter in the CREATE DATABASE 确定了最大的members.
3. Redo Logs Work

The Oracle server sequentially records all changes made to the database in the redo log buffer .The redo entries(条目) are written from the redo log buffer to one of the online redo log groups called the current online redo log group by the LGWR process .LGWR writes under the following situations :

  1. when a transaction commits.
  2. when the redo log buffer becomes one-third full ( 1/3 满 )
  3. when there is more than a megabtye ( MB ) of changed recoreds in the redo log buffer
  4. Before the DBWn writes modified blocks in the database buffer cache to the data files
  • 循环工作
  • When a redo log file is full, LGWR will move to the next log group . ( LOG Switch ) ( 强行执行 , alter system switch logfile )
    • This is called a log switch
    • Checkpoint operation also occurs
    • Information is written to the control file
  • Checkpoint ( 强行执行 , alter system checkpoint ) 检查点,在数据库恢复时,检查点的很有用,类似划分阶段的作用一样。
    • At every log switch
    • When an instance has been shutdown with the normal, transactional, or immediate option
    • When forced by setting the initialization parameter FAST_START_MTTR_TARGET
    • When manually requested by the database administrator
    • When the ALTer TABLESPACE .
    • Information about each checkpoint is recorded in the alert_sid.log if the LOG_CHECKPOINTS_TO_ALERT initialization parameter is set to TRUE, 默认是faluse.
  • 强制执行Log switches , Checkpoints ( DBA 可以执行 )
    • alter system switch logfile
    • Setting FAST_START_MTTR_TARGET parameter , alter system checkpoint ( 这个单位是秒, 比如数字是 600,就指每隔600秒必须执行一次 ckpt )

重做日志组内的每一个联机日志文件称为一个成员

        一个组内的每一个成员具有相同的日志序列号(log sequence number),且成员的大小相同

        每次日志切换时,Oracle服务器分配一个新的LSN号给即将写入日志的日志文件组

        LSN号用于唯一区分每一个联机日志组和归档日志

        处于归档模式的联机日志,LSN号在归档时也被写入到归档日志之中

 

 

lgwr 写的比较快,很可能第一个 redolog file 启动的 checkpoint 还没有完成,而这时的 lgwr就不能覆盖掉之前的 redo log file , 如果不是 archieved log 模式,就要等待。这理解错误了,即便是 archieved log模式,如果是这种情况,也要等待,archieved log模式只是说,如果一个 member写满了,会将这个内容写到归档日志里,这样,即便你覆盖了member也有备份,仅此而已。 解决这个问题的关键在于,可以多创建几个group, 这样就没有问题了,如果只有两个 group,那么当第一组写满以后,启动check point,开始往磁盘里数据,而这个时候如果第2组也满了,就要等待 group 1 写完以后,覆盖掉 group 1的日志,但是如果这个时候有个group 3的话,那么就可以往group 3里写.

log switch 重要概念 : The act of switching from one log file group to the other is called a log switch ( 在 redo log file 中 )

checkpoint 重要概念 : A checkpoint is the  writing of dirty( modified ) blocks from the buffer cache to disk . ( datafile 中 )

4. Adding Online Redo Log Groups

ALTER DATABASE ADD LOGFILE GROUP 3

( '$home/oradata/u01/log3a.rdo' ,

  '$HOME/ORADATA/u02/log3b.rdo' )

SIZE 1M ;

5. Adding Online Redo Log Numbers

ALTER DATABASE ADD LOGFILE MEMBER

'$HOME/ORADATA/u04/log1c.rdo' TO GROUP 1,

'$HOME/ORADATA/u04/log2c.rdo' TO GROUP 2,

'$HOME/ORADATA/u04/log3c.rdo' TO GROUP 3;

需要指定路径, 如果之前存在此名字的member , 那么要在 ' filename ' 加上 reuse 标签

6. Dropping Online Redo Log Groups

ALTER DATABASE DROP LOGFILE GROUP 3 ;

限制:

  1. An instance requires at least two groups of online redo log files.
  2. An active or current group cannot be dropped .
  3. When an online redo log group is dropped , the operating system files are not deleted .
7. Dropping Online Redo Log Members

ALTER DATABASE DROPLOGFILE MEMBER '$HOME/ORADATA/u04/log3c.rdo' ;

限制 :

  1. If the member you want to drop is the last valid member of the group , you cannot drop that member .
  2. if the group is current , you must force a log file switch before you can drop the member .
  3. if hte database is running in ARCHIVELOG mode and the log file group to which the member blongs is not archived , then member cannot be dropped .
  4. When an online redo log member is dropped , the operating system file is not deleted .
8. Clearing , Relocating , Renaming  Online Redo log files
  • Clearing online redo log files: alter database clear logfile '$HOME/ORADATA/u01/log2a.rdo' ; ( Using this command is equivalent to adding and dropping an online redo log files. ( 但是可以clear , 比如只有2组, 或者组内只有1个member都没关系 ) 针对member
  • Relocating and Renaming Redo log files :(换存放区域,只需要删除旧的文件,创建新的文件, 修改名称需要将数据库设置成mount状态 )
  • 删除旧的,建立新的。
9. Online Redo Log configuration
  • 适当数量的group
  • Location , 将同一个组的不同member存放在不同disk中, 将archive log file 和 online redo log file 分放在不同磁盘上. data file 和 online redo log file 放在不同 disk中
  • Size 一样大小比较好. ( member )
10. 获得 redo log file 信息在数据字典中
  • V$LOG , V$LOGFILE
11. Archived Redo Log Files

Filled online redo log files can be archived.

2个好处 :

  1. 回复时保证数据不会丢失.
  2. 在数据库开启时也可以被备份.

default : NOARCHIVELOG mode , 推荐 : ARCHIVELOG mode.

NOARCHIVELOG : In NOARCHIVELOG mode, the online redo log files are overwritten each time an online redo log file is filled, and log switches occur, LGWR does not overwrite a redo log group until the checkpoint for that group is completed.

archive : 两种模式 , 一种是自动, 一种是手动 , ( 推荐使用自动 ) LOG_ARCHIVE_START ( initialization parameter 先则是否是自动还是手动 )

archive : 比如某个 inactive groups of filled online redo log files must be archived .

  • Archiving 发生在 ( 自动 ARCn ) 或者 手动操作的时候.
  • 重要信息会保存在 control file中. archive log name, log sequence number 等等
  • A filled redo log file cannot be reused until a checkpoint has taken place and the redo log file has been backed up the ARCn proces . ( 重要, 因为如果不选择 Archiving mode , 则当 redo log file 被写满时, 需要等待 checkpoint , 而 Archiving mode 的情况下, 可以将 redo log file 写入 archiving 档案, 所以, 可以继续使用 redo log file .
  • Archived redo log files can be multiplexed.
  • Archived redo log files must be maintained by the DBA.

archived 信息可以查询 ; V$INSTANCE

个人总结

本章主要介绍了 redo log 的原理, 结构

archivelog 的好处

注意 LSN 是分配给同一组的多个MEMBER一起的, 并且同一组内的多个MEMBER的LSN是相同的.

以及一些针对 redo log group, member 的操作

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值