Oracle 1Z031第七章维护redo log 文件

1Z031 第七章维护 redo log 文件
学习目标
1、 理解在线重做日志文件存在的目的
2、 描述在线重做日志文件的结构
3、 控制日志切换和检查点
4、 镜像和管理在线重做日志
5、 通过 OMF 管理在线重做日志
一、 使用 Redo log 文件
重做日志纪录所有对数据的改变,并且提供恢复机制供系统或者介质失败时恢复数据。重做日志组织成为日志组,每个 oracle 数据库至少需要 2 个日志组,每个重做日志组中的日至文件称为成员。
Purposes of the Redo Log Files
Redo log files provide the means to redo transactions in the event of a database failure. Every
transaction is written synchronously to the redo log files in order to provide a recovery
mechanism in case of media failure. (With exceptions such as: direct loads and direct reads
done with the NOLOGGING option.) This includes transactions that have not yet been
committed, undo segment information, and schema and object management statements. Redo
log files are used in a situation such as an instance failure to recover committed data that has
not been written to the data files. The redo log files are used only for recovery.
二、 重做日志的结构
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 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.
Creating Initial Redo Log Files
The initial set of online redo log groups and members are created during the database
creation.
The following parameters limit the number of online redo log files:
• The MAXLOGFILES parameter in the CREATE DATABASE command specifies the
absolute maximum of online redo log groups.
• The maximum and default value for MAXLOGFILES is dependent on your operating
system.
• The MAXLOGMEMBERS parameter used in the CREATE DATABASE command
determines the maximum number of members per group. The maximum and default
value for MAXLOGMEMBERS is dependent on your operating system.
三、 重做日志的工作方式
重做日志通过循环方式使用的,当 redo log 文件满的时候, LGWR 将切换到下一个日志组。
这被叫做日志切换
checkpoint 操作也同时出现
信息写到控制文件
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:
• When a transaction commits
• When the redo log buffer becomes one-third full
• When there is more than a megabyte of changed records in the redo log buffer
• Before the DBWn writes modified blocks in the database buffer cache to the data files
Redo logs are used in a cyclic fashion. Each redo log file group is identified by a log
sequence number that is overwritten each time the log is reused.
Log Switches
LGWR writes to the online redo log files sequentially. When the current online redo log
group is filled, LGWR begins writing to the next group. This is called a log switch.
When the last available online redo log file is filled, LGWR returns to the first online redo
log group and starts writing again.
Checkpoints
检查点的后台进程是CKPT,作用是更新所以数据文件和控制文件的头部。检查点可以在所以的数据文件上出现,也可以在特定的数据文件上出现。检查点在这些情况下出现:
1、 每次log 切换
2、 实例关闭normal,transactional,immediate
3、 强行改变FAST_START_MTTR_TARGET 参数的时候
4、 手动启动检查点
5、  
ALTER TABLESPACE [OFFLINE NORMAL|READ ONLY|BEGIN
BACKUP] 语句导致在特定的数据文件上出现 checkpoint
如果 LOG_CHECKPOINTS_TO_ALERT 设置为 TRUE,( 默认是 false) 每个检查点的信息将被记录在 alert_SID.log
During a checkpoint:
• A number of dirty database buffers covered by the log being checkpointed are written to
the data files by DBWn. The number of buffers being written by DBWn is determined
by the FAST_START_MTTR_TARGET parameter, if specified.
Note: The FAST_START_MTTR_TARGET parameter is covered in detail in the Oracle9i
DBA Fundamentals II course.
• The checkpoint background process CKPT updates the headers of all data files and
control files to reflect that it has completed successfully.
Checkpoints can occur for all data files in the database or for only specific data files.
A checkpoint occurs, for example, in the following situations:
• At every log switch
• When an instance has been shut down 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 [OFFLINE NORMAL|READ ONLY|BEGIN
BACKUP] cause checkpointing on specific data files.
Information about each checkpoint is recorded in the alert_SID.log file if the
LOG_CHECKPOINTS_TO_ALERT initialization parameter is set to TRUE. The default value
of FALSE for this parameter does not log checkpoints.
 
Forcing Log Switches and Checkpoints
强制日志切换和检查点
日志可以通过 alter system switch logfile 命令来强制切换。
检查点可以通过:
1、 设置 FAST_START_MTTR_TARGET 参数
2、 alter system checkpoint命令
 
fast_start_mttr_target参数是(deprecated,原文此处用这个词来修饰参数,这个词的本义是贬低,不赞成)参数fast_start_io_target 和 log_checkpoint_timeout的快捷方法。Fast_start_mttr_target = 600表明实例恢复时不能超过600秒,数据库会调整其他的参数达到这个目标。如果在使用了fast_start_mttr_target参数那么就不要用fast_start_io_target 和 log_checkpoint_timeout参数。
 
