Home  >  Article  >  Database  >  Oracle RBA 浅谈

Oracle RBA 浅谈

WBOY
WBOYOriginal
2016-06-07 17:18:351037browse

今天来和大家简单谈一下rba ,rba = redo byte address 。讲到rba,这里涉及到了几点需要大家提前预知,即controlfile header,c

今天来和大家简单谈一下rba ,rba = redo byte address 。 

讲到rba,这里涉及到了几点需要大家提前预知,即controlfile header,ckpt process 与 dbwn process , dirty buffer 。

先来看一下RBA的构成:

它由3部分组成,4byte+4byte+2byte分别为 logfile sequence number ,logfile block number,byte offsetinto the block ,即redo 序列号,redo block 号,以及偏移量。

并且全部使用16进制。

例如:rba= 0x000024.000011bd.0010

seq#=0x000024=36

blk#=0x000011bd=4541

ofs#=0x0010=16

接下来说一下instance recovery

这里的Checkpoint position 其实就是cache low rba, End of redo thread就是最后一个on-disk rba

大家都知道实例恢复的时候需要从cache low rba 到 on-disk rba  , lowrba  与 on-disk 全部存储在控制文件里面,on-diskrba 可以简单的理解为是 lgwr 最后写日志文件的地址。那么cache low rba是如何而来呢?

cache low rba 其实就是ckpt进程每3秒写入到controlfileheader 上面的rba 。所以下面的文章将cache low rba 命名为ckpt rba 。

大家知道 ckpt 分为三种,即 database check points ,,Tablespace and datafile checkpoints和Incremental checkpoints。这里和第三种checkpoints有关。增量检查点的存在是为了防止在发生日志切换的时候,写出大量的dirty block 到disk上面,它每3秒会监控一下dbwn写出block的情况,并且写到controlfile header里面(不包括datafile header)。

这里有几点需要注意:

1.     dbwn 写出 dirtyblock 是使用一个叫做ckpt queue的双向链表来维护的,按照lrba的顺序写出dirty block 到 disk 上面。

2.     每个dirty block 上面都有一个lrba ,并且有一个指向ckpt queue的指针。

3.     dbwn触发条件,请详见concepts。

好,下面我们用实验说话: 

1.     先取出几个块的数据

01:57:02 dex@FAKE> select * from

01:58:10  2  (

01:58:10  3  selectdbms_rowid.rowid_relative_fno(substr(rowid,1,15)||'AAA') as file# ,

01:58:10  4        dbms_rowid.rowid_block_number(substr(rowid,1,15)||'AAA') as blk#,

01:58:10  5         max(t.id),max(t.name)

01:58:10  6    from dex.t

01:58:10  7   group by substr(rowid,1,15)

01:58:10  8   )

01:58:10  9   where rownum

     FILE#       BLK# MAX(T.ID) MAX(T.NAME)

---------- ---------- ---------- --------------------

         4        446     37949 name

         4        447     38433 name

         4        442     39401 name

看一下x$bh

02:02:17 sys@FAKE> select dbablk ,lrba_seq,lrba_bno,flag from x$bh b where file#=4 and dbablk in (442,446,447);

    DBABLK   LRBA_SEQ  LRBA_BNO       FLAG

---------- ---------- ---------- ----------

       442          0          0    524288

       447          0          0    524288

       446          0          0    524288

看一下当前的ckpt rba 和 ondisk rba

02:02:21 sys@FAKE> selectcplrba_seq,cplrba_bno,cplrba_bof,cpodr_seq,cpodr_bno,cpodr_bof,cphbt,cpodt fromx$kcccp where indx=0 ;

CPLRBA_SEQ CPLRBA_BNO CPLRBA_BOF  CPODR_SEQ CPODR_BNO  CPODR_BOF      CPHBT CPODT

---------- ---------- ---------- -------------------- ---------- ---------- --------------------

        37      10567          0         37     13157          0  791349660 08/15/2012 02:02:02

2.     更新数据

02:07:16 sys@FAKE> update dex.t setwhere id=37949 ;

1 row updated.

02:10:46 sys@FAKE> update dex.t setwhere id=38433 ;

1 row updated.

02:10:46 sys@FAKE> update dex.t setwhere id=39401 ;

1 row updated.

02:10:48 sys@FAKE> commit ;

Commit complete.

3.     查看一下各种状态

状态为脏数据

02:10:51 sys@FAKE> select dbablk ,lrba_seq,lrba_bno,flag from x$bh b where file#=4 and dbablk in (442,446,447);

   DBABLK   LRBA_SEQ   LRBA_BNO       FLAG

---------- ---------- ---------- ----------

      442         37      14429  33554433

      447         37      14429  33554433

      446         37      14429  33554433

现在的ckpt rba 为14104

02:10:56 sys@FAKE> selectcplrba_seq,cplrba_bno,cplrba_bof,cpodr_seq,cpodr_bno,cpodr_bof,cphbt,cpodt fromx$kcccp where indx=0 ;

CPLRBA_SEQ CPLRBA_BNO CPLRBA_BOF  CPODR_SEQ CPODR_BNO  CPODR_BOF      CPHBT CPODT

---------- ---------- ---------- -------------------- ---------- ---------- --------------------

       37      14104          0         37     14437          0  791349830 08/15/2012 02:10:51

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn