oracle switch logfile日志切换及alter system checkpoint作了什么

日志切换或checkpoint到底发生了什么?
   1,刚变成active的日志文件(即由last_change#到next_change#的redo)被 dbwr写入到数据文件

   2,ckpt更新所有数据文件头的start scn即v$datafile_header.checkpoint_change#为刚变成active的日志文件
    的first_change#

   3,ckpt同时更新控制文件的检查点scn,即v$database.checkpoint_change#为active状态日志文件的first_change#

/***********测试开始*************/
/**********检查点发生前的数据文件头scn*********/
SQL> select checkpoint_change# from v$datafile_header;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected

SQL> select * from v$log;
 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARCHIVED STATUS           FIRST_CHANGE# FIRST_TIME  NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- ----------- ------------ -----------
         3          1        817   52428800        512          1 NO       INACTIVE              10453013 2013/3/24 1     10454569 2013/3/24 1
         4          1        818  209715200        512          1 NO       INACTIVE              10454569 2013/3/24 1     10492795 2013/3/24 1
         5          1        819  209715200        512          1 NO       INACTIVE              10492795 2013/3/24 1     10560992 2013/3/25 1
         6          1        820  209715200        512          1 NO       INACTIVE              10560992 2013/3/25 1     10561002 2013/3/25 1
         7          1        821  209715200        512          1 NO       INACTIVE              10561002 2013/3/25 1     10561202 2013/3/25 1
         8          1        822  209715200        512          1 NO       INACTIVE              10561202 2013/3/25 1     10588922 2013/3/25 1
         9          1        816  209715200        512          1 NO       INACTIVE              10446578 2013/3/24 1     10453013 2013/3/24 1
        10          1        823   20971520        512          1 NO       CURRENT               10588922 2013/3/25 1 281474976710
 
8 rows selected


SQL> select checkpoint_change# from v$database;
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
SQL> select checkpoint_change# from v$datafile;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected

/*********日志切换后各个scn*****************/
SQL> alter system switch logfile;
 
System altered
 
 
SQL> select checkpoint_change# from v$datafile;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected

SQL> select checkpoint_change# from v$database;
 
CHECKPOINT_CHANGE#
------------------
          10590730
         

SQL> select * from v$log;
 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARCHIVED STATUS           FIRST_CHANGE# FIRST_TIME  NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- ----------- ------------ -----------
         3          1        817   52428800        512          1 NO       INACTIVE              10453013 2013/3/24 1     10454569 2013/3/24 1
         4          1        818  209715200        512          1 NO       INACTIVE              10454569 2013/3/24 1     10492795 2013/3/24 1
         5          1        819  209715200        512          1 NO       INACTIVE              10492795 2013/3/24 1     10560992 2013/3/25 1
         6          1        820  209715200        512          1 NO       INACTIVE              10560992 2013/3/25 1     10561002 2013/3/25 1
         7          1        821  209715200        512          1 NO       INACTIVE              10561002 2013/3/25 1     10561202 2013/3/25 1
         8          1        822  209715200        512          1 NO       INACTIVE              10561202 2013/3/25 1     10588922 2013/3/25 1
         9          1        824  209715200        512          1 NO       CURRENT               10591778 2013/3/25 1 281474976710
        10          1        823   20971520        512          1 NO       ACTIVE                10588922 2013/3/25 1     10591778 2013/3/25 1
 
8 rows selected          
 
SQL> select checkpoint_change# from v$datafile_header;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected

小结:alter system checkpoint不会触发变更数据文件及数据文件头的检查点scn


/***********再看下日志切换是怎么样的情况********************/
/**************日志切换前*************************/
SQL> select checkpoint_change# from v$datafile_header;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected
 
SQL> select checkpoint_change# from v$datafile;
 
CHECKPOINT_CHANGE#
------------------
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
          10590730
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
21 rows selected
 
SQL> select checkpoint_change# from v$database;
 
CHECKPOINT_CHANGE#
------------------
          10590730
 
SQL> select * from v$log;
 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARCHIVED STATUS           FIRST_CHANGE# FIRST_TIME  NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- ----------- ------------ -----------
         3          1        817   52428800        512          1 NO       INACTIVE              10453013 2013/3/24 1     10454569 2013/3/24 1
         4          1        818  209715200        512          1 NO       INACTIVE              10454569 2013/3/24 1     10492795 2013/3/24 1
         5          1        819  209715200        512          1 NO       INACTIVE              10492795 2013/3/24 1     10560992 2013/3/25 1
         6          1        820  209715200        512          1 NO       INACTIVE              10560992 2013/3/25 1     10561002 2013/3/25 1
         7          1        821  209715200        512          1 NO       INACTIVE              10561002 2013/3/25 1     10561202 2013/3/25 1
         8          1        822  209715200        512          1 NO       INACTIVE              10561202 2013/3/25 1     10588922 2013/3/25 1
         9          1        824  209715200        512          1 NO       CURRENT               10591778 2013/3/25 1 281474976710
        10          1        823   20971520        512          1 NO       ACTIVE                10588922 2013/3/25 1     10591778 2013/3/25 1
 
8 rows selected
 
SQL>

/***********日志切换后****************/
SQL> alter system switch logfile;
 
System altered


SQL> select * from v$log;
 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARCHIVED STATUS           FIRST_CHANGE# FIRST_TIME  NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- ----------- ------------ -----------
         3          1        825   52428800        512          1 NO       CURRENT               10592541 2013/3/25 1 281474976710
         4          1        818  209715200        512          1 NO       INACTIVE              10454569 2013/3/24 1     10492795 2013/3/24 1
         5          1        819  209715200        512          1 NO       INACTIVE              10492795 2013/3/24 1     10560992 2013/3/25 1
         6          1        820  209715200        512          1 NO       INACTIVE              10560992 2013/3/25 1     10561002 2013/3/25 1
         7          1        821  209715200        512          1 NO       INACTIVE              10561002 2013/3/25 1     10561202 2013/3/25 1
         8          1        822  209715200        512          1 NO       INACTIVE              10561202 2013/3/25 1     10588922 2013/3/25 1
         9          1        824  209715200        512          1 NO       ACTIVE                10591778 2013/3/25 1     10592541 2013/3/25 1
        10          1        823   20971520        512          1 NO       INACTIVE              10588922 2013/3/25 1     10591778 2013/3/25 1
 
8 rows selected

/***参考上面日志信息,控制文件的检查点scn及数据文件及数据文件头的scn已经更新active日志的first_change#/
SQL> select checkpoint_change# from v$database;
 
CHECKPOINT_CHANGE#
------------------
          10591778
 
SQL> select checkpoint_change# from v$datafile;
 
CHECKPOINT_CHANGE#
------------------
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
 
CHECKPOINT_CHANGE#
------------------
          10591778
 
21 rows selected
 
SQL> select checkpoint_change# from v$datafile_header;
 
CHECKPOINT_CHANGE#
------------------
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
          10591778
 
CHECKPOINT_CHANGE#
------------------
          10591778
 
21 rows selected

参考文档:
  http://czmmiao.iteye.com/blog/1010267

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-757066/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-757066/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值