Adding Online Redo Log Groups
增加在线重做日志组
alter database add logfile group 3
('$HOME/ORADATA/u01/log3a.rdo',
'$HOME/ORADATA/u02/log3b.rdo')
size 1M;
如果在上述命令中不写组号,系统会自动地加上这个号码。
 
增加在线重做文件成员
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;
 
 
 
 
Dropping Online Redo Log Groups
干掉在线重做日志组
alter database drop logfile group 3;
注意:
1、           一个实例最少需要 2 个日志组。
2、           一个活动的或者当前日志组不能干掉。
3、           干掉重做日志组并不会干掉操作系统中的文件。
 
Dropping Online Redo Log Members
干掉重做日志成员
alter database drop logfile member
注意:
1、 如果这个成员是最后一个当前组成员,你不能删除。
2、 如果这个组是当前正在使用的组,那么你要删除组成员必须强制日志切换。
3、 如果数据库在archivelog模式,并且你要删除的成员属于还没有归档的组,那么这个成员不能删除。
4、 日志组成员被删除时,操作系统的文件不会删除。
 
Clearing, Relocating, or Renaming Online Redo Log Files
清除、重分配、重命名在线重做日志文件
1、 清除在线重做日志文件:
alter database clear logfile
'$HOME/ORADATA/u01/log2a.rdo';
如果重做日志在成员间冲突,管理员可以通过重新初始化日志文件来解决这个问题通过使用 alter database clear logfile 命令来解决。用这个命令等于增加和删除一个在线日志。但是你可以在只有 2 个日志组每个组只有一个文件的情况下运行这个命令,甚至这个被清理的组是可用但是没有归档。
注意:
你可以清理在线日志不管它是否归档。但是当它没有归档的情况下,你必须使用关键字 unarchived 。这将使备份不可用如果这个在线日志文件需要恢复( recovery )。
 
2、 重分配、重命名在线重做日志文件可以通过增加新成员删除旧成员来完成。
日志的位置可以通过增加新文件、删除旧文件来完成。另一个方法就是通过
alter database rename file 来完成,但是这需要数据库在 mount 状态。因此增加一个新文件,删除旧的更容易。
 
Online Redo Log Configuration
在线重做日志调整
 
在线日志文件的数量
决定合适的日志文件的数量,你需要测试多种配置调整。
某些情况下,一个实例可能仅需要2个组,在另外一些情况下,一个数据库实例需要额外的组来保证日志组始终对LGWR可用。例如如果在LGWR跟踪文件中或者alert文件中发现LGWR经常需要等待文件组因为检查点还没有完,或者日志组还没有归档,你必须增加组。
重做日志文件的位置
    当镜像在线日志文件的时候,把日志组成员放在不同的磁盘上。这样就算有一个成员不可用,也不需要关闭数据库。
    把archive log 文件和 online redo log 文件放在不同的磁盘上减少ARCn和LGWR后台进程之间的冲突。
    数据文件和redo log 文件要放置在不同的磁盘上,减少LGWR和DBWn之间的冲突,减少同时丢失数据文件和日志文件的风险。
日志文件的大小
    最小的日志文件的大小是50K,最大文件尺寸由操作系统决定。不同组成员的大小可以不一样。但是这样做没有任何好处。
    下述情况影响配置在线日志:
1、 日志切换和检查点的数量。
2、 redo entries的数量。
3、 存储介质的大小
 
Managing Online Redo Logs with OMF
通过OMF来管理在线重做日志
增加组是不需要指明文件
alter database add logfile
如果一个组被删除,所以的通过OMF管理的文件将在OS级别删除
 
Obtaining Group and Member Information
获取组和成员信息
通过查询下述字典
v$log
v$logfile
 
 
Archived Redo Log Files
归档重做日志文件
写满的重做日志文件可以被归档
归档重做日志有2个好处:
1、 恢复recovery:数据库备份时和在线日志,归档日志一起备份,可以保证恢复所有的提交了的事务。
2、 备份:可以在数据库打开的情况下备份。
默认的数据库在创建的时候处于noarchivelog模式
在归档日志模式下
    如果数据库运行在归档日志模式下,不活动的写满的组必须被归档。因为所有对数据库的改变必须记录在在线重做日志中,
    log_archive_start 初始化参数决定归档是否是自动进行。
 
Archived Redo Log Files
归档重做日志文件
1、 归档重做日志文件是由ARCn完成或者通过手工SQL语句。
2、 在控制文件中一个入口记录归档日志名字,日志序列数,和不管何时重做日志成功归档后创建高、低SCN数。
3、 写满的重做日志文件在检查点启动,重做日志被ARCn备份前不能被重用。
4、 归档的重做日志文件可以复制。
5、 归档的重做日志必须由DBA来操作。
 
归档日志信息可以通过查询V$INSTANCE得到
    select archiver from v$instance;
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值