[20180202]脏块写盘问题.txt
--//别人问的问题,如果要写脏块的scn号比块小,脏块会写盘吗?
--//感觉这种情况不可能出现,脏块的scn应该是最高的,即使rac环境,也不会出现这种情况.
--//测试看看,顺便温习bbed使用(感觉好久不用了)
1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SYS@book> alter database flashback on;
Database altered.
--//这样关闭IMU特性,避免IMU的干扰.我测试环境有dg,也关闭.
create table t (id number, update_scn number, commit_scn number,pad varchar2(20));
insert into t values (1,dbms_flashback.get_system_change_number,userenv('commitscn'),lpad('x',10,'x'));
commit;
SCOTT@book> select ora_rowscn,rowid,t.* from scott.t;
ORA_ROWSCN ROWID ID UPDATE_SCN COMMIT_SCN PAD
------------ ------------------ ------------ ------------ ------------ --------------------
13278359044 AAAWUIAAEAAAAI0AAA 1 13278359039 13278359043 xxxxxxxxxx
SCOTT@book> @ &r/rowid AAAWUIAAEAAAAI0AAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
------------ ------------ ------------ ------------ -------------------- -------------------- ----------------------------------------
91400 4 564 0 0x1000234 4,564 alter system dump datafile 4 block 564 ;
SYS@book> alter system flush buffer_cache ;
System altered.
2.先复习修改scn看看.
select 13278359044,trunc(13278359044/power(2,32)) scn_wrap,mod(13278359044,power(2,32)) scn_base from dual
13278359044 SCN_WRAP SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
13278359044 3 393457156 3 1773ae04
$ cat scn.cmd
set count 8192
set width 210
p dba 4,564 kcbh.bas_kcbh
p dba 4,564 ktbbh.ktbbhcsc.kscnbas
p dba 4,564 ktbbh.ktbbhitl[0].ktbitflg
p dba 4,564 ktbbh.ktbbhitl[0].ktbitbas
p dba 4,564 ktbbh.ktbbhitl[1].ktbitflg
p dba 4,564 ktbbh.ktbbhitl[1].ktbitbas
#p dba 4,564 ktbbh.ktbbhitl[2].ktbitflg
#p dba 4,564 ktbbh.ktbbhitl[2].ktbitbas
quit
$ $ORACLE_HOME/bin/bbed parfile=bbed.par cmdfile=scn.cmd
BBED> p dba 4,564 kcbh.bas_kcbh
ub4 bas_kcbh @8 0x1773ae04
BBED> p dba 4,564 ktbbh.ktbbhcsc.kscnbas
ub4 kscnbas @28 0x1773ae01
BBED> p dba 4,564 ktbbh.ktbbhitl[0].ktbitflg
ub2 ktbitflg @60 0x2001 (KTBFUPB)
BBED> p dba 4,564 ktbbh.ktbbhitl[0].ktbitbas
ub4 ktbitbas @64 0x1773ae04
BBED> p dba 4,564 ktbbh.ktbbhitl[1].ktbitflg
ub2 ktbitflg @84 0x0000 (NONE)
BBED> p dba 4,564 ktbbh.ktbbhitl[1].ktbitbas
ub4 ktbitbas @88 0x00000000
ub4 tailchk @8188 0xae040601
SCOTT@book> select current_scn from v$database ;
CURRENT_SCN
------------
13278359159
select 13278359159,trunc(13278359159/power(2,32)) scn_wrap,mod(13278359159,power(2,32)) scn_base from dual
13278359159 SCN_WRAP SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
13278359159 3 393457271 3 1773ae77
--//修改块4,564的scn=13278359159
assign dba 4,564 kcbh.bas_kcbh=0x1773ae77
assign dba 4,564 ktbbh.ktbbhitl[0].ktbitbas=0x1773ae77
modify /x 010677ae offset 8188
sum apply dba 4,564
--//modify 注意顺序.
SCOTT@book> alter system flush buffer_cache ;
System altered.
SYS@book> select ora_rowscn,rowid,t.* from scott.t;
ORA_ROWSCN ROWID ID UPDATE_SCN COMMIT_SCN PAD
------------ ------------------ ------------ ------------ ------------ --------------------
13278359159 AAAWUIAAEAAAAI0AAA 1 13278359039 13278359043 xxxxxxxxxx
--//OK.成功.
3.开始测试:
SYS@book> update scott.t set pad='aaa',COMMIT_SCN=userenv('commitscn') where id=1;
1 row updated.
SYS@book> commit ;
Commit complete.
SYS@book> select ora_rowscn,rowid,t.* from scott.t;
ORA_ROWSCN ROWID ID UPDATE_SCN COMMIT_SCN PAD
------------ ------------------ ------------ ------------ ------------ --------------------
13278381233 AAAWUIAAEAAAAI0AAA 1 13278359039 13278381232 aaa
SYS@book> select current_scn+100 from v$database ;
CURRENT_SCN+100
---------------
13278381367
select 13278381367,trunc(13278381367/power(2,32)) scn_wrap,mod(13278381367,power(2,32)) scn_base from dual
13278381367 SCN_WRAP SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
13278381367 3 393479479 3 17740537
assign dba 4,564 kcbh.bas_kcbh=0x17740537
assign dba 4,564 ktbbh.ktbbhitl[0].ktbitbas=0x17740537
modify /x 01063705 offset 8188
sum apply dba 4,564
$ dbv file=/mnt/ramdisk/book/users01.dbf
--OK!!
SYS@book> @ &r/bh 4 564
old 23: dbarfil = &1 and
new 23: dbarfil = 4 and
old 24: dbablk = &2
new 24: dbablk = 564
HLADDR DBARFIL DBABLK CLASS CLASS_TYPE STATE TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA OBJECT_NAME
---------------- ------------ ------------ ------------ ------------------ ---------- ---- ------------ ------------ ------------ ------------ ------------ ---------------- -----------
00000000844A29F8 4 564 1 data block xcur 2 0 0 0 0 0 0000000074592000 T
00000000844A29F8 4 564 1 data block cr 1 393479342 3 0 0 0 0000000074594000 T
00000000844A29F8 4 564 1 data block free 0 0 0 0 0 0 00000000758EA000 T
00000000844A29F8 4 564 1 data block free 0 0 0 0 0 0 0000000075708000 T
00000000844A29F8 4 564 1 data block free 0 0 0 0 0 0 0000000078EFE000 T
00000000844A29F8 4 564 1 data block free 0 0 0 0 0 0 0000000077478000 T
6 rows selected.
SYS@book> alter system flush buffer_cache ;
System altered.
SYS@book> select ora_rowscn,rowid,t.* from scott.t;
ORA_ROWSCN ROWID ID UPDATE_SCN COMMIT_SCN PAD
------------ ------------------ ------------ ------------ ------------ --------------------
13278381233 AAAWUIAAEAAAAI0AAA 1 13278359039 13278381232 aaa
--//可以发现脏块还是写盘的.pad='aaa'.