Chinaunix首页 | 论坛 | 博客
  • 博客访问: 894800
  • 博文数量: 101
  • 博客积分: 2256
  • 博客等级: 大尉
  • 技术积分: 1481
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-19 17:52
文章存档

2017年(1)

2013年(2)

2012年(25)

2011年(73)

分类: Oracle

2011-04-19 18:28:36

一.Oracle重做日志文件概念

重做日志文件(redo log file)对于Oracle数据库至关重要。它们是数据库的事务日志,通常只用于恢复。

二.查看重做日志的信息
Oracle提供了两个数据字典来查看重做日志信息,分别为v$log何v$logfile.
命令示范:

C:/Documents and Settings/jacky>sqlplus/nolog

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 3月 23 22:44:23 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> conn / as sysdba;
已连接。
SQL> select group#,sequence#,members,bytes,status,archived
2 from v$log;

GROUP# SEQUENCE# MEMBERS BYTES STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 5 1 52428800 INACTIVE NO
2 6 1 52428800 INACTIVE NO
3 7 1 52428800 CURRENT NO

SQL> --GROUP表示重做日志组的编号,SEQUENCES表示是日志的序列号;
SQL> --MEMBERS表示是每个组的成员数目;CURRENT表示这个组是当前
SQL> --正在使用的组,INACTIVE表示实例回复不需要这组日志了。
SQL> --还有UNUSED表示这个是刚刚添加到重做日志中的。ACTIVE表示
SQL> --是活动的但不是当前在用的。
SQL> col member for a50;
SQL> set line 140;
SQL> select * from v$logfile;

GROUP# STATUS TYPE MEMBER IS
_
---------- ------- ------- -------------------------------------------------- --
-
3 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO03.LOG NO

2 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO02.LOG NO

1 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO01.LOG NO


SQL> --空白:表示该文件的状态是正在使用;
SQL> --stale:表示该文件的内容是不完全的;
SQL> --invalid:表示该文件不可以被访问
SQL> --deleted:表示该文件已经不再有用了;
SQL>

三.添加和删除联机重做日志组

因为我刚刚看过我只有3个重做日志组,每个组只有一个成员;
我现在将增加2个组,并对原来的3个组进行删除,从而有全新的
强壮的重做日志组。
我先在我的F盘创建了文件夹REDOLOG,然后在REDOLOG下面建了
5个文件夹,来模拟5个磁盘;分别为disk01--disk05:
操作如下:

C:/Documents and Settings/jacky>sqlplus/nolog

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 3月 23 23:05:39 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> conn / as sysdba;
已连接。
SQL> set line 150
SQL> col member for a50
SQL> select * from v$logfile;

GROUP# STATUS TYPE MEMBER IS
_
---------- ------- ------- -------------------------------------------------- --
-
3 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO03.LOG NO

2 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO02.LOG NO

1 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO01.LOG NO


SQL> select group#,sequence#,members,bytes,status,archived
2 from v$log;

GROUP# SEQUENCE# MEMBERS BYTES STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 5 1 52428800 INACTIVE NO
2 6 1 52428800 INACTIVE NO
3 7 1 52428800 CURRENT NO

SQL> alter database add logfile
2 ('f:/redolog/disk04/redo04A.log',
3 'f:/redolog/disk04/redo04B.log',
4 'f:/redolog/disk04/redo04C.log')
5 size 15m;

数据库已更改。

