Online redo logfiles(在线重做日志文件)
The most crucial structure for recovery is the online redo log,
which consists of two or more preallocated files that store changes to the database as they occur.
The online redo log records changes to the data files。
在线重做日志文件,是用于recovery的最重要的结构;
里面包含了两个或者更多的预分配的文件,来存放数据库的变化情况;
在线重做日志记录数据文件的变化;
在线重做日志以日志组为单位;
日志组的大小决定里面每个成员的大小;
日志组的每个成员之间是镜像关系;
两个关键的数据字典来描述在线重做日志文件的信息?
V$LOG displays log file information from the control file.
V$LOGFILE contains information about redo log files
SYS@orcl11g> set pagesize 20
SYS@orcl11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ -------------------
1 1 25 52428800 512 1 NO INACTIVE 1229803 2013-06-16 09:55:15 1244798 2013-06-16 12:30:58
2 1 26 52428800 512 1 NO CURRENT 1244798 2013-06-16 12:30:58 2.8147E+14 (null)
3 1 24 52428800 512 1 NO INACTIVE 1205465 2013-06-16 09:00:22 1229803 2013-06-16 09:55:15
GROUP# NUMBER Log group number --日志组的编号
THREAD# NUMBER Log thread number -- 日志线程号(多实例的情况下有用)
SEQUENCE# NUMBER Log sequence number -- 日志序列号
BYTES NUMBER Size of the log (in bytes) -- 日志组大小
BLOCKSIZE NUMBER Block size of the logfile (512 or 4096) -- 日志文件块大小
MEMBERS NUMBER Number of members in the log group -- 日志组的成员个数
ARCHIVED VARCHAR2(3) Archive status (YES) or (NO) -- 归档状态
STATUS VARCHAR2(16) Log status: -- 日志组状态
■ UNUSED - Online redo log has never been written to. This is the state
of a redo log that was just added, or just after a RESETLOGS, when it
is not the current redo log.
■ CURRENT - Current redo log. This implies that the redo log is active.
The redo log could be open or closed.
■ ACTIVE - Log is active but is not the current log. It is needed for
crash recovery. It may be in use for block recovery. It may or may not
be archived.
■ CLEARING - Log is being re-created as an empty log after an ALTER
DATABASE CLEAR LOGFILE statement. After the log is cleared, the
status changes to UNUSED.
■ CLEARING_CURRENT - Current log is being cleared of a closed
thread. The log can stay in this status if there is some failure in the
switch such as an I/O error writing the new log header.
■ INACTIVE - Log is no longer needed for instance recovery. It may be
in use for media recovery. It may or may not be archived.
FIRST_CHANGE# NUMBER Lowest system change number (SCN) in the log -- 记录了该日志组中最小的scn号
FIRST_TIME DATE Time of the first SCN in the log -- 记录该日志组中最早的事件发生的时间
NEXT_CHANGE# NUMBER highest system change number (SCN) in the log -- 记录了下一个日志组的first_change#
NEXT_TIME DATE Time of the next scn -- next_change#对应的时间
V$LOGFILE contains information about redo log files
SYS@orcl11g> col member for a50
SYS@orcl11g> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- -------------------------------------------------- ---
3 (null) ONLINE /u01/app/oracle/oradata/orcl11g/redo03.log NO
2 (null) ONLINE /u01/app/oracle/oradata/orcl11g/redo02.log NO
1 (null) ONLINE /u01/app/oracle/oradata/orcl11g/redo01.log NO
GROUP# NUMBER Redo log group identifier number -- 日志组编号
STATUS VARCHAR2(7) Status of the log member: -- 日志文件状态
■ INVALID - File is inaccessible
■ STALE - File's contents are incomplete
■ DELETED - File is no longer used
■ null - File is in use
TYPE VARCHAR2(7) Type of the logfile:
■ ONLINE
■ STANDBY
MEMBER VARCHAR2(513) Redo log member name -- 日志文件名
IS_RECOVERY_DEST_FILE VARCHAR2(3) Indicates whether the file was created
in the fast recovery area (YES) or not (NO)
日志组的管理:
如何增加日志组?
SYS@orcl11g> alter database add logfile group 4
2 '/u01/app/oracle/oradata/orcl11g/redo04.log'
3 size 50m;
Database altered.
如何增加日志组成员?
SYS@orcl11g> alter database add logfile member
2 '/u01/app/oracle/oradata/redolog/redo042.log'
3 to group 4;
Database altered.
如何删除一个日志组成员?
SYS@orcl11g> alter database drop logfile member
2 '/u01/app/oracle/oradata/redolog/redo042.log';
Database altered.
如何删除一个日志组?
SYS@orcl11g> alter database drop logfile group 4;
Database altered.
注意:当前状态的日志组的成员或者整个日志组不能被删除;
active状态的日志组,如果有多个成员,可以删除其中的成员;
但是不能删除整个日志组;
日志组的切换:
1.自动切换:当日志组被写满之后,自动发生切换行为;
2.手动切换:alter system switch logfile;
改变日志组的状态?
SYS@orcl11g> alter system checkpoint;
如何改变日志的大小和位置呢?
1.改变日志组状态,变成inactive的组可以被删除;
2.重新添加一个新的如何要求的日志组即可;
确定日志切换的频率?
SYS@orcl11g> set pagesize 50
SYS@orcl11g> l
1* select sequence#,first_time from v$log_history order by 1
SYS@orcl11g> /
SEQUENCE# FIRST_TIME
---------- -------------------
1 2013-05-28 15:32:48
2 2013-05-28 15:36:35
3 2013-05-28 15:36:53
4 2013-05-28 15:37:54
5 2013-05-28 15:39:03
6 2013-05-28 15:47:01
7 2013-05-31 13:57:38
8 2013-06-03 10:17:14
9 2013-06-03 16:47:15
如何控制日志切换频率呢?
通过控制日志文件的大小,来控制日志切换频率;
定期切换日志:
SYS@orcl11g> alter system set archive_lag_target=300;
System altered.
SYS@orcl11g> show parameter archive_lag_target
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target integer 300