分类: Oracle
2008-04-25 22:05:34
Oracle的数据库日志称为redo log,所有数据改变都记录redo log,可以用于修复受损的数据库。大型数据库都采用日志,这样设计的好处都是一样的。
Redo日志是分组的,一个库至少需要两组,默认是三组。每个组内的redo日志称为成员。默认情况下,每个组只有一个成员,这样没有冗余性,可能造成online redo log的丢失,要提高数据的可靠性,应该为两个组至少配置两个成员,交将这两个成员分配到不同的磁盘上。
Redo日志是轮流使用的,一个redo log满了,LGWR会切换到下一组redo log,这种操作称为log switch,做log switch的同时也会做checkpoint,相应的信息还会写入控制文件。
也可以手工执行log switch或checkpoint操作
SQL> alter system switch logfile;
System altered.
SQL> alter system checkpoint;
System altered.
查看系统的redo log信息:
SQL> select group#,sequence#,bytes,members,status from v$log;
GROUP# SEQUENCE# BYTES MEMBERS STATUS
---------- ---------- ---------- ---------- ---------------- 1 5 104857600 1 INACTIVE 2 6 104857600 1 INACTIVE 3 7 104857600 1 CURRENT SQL> select member from v$logfile;
MEMBER
-------------------------------------------------------------------------------- /home/oracle/oradata/gldb/redo03.log /home/oracle/oradata/gldb/redo02.log /home/oracle/oradata/gldb/redo01.log 可以在线添加online redo log组:
SQL> alter database add logfile group 4 ('/home/oracle/oradata/gldb/redo04.log') size 1m;
Database altered.
SQL> select member from v$logfile;
MEMBER
-------------------------------------------------------------------------------- /home/oracle/oradata/gldb/redo03.log /home/oracle/oradata/gldb/redo02.log /home/oracle/oradata/gldb/redo01.log /home/oracle/oradata/gldb/redo04.log 可以在线添加online redo log组成员:
SQL> alter database add logfile member '/home/oracle/oradata/gldb/redo01b.log' to group 1;
Database altered.
SQL> select member from v$logfile;
MEMBER
-------------------------------------------------------------------------------- /home/oracle/oradata/gldb/redo03.log /home/oracle/oradata/gldb/redo02.log /home/oracle/oradata/gldb/redo01.log /home/oracle/oradata/gldb/redo04.log /home/oracle/oradata/gldb/redo01b.log 在线删除刚才添加的组和组成员:
SQL> alter database drop logfile group 4;
Database altered.
SQL> alter database drop logfile member '/home/oracle/oradata/gldb/redo01b.log';
Database altered.
SQL> select member from v$logfile;
MEMBER
-------------------------------------------------------------------------------- /home/oracle/oradata/gldb/redo03.log /home/oracle/oradata/gldb/redo02.log /home/oracle/oradata/gldb/redo01.log 归档Redo log文件:
启动日志归档有两个好处:
1,带有归档日志的数据库备份可以恢复到任意时间点。 2,可以在线备份数据库。 如果你的数据很重要,应该启用归档日志模式,否则数据库损坏时很可能只能恢复到上一次备份时的状态了。
缺省情况下,数据库是非归档日志模式。 可以用以下两条命令检查数据库的归档日志模式:
SQL> select archiver from v$instance;
ARCHIVE
------- STOPPED SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled Archive destination /home/oracle/product/9.2.0/dbs/arch Oldest online log sequence 7 Current log sequence 9 |