[20150522]bbed與資料塊檢查和.txt

lfree發表於2015-05-22

[20150522]bbed與資料塊檢查和.txt

--我現在基本拿bbed學習,基本是拿bbed檢視,而使用bvi修改資料.我感覺這種方便1寫.
--實際上使用bbed的好處就是修改資料塊檢查和不一致,而使用bbed修改很簡單僅僅需要執行sum apply就ok了.

--對比dbv與bbed確定檢查和位置.

1.建立測試環境:
SCOTT@test> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx            10.2.0.4.0     Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

SCOTT@test> select rowid,deptx.* from deptx;
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAO1FAAGAAAAAKAAA           10 ACCOUNTING     NEW YORK
AAAO1FAAGAAAAAKAAB           20 RESEARCH       DALLAS
AAAO1FAAGAAAAAKAAC           30 SALES          CHICAGO
AAAO1FAAGAAAAAKAAD           40 OPERATIONS     BOSTON

SCOTT@test> @ &r/lookup_rowid AAAO1FAAGAAAAAKAAA
      OBJECT         FILE        BLOCK          ROW DBA                  TEXT
------------ ------------ ------------ ------------ -------------------- ----------------------------------------
       60741            6           10            0 6,10                 alter system dump datafile 6 block 10 ;

SCOTT@test> alter system checkpoint;
System altered.

SCOTT@test> alter system flush buffer_cache;
System altered.

$  bvi -b 81920 -s 8192 /mnt/ramdisk/test/mssm01.dbf
--修改.
YORK=>york
--說明:bvi修改很簡單選擇R,替換裡面的K->k. 前面的引數-b 表示開始偏移量,10*8192=81920. -s表示顯示大小.
--這樣就人為的破壞了檢查和.

BBED> set dba 6,10
        DBA             0x0180000a (25165834 6,10)

BBED> sum;
Check value for File 6, Block 10:
current = 0x893e, required = 0x893e

--出現一個奇怪的情況,檢查和是正確的.說明checksum的演算法很簡單,這樣修改竟然會重合!!!!
$  bvi -b 81920 -s 8192 /mnt/ramdisk/test/mssm01.dbf
--修改.
YORK=>aaaa

BBED> set dba 6,10
        DBA             0x0180000a (25165834 6,10)

BBED> sum
Check value for File 6, Block 10:
current = 0x893e, required = 0x8d35

2.開始測試:
SCOTT@test> alter system flush buffer_cache;
System altered.

SCOTT@test> select rowid,deptx.* from deptx;
select rowid,deptx.* from deptx
                          *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 10)
ORA-01110: data file 6: '/mnt/ramdisk/test/mssm01.dbf'

--我所關注兩個: 1.檢查和位置 2.如果沒有bbed,如何確定檢查和.
$  dbv file=/mnt/ramdisk/test/mssm01.dbf
DBVERIFY: Release 10.2.0.4.0 - Production on Fri May 22 11:33:49 2015
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
DBVERIFY - Verification starting : FILE = /mnt/ramdisk/test/mssm01.dbf
Page 10 is marked corrupt
Corrupt block relative dba: 0x0180000a (file 6, block 10)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x0180000a
last change scn: 0x0002.f445ace5 seq: 0x2 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0xace50602
check value in block header: 0x893e
computed block checksum: 0x40b

DBVERIFY - Verification complete

Total Pages Examined         : 2048
Total Pages Processed (Data) : 1
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 10
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 2036
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Highest block SCN            : 4098132609 (2.4098132609)

3.從以上觀察:
--資料塊記錄的檢查和是0x893e,目前真正正確的是0x8d35
--而dbv提示的是:
check value in block header: 0x893e
computed block checksum: 0x40b
--很明顯塊checksum不是 0x40b,有時候覺得oracle的設計不人性化,既然知道不對,為什麼不給出當前正確的值,而是給出一個computed block checksum: 0x40b.

-- 當然演算法很簡單,異或就可以了.
893e => 1000 1001 0011 1101
40b => 0000 0100 0000 0110
----------------------------
        1000 1101 0011 1011 => 8d35

--查詢塊:可以發現偏移是16,注意查詢是倒過來 3e89.使用bbed也可以確定.

BBED> print chkval_kcbh
ub2 chkval_kcbh                             @16       0x893e


BBED> sum apply
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
Check value for File 6, Block 10:
current = 0x8d35, required = 0x8d35

BBED> print chkval_kcbh
ub2 chkval_kcbh                             @16       0x8d35

SCOTT@test> alter system flush buffer_cache;
System altered.

SCOTT@test> select rowid,deptx.* from deptx;
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAO1FAAGAAAAAKAAA           10 ACCOUNTING     NEW aaaa
AAAO1FAAGAAAAAKAAB           20 RESEARCH       DALLAS
AAAO1FAAGAAAAAKAAC           30 SALES          CHICAGO
AAAO1FAAGAAAAAKAAD           40 OPERATIONS     BOSTON

--可以知道使用dbv確定也很簡單,做一個異或就ok了.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1666781/,如需轉載,請註明出處,否則將追究法律責任。

相關文章