SUMSEN

Oracle&Sql爱好者,用友NC管理员

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Oracle的主要文件类型有三种,分别是控制文件,数据文件和日志文件;日志文件记录了对数据库的所有操作记录,提供了一个恢复机 制,oracle将数据写入数据文件之前,需要将修改过的内容写入redo日志文件,oracle推荐最少存在两个日志文件组,每个组中存在两个或更多的 成员文件;LGWR进程根据日志组循环写,日志组的中的文件成员大小是一致的,并分配(LSN)log sequence number;当写满一个文件组的时候,Oracle会触发一个log switch切换到另一个日志组,将LSN号码加一,同时引发check point,DBWR进程将修改过的数据写入磁盘上的数据文件中;

触发lgwr的5个条件:

在一个事务提交之后

每三秒钟

当redo buffer cache三分之一满后

当redo buffer cache里面修改过的数据容量达到1M后

在dbwn进程将修改过的数据写入磁盘文件之前

SQL> select group#,thread#,sequence#,archived,status from v$log;    //查看日志组总数和当前active状态的日志组,当前为1

    GROUP#    THREAD# SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
         1          1         46 NO CURRENT
         2          1         44 YES INACTIVE
         3          1         45 YES INACTIVE


SQL> alter system switch logfile;       //手动触发一次日志切换

System altered.

SQL> select group#,thread#,sequence#,archived,status from v$log;    //可以看到当前active的日志组已经切换为2

    GROUP#    THREAD# SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
         1          1         46 YES ACTIVE
         2          1         47 NO CURRENT
         3          1         45 YES INACTIVE


如 果LGWR进程工作很频繁,日志组很快就会被写满,这个时候就需要DBWN进程将修改过的数据写到数据文件中,否则Oracle将无法正常工 作,fast_start_mttr_target参数定义了DBWN进程在多少时间间隔内必须将redolog中的数据写入数据文件,单位为秒,这是个 影响数据库性能的关键参数;

SQL> show parameter fast_start;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fast_start_io_target                 integer     0
fast_start_mttr_target               integer     0
fast_start_parallel_rollback         string      LOW
SQL> alter system set fast_start_mttr_target=600 scope=both; //修改这个参数为600秒

System altered.

SQL> show parameter fast_start_mttr_target;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fast_start_mttr_target               integer     600


SQL> desc v$logfile;   //查看日志组成员信息
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
GROUP#                                             NUMBER
STATUS                                             VARCHAR2(7)
TYPE                                               VARCHAR2(7)
MEMBER                                             VARCHAR2(513)
IS_RECOVERY_DEST_FILE                              VARCHAR2(3)

SQL> col member format a40;
SQL> select * from v$logfile;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE /u01/oradata/yang/redo03.log             NO
         2         ONLINE /u01/oradata/yang/redo02.log             NO
         1         ONLINE /u01/oradata/yang/redo01.log             NO


SQL> alter database add logfile group 4 ('/u01/oradata/yang/redo04a.rdo','/u01/oradata/yang/redo04b.rdo') size 50M; //添加一个新的日志组,组编号为4,存在两个组成员,大小各位50M

Database altered.

SQL> select * from v$logfile where group#=4;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         4         ONLINE /u01/oradata/yang/redo04a.rdo            NO
         4         ONLINE /u01/oradata/yang/redo04b.rdo            NO

SQL> !ls -lh /u01/oradata/yang/redo04*  
-rw-r----- 1 oracle oinstall 51M 09-20 09:49 /u01/oradata/yang/redo04a.rdo
-rw-r----- 1 oracle oinstall 51M 09-20 09:49 /u01/oradata/yang/redo04b.rdo

SQL> alter database add logfile member '/u01/oradata/yang/redo01.rdo' to group 1;   //添加一个新的成员到日志组1

Database altered.

SQL> select * from v$logfile where group#=1;   //INVALID状态时由于当前的的日志组并非active日志组

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         1 INVALID ONLINE /u01/oradata/yang/redo01.rdo             NO

SQL> select * from v$logfile order by group#;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         1         ONLINE /u01/oradata/yang/redo01.rdo             NO
         2         ONLINE /u01/oradata/yang/redo02.log             NO
         3         ONLINE /u01/oradata/yang/redo03.log             NO
         4         ONLINE /u01/oradata/yang/redo04b.rdo            NO
         4         ONLINE /u01/oradata/yang/redo04a.rdo            NO

6 rows selected.


SQL> alter database drop logfile group 4;   //删除日志组

Database altered.

SQL> select * from v$logfile order by group#;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         1         ONLINE /u01/oradata/yang/redo01.rdo             NO
         2         ONLINE /u01/oradata/yang/redo02.log             NO
         3         ONLINE /u01/oradata/yang/redo03.log             NO


SQL> alter database drop logfile member '/u01/oradata/yang/redo01.rdo';   //删除日志组成员

Database altered.

SQL> select * from v$logfile order by group#;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         2         ONLINE /u01/oradata/yang/redo02.log             NO
         3         ONLINE /u01/oradata/yang/redo03.log             NO

redo log的rename和relocation:这种操作对数据库的影响非常大,在生产环境中执行前最好要对数据库进行一次完整备份
1:可以采用添加新的组,删除旧的组来实现
2:数据库级别上实现

SQL> select * from v$logfile where group#=1;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         1         ONLINE /u01/oradata/yang/redo01.rdo             NO

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !
[oracle@jsb-ylw-5024 ~]$ mv /u01/oradata/yang/redo01.rdo /u01/oradata/redo01a.log
[oracle@jsb-ylw-5024 ~]$ exit
exit

SQL> startup mount
ORACLE instance started.

Total System Global Area 1620115456 bytes
Fixed Size                  2213816 bytes
Variable Size            1056966728 bytes
Database Buffers          553648128 bytes
Redo Buffers                7286784 bytes
Database mounted.
SQL> alter database rename file '/u01/oradata/yang/redo01.rdo' to '/u01/oradata/redo01a.log';

Database altered.

SQL> alter database open;

Database altered.

SQL> select * from v$logfile where group#=1;

    GROUP# STATUS TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         1         ONLINE /u01/oradata/yang/redo01.log             NO
         1         ONLINE /u01/oradata/redo01a.log                 NO

posted on 2013-01-12 14:33  sumsen  阅读(547)  评论(0编辑  收藏  举报