SQL> alter database add logfile
2 ('f:/redolog/disk04/redo04A.log',
3 'f:/redolog/disk04/redo04B.log',
4 'f:/redolog/disk04/redo04B.log',
5
SQL> alter database add logfile group 5
2 ('f:/redolog/disk05/redo05A.log',
3 'f:/redolog/disk05/redo05B.log',
4 'f:/redolog/disk05/redo05C.log')
5 size 15m;

数据库已更改。

SQL> --查看一下是否增加了重做日志组;
SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 5 52428800 1 INACTIVE NO
2 6 52428800 1 INACTIVE NO
3 7 52428800 1 CURRENT NO
4 0 15728640 3 UNUSED YES
5 0 15728640 3 UNUSED YES

SQL> select * from v$logfile;

GROUP# STATUS TYPE MEMBER IS
_
---------- ------- ------- -------------------------------------------------- --
-
3 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO03.LOG NO

2 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO02.LOG NO

1 ONLINE E:/ORACLE/PRODUCT/10.2.0/ORADATA/JACKY/REDO01.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04A.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04B.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04C.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05A.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05B.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05C.LOG NO


已选择9行。

SQL> alter database drop logfile group 1;

数据库已更改。

SQL> alter database add logfile group 1
2 ('f:/redolog/disk01/redo01A.log',
3 'f:/redolog/disk01/redo01B.log',
4 'f:/redolog/disk01/redo01C.log')
5 size 15m;

数据库已更改。

SQL> alter database drop logfile group 2;

数据库已更改。

SQL> alter database add logfile group 2
2 ('f:/redolog/disk02/redo02A.log',
3 'f:/redolog/disk02/redo02B.log',
4 'f:/redolog/disk02/redo02C.log')
5 size 15m;

数据库已更改。

SQL> --查看状态
SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 0 15728640 3 UNUSED YES
2 0 15728640 3 UNUSED YES
3 7 52428800 1 CURRENT NO
4 0 15728640 3 UNUSED YES
5 0 15728640 3 UNUSED YES

SQL> --因为3号重做日志组是在线的,所以必须先切换日志,而且等到3号的
SQL> --状态变为INACTIVE才可以删除它。
SQL> alter system switch logfile;

系统已更改。

SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 8 15728640 3 CURRENT NO
2 0 15728640 3 UNUSED YES
3 7 52428800 1 ACTIVE NO
4 0 15728640 3 UNUSED YES
5 0 15728640 3 UNUSED YES

SQL> --因为目前3号还是ACTIVE,所以还不能删除,所以再次进行切换;
SQL> alter system switch logfile;

系统已更改。

SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 8 15728640 3 ACTIVE NO
2 9 15728640 3 CURRENT NO
3 7 52428800 1 ACTIVE NO
4 0 15728640 3 UNUSED YES
5 0 15728640 3 UNUSED YES

SQL> alter system switch logfile;

系统已更改。

SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 8 15728640 3 ACTIVE NO
2 9 15728640 3 ACTIVE NO
3 7 52428800 1 ACTIVE NO
4 10 15728640 3 CURRENT NO
5 0 15728640 3 UNUSED YES

SQL> alter system switch logfile;

系统已更改。

SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 8 15728640 3 INACTIVE NO
2 9 15728640 3 INACTIVE NO
3 7 52428800 1 INACTIVE NO
4 10 15728640 3 ACTIVE NO
5 11 15728640 3 CURRENT NO
SQL>--因为现在3号重做日志组已经是INACTIVE,非活动状态了。所以可以
SQL>--删除了。
SQL> alter database drop logfile group 3;

数据库已更改。
SQL> alter database add logfile group 3
2 ('f:/redolog/disk03/redo03A.log',
3 'f:/redolog/disk03/redo03B.log',
4 'f:/redolog/disk03/redo03C.log')
5 size 15m;

数据库已更改。

SQL> select group#,sequence#,bytes,members,status,archived
2 from v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS ARC
---------- ---------- ---------- ---------- ---------------- ---
1 8 15728640 3 INACTIVE NO
2 9 15728640 3 INACTIVE NO
3 0 15728640 3 UNUSED YES
4 10 15728640 3 INACTIVE NO
5 11 15728640 3 CURRENT NO

SQL> set line 150
SQL> set pagesize 25
SQL> col member for a50
SQL> select * from v$logfile order by group#,member;

GROUP# STATUS TYPE MEMBER IS
_
---------- ------- ------- -------------------------------------------------- --
-
1 ONLINE F:/REDOLOG/DISK01/REDO01A.LOG NO

1 ONLINE F:/REDOLOG/DISK01/REDO01B.LOG NO

1 ONLINE F:/REDOLOG/DISK01/REDO01C.LOG NO

2 ONLINE F:/REDOLOG/DISK02/REDO02A.LOG NO

2 ONLINE F:/REDOLOG/DISK02/REDO02B.LOG NO

2 ONLINE F:/REDOLOG/DISK02/REDO02C.LOG NO

3 ONLINE F:/REDOLOG/DISK03/REDO03A.LOG NO

3 ONLINE F:/REDOLOG/DISK03/REDO03B.LOG NO

3 ONLINE F:/REDOLOG/DISK03/REDO03C.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04A.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04B.LOG NO

4 ONLINE F:/REDOLOG/DISK04/REDO04C.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05A.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05B.LOG NO

5 ONLINE F:/REDOLOG/DISK05/REDO05C.LOG NO


已选择15行。

SQL> 完成,希望对各位网友有帮助!

阅读(1019) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~