Oracle的回滚段存储内容分析


    事务在执行DML操作时,会首先将相关的数据块写入数据缓冲区中,数据缓冲区中存储的是DML操作相关的完整数据块,比如我们对表中的某一个记录执行update操作,Oracle会将记录所在的数据块读入数据缓冲区中。

    在执行update操作之后,oracle后台进程会首先将修改前的内容(包括数据块中其他记录内容)以及scn,块信息等写入回滚段中,但这里写的时候不仅仅只是简单的块复制,而是将原来的数据块顺序写入回滚段的数据块。测试表明,在源表数据块占用空间较少的情况下(比如设置pctfree为99),对源表两个数据块中记录的修改只占用一个回滚段中的数据块(因为这时回滚段的数据块pctfree值是默认的,相对较小,一个回滚块可以存储更多的源数据块)。但如果设置源表占用空间较大,比如设置默认或者设pctfree为1,则对源表的两个数据块内容修改时,会占用回滚段中的两个数据块。

    同时会将修改记录的前后内容都写入重做日志文件中(这里只写入修改前后的该记录的信息,数据块中的其他记录将不会写入重做日志)。

    一旦用户对该操作执行了commit或rollback操作,回滚段内容会理解清空。

    现在我们来作个测试验证上面的说法。

    1, 创建一个用户表Trollsegment,并插入数据1000条记录到表中

drop table trollsegment;

create table trollsegment(
FID
integer,
Fname
varchar2(40),
Fothers
varchar2(40)
)
tablespace odsd
pctfree 98;


insert into trollsegment
select rownum, rpad('name',20,rownum),rpad('other',20,rownum)
from dba_objects
where rownum < 1000;

commit;

    2, 转储表中FID=10的数据块内容

select dbms_rowid.rowid_block_number(rowid),count(*)
from trollsegment
group by dbms_rowid.rowid_block_number(rowid)

select dbms_rowid.rowid_block_number(rowid),dbms_rowid.rowid_relative_fno(rowid),fid
from trollsegment
where fid = 10

1     7437       14    10

 

SQL> alter system dump datafile 14 block 7437;

 

System altered

 

*** 2009-02-07 10:28:48.629

Start dump data blocks tsn: 11 file#: 14 minblk 7437 maxblk 7437

buffer tsn: 11 rdba: 0x03801d0d (14/7437)

scn: 0x0001.8569780b seq: 0x01 flg: 0x02 tail: 0x780b0601

frmt: 0x02 chkval: 0x0000 type: 0x06=trans data

Block header dump:  0x03801d0d

 Object id on Block? Y

 seg/obj: 0x167cc  csc: 0x01.856977e6  itc: 2  flg: E  typ: 1 - DATA

     brn: 0  bdba: 0x3801d09 ver: 0x01

     inc: 0  exflg: 0

 

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc

0x01   0x0012.018.0000034d  0x0e000c3e.0054.48  --U-    3  fsc 0x0000.8569780b

0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000

 

data_block_dump,data header at 0x80000001001a3864

===============

tsiz: 0x1f98

hsiz: 0x18

pbl: 0x80000001001a3864

bdba: 0x03801d0d

     76543210

flag=--------

ntab=1

nrow=3

frre=-1

fsbo=0x18

fseo=0x1f08

avsp=0x1ef0

tosp=0x1ef0

0xe:pti[0]      nrow=3  offs=0

0x12:pri[0]     offs=0x1f08

0x14:pri[1]     offs=0x1f38

0x16:pri[2]     offs=0x1f68

block_row_dump:

tab 0, row 0, @0x1f08

tl: 48 fb: --H-FL-- lb: 0x1  cc: 3

col  0: [ 2]  c1 0b

col  1: [20]  6e 61 6d 65 31 30 31 30 31 30 31 30 31 30 31 30 31 30 31 30

col  2: [20]  6f 74 68 65 72 31 30 31 30 31 30 31 30 31 30 31 30 31 30 31

tab 0, row 1, @0x1f38

tl: 48 fb: --H-FL-- lb: 0x1  cc: 3

col  0: [ 2]  c1 0c

col  1: [20]  6e 61 6d 65 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31

col  2: [20]  6f 74 68 65 72 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31

tab 0, row 2, @0x1f68

tl: 48 fb: --H-FL-- lb: 0x1  cc: 3

col  0: [ 2]  c1 0d

col  1: [20]  6e 61 6d 65 31 32 31 32 31 32 31 32 31 32 31 32 31 32 31 32

col  2: [20]  6f 74 68 65 72 31 32 31 32 31 32 31 32 31 32 31 32 31 32 31

end_of_block_dump

End dump data blocks tsn: 11 file#: 14 minblk 7437 maxblk 7437

  • 1
  • 2
  • 3
  • 下一页

相关内容