Oracle11g温习-第七章:redo日志
2013年4月27日 星期六
10:33
1、redo (重做) log 的功能: 用于数据恢复 |
|||
2、redo log 特征: |
|||
日志组 和 日志文件的状态
日志切换: 1) 归档模式:将历史日志进行保存 ,并产生checkpoint,通知redo log 把对应的 dirty block 从data buffer写入到datafile,并且更新控制文件 2)非归档: 历史日志被覆盖【archive log list 可以查看数据库是否启用归档模式】
与日志相关的的数据字典
V$LOG 查看日志信息(从控制文件读取) V$LOGFILE 查看日志存放的位置
|
|||
|
|||
3、redo 日志组 |
|||
1) 最少两组,最好每组有两个成员,并存放到不同的磁盘上,大小相同,互相镜像 2) 日志在写满时发生切换,或 手工切换:alter system switch logfile ; 3) 在归档模式,日志进行归档,并把相关的信息写入controlfile |
|||
4、添加日志组 |
|||
SQL> startup ORACLE instance started.
Total System Global Area 251658240 bytes Fixed Size 1218820 bytes Variable Size 134219516 bytes Database Buffers 113246208 bytes Redo Buffers 2973696 bytes Database mounted. Database opened.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- 2 1 7 10485760 1 NO CURRENT 381102 02-AUG-11 1 1 6 10485760 1 NO INACTIVE 357157 01-AUG-11
SQL> select group#, member from v$logfile;
GROUP# MEMBER ---------- -------------------------------------------------- 2 /u01/app/oracle/oradata/cuug/redo02a.log 1 /u01/app/oracle/oradata/cuug/redo01a.log
SQL> select group#, member from v$logfile ;
GROUP# MEMBER ---------- -------------------------------------------------- 2 /u01/app/oracle/oradata/cuug/redo02a.log 1 /u01/app/oracle/oradata/cuug/redo01a.log 3 /u01/app/oracle/oradata/cuug/redo03a.log
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- 1 1 6 10485760 1 NO INACTIVE 357157 01-AUG-11 3 1 0 10485760 1 YES UNUSED 0 ——刚创建的日志组,处于未使用状态,进行日志切换即可 2 1 7 10485760 1 NO CURRENT 381102 02-AUG-11
SQL> alter system switch logfile; 手工切换日志
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME ---------- ---------- ---------- ---------- ---------- --------- ---------- ------------- ------------------- 1 1 7 104857600 1 NO INACTIVE 215301 2012-03-07 18:02:39 4 1 10 104857600 1 NO CURRENT 238364 2012-03-08 17:14:10 3 1 9 104857600 1 NO ACTIVE 237357 2012-03-08 16:49:45 2 1 8 104857600 1 NO INACTIVE 216223 2012-03-07 18:49:17
|
|||
5、添加日志组的成员 |
|||
SQL> select group#, member from v$logfile;
GROUP# MEMBER ---------- -------------------------------------------------- 2 /u01/app/oracle/oradata/cuug/redo02a.log 1 /u01/app/oracle/oradata/cuug/redo01a.log 3 /u01/app/oracle/oradata/cuug/redo03a.log SQL> select group#, member from v$logfile order by 1;
GROUP# MEMBER ---------- -------------------------------------------------- 1 /u01/app/oracle/oradata/cuug/redo01a.log 1 /disk1/cuug/oradata/redo01b.log 2 /disk1/cuug/oradata/redo02b.log 2 /u01/app/oracle/oradata/cuug/redo02a.log 3 /disk1/cuug/oradata/redo03b.log 3 /u01/app/oracle/oradata/cuug/redo03a.log |
|||
6、查看日志信息 |
|||
SYS@ prod>select SEQUENCE# ,FIRST_CHANGE#,NEXT_CHANGE# ,to_char(FIRST_TIME ,'yyyy-mm-dd- hh24:mi:ss') from v$log_history;
SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# TO_CHAR(FIRST_TIME,' ---------- ------------- ------------ -------------------- 1 446075 474850 2013-01-09- 03:55:23 2 474850 496815 2013-01-09- 03:59:39 3 496815 497931 2013-01-09- 04:02:31 4 497931 497947 2013-01-09- 04:38:17 5 497947 497961 2013-01-09- 04:39:01 6 497961 497971 2013-01-09- 04:39:36 7 497971 497975 2013-01-09- 04:39:58 8 497975 497983 2013-01-09- 04:40:03 9 497983 497986 2013-01-09- 04:40:21 10 497986 498899 2013-01-09- 04:40:25 11 498899 499047 2013-01-09- 05:01:09 12 499047 499055 2013-01-09- 05:02:54 13 499055 531192 2013-01-09- 05:02:58
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- 1 1 6 10485760 2 NO INACTIVE 357157 01-AUG-11 3 1 0 10485760 2 YES UNUSED 0 2 1 7 10485760 2 NO CURRENT 381102 02-AUG-11
SQL> alter system switch logfile;
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- 1 1 9 10485760 2 NO CURRENT 384007 02-AUG-11 3 1 8 10485760 2 NO ACTIVE 384005 02-AUG-11 2 1 7 10485760 2 NO ACTIVE 381102 02-AUG-11
----------查看生成的日志量
SQL> insert into scott.emp1 select * from scott.emp1; 28 rows created. SQL> insert into scott.emp1 select * from scott.emp1; 56 rows created. ——通过联合查询视图 v$statname ,v$mystat可以查看日志生成量
SYS @ prod >select a.name, b.value/1024/1024 "SIZE: M" from v$statname a,v$mystat b where b.statistic#=a.statistic# and a.name like '%redo size%';
NAME SIZE: M ---------------------------------------------------------------- ---------- redo size .019523621
|
|||
7、redo 日志成员重命名或迁移 【只能在mount状态下修改因为mount状态打开了控制文件】一定要确认新的位置有该文件否则报错 总之先改物理位置再改逻辑位置 无法修改日志文件的大小因为日志文件一旦建立就已经被格式化为oracle标准格式 所以无法修改 |
|||
|
|||
SQL> select group#,member from v$logfile order by 1;
GROUP# MEMBER ---------- -------------------------------------------------- 1 /u01/app/oracle/oradata/cuug/redo01a.log 1 /disk1/cuug/oradata/redo01b.log 2 /disk1/cuug/oradata/redo02b.log 2 /u01/app/oracle/oradata/cuug/redo02a.log 3 /disk1/cuug/oradata/redo03b.log 3 /u01/app/oracle/oradata/cuug/redo03a.log
6 rows selected.
SQL> shutdown immediate
Database closed. Database dismounted. ORACLE instance shut down.
[oracle@oracle ~]$ cp /u01/app/oracle/oradata/cuug/redo01a.log /disk2/cuug/oradata/ [oracle@oracle ~]$ cp /u01/app/oracle/oradata/cuug/redo02a.log /disk2/cuug/oradata [oracle@oracle ~]$ cp /u01/app/oracle/oradata/cuug/redo03a.log /disk2/cuug/oradata
[oracle@oracle ~]$ !sql
sqlplus '/as sysdba'
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 2 05:08:35 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount ;
ORACLE instance started.
Total System Global Area 251658240 bytes Fixed Size 1218820 bytes Variable Size 125830908 bytes Database Buffers 121634816 bytes Redo Buffers 2973696 bytes Database mounted.
SQL> select group# ,member from v$logfile order by 1;
GROUP# MEMBER ---------- -------------------------------------------------- 1 /u01/app/oracle/oradata/cuug/redo01a.log 1 /disk1/cuug/oradata/redo01b.log 2 /disk1/cuug/oradata/redo02b.log 2 /u01/app/oracle/oradata/cuug/redo02a.log 3 /disk1/cuug/oradata/redo03b.log 3 /u01/app/oracle/oradata/cuug/redo03a.log
SQL> alter database rename file '/u01/app/oracle/oradata/cuug/redo01a.log' to '/disk2/cuug/oradata/redo01a.log';
Database altered.
SQL> alter database rename file '/u01/app/oracle/oradata/cuug/redo02a.log' to '/disk2/cuug/oradata/redo02a.log';
Database altered.
SQL> alter database rename file '/u01/app/oracle/oradata/cuug/redo03a.log' to '/disk2/cuug/oradata/redo03a.log';
Database altered.
SQL> select group# ,member from v$logfile order by 1;
GROUP# MEMBER ---------- -------------------------------------------------- 1 /disk2/cuug/oradata/redo01a.log 1 /disk1/cuug/oradata/redo01b.log 2 /disk1/cuug/oradata/redo02b.log 2 /disk2/cuug/oradata/redo02a.log 3 /disk1/cuug/oradata/redo03b.log 3 /disk2/cuug/oradata/redo03a.log
6 rows selected.
SQL> alter database open;
Database altered.
SQL> select group# ,member from v$logfile order by 1;
GROUP# MEMBER ---------- -------------------------------------------------- 1 /disk2/cuug/oradata/redo01a.log 1 /disk1/cuug/oradata/redo01b.log 2 /disk1/cuug/oradata/redo02b.log 2 /disk2/cuug/oradata/redo02a.log 3 /disk1/cuug/oradata/redo03b.log 3 /disk2/cuug/oradata/redo03a.log
6 rows selected.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- 1 1 9 10485760 2 NO INACTIVE 384007 02-AUG-11 3 1 8 10485760 2 NO INACTIVE 384005 02-AUG-11 2 1 10 10485760 2 NO CURRENT 385481 02-AUG-11
日志文件 clear 假如主机断电 数据库启动报错该日志组的日志文件损坏必须要保证该日志组的状态不是current
Alter database clear logfile group 1; 清空损坏的日志组 就可以打开数据库了打开数据库以后oracle自行创建该组的日志成员 Alter database clear unarchived logfile group 2 ; 此乃当前日志组 报错 该日志组需要归档 |
|||
8、日志恢复 |
|||
1、多元化成员中,单个组成员丢失(不会影响到数据库的正常运行)(当前组和非当前组的都一样) 解决方法:复制一下就行
2、非当前日志组所有成员丢失(数据库打不开,只丢失单个就没影响,全丢失了就无法正常打开数据库) 解决方法:alter database clear logfile group 2 清理该组的所有成员日志即可
(清理一下该日志组的文件信息,因为日志组的状态是inactive,所有的脏块已经写入数据库,这样在启动时就不会进行校验了,此时数据库可以正常启动,当使用到该日志组的时候会自动创建日志组成员)
3、当前日志组丢失(正常关库 shutdown immediate)
|
|||
drop |
|||
clear |