使用BBED檢視資料檔案頭(block# 1)的簡單使用及查詢DBID/DB_NAME等資訊

還不算暈發表於2013-11-28
DBID及DB_NAME的檢視在最後。
進入BBED及初始設定如下:
[oracle@bys3 ~]$ cat par.bbd
blocksize=8192
listfile=bbedfile.txt
mode=edit
[oracle@bys3 ~]$ cat bbedfile.txt   --可以通過select file#,name from v$dbfile;  select file#,name from v$datafile;
1       /u01/oradata/bys3/system01.dbf  524288000
2       /u01/oradata/bys3/sysaux01.dbf  340787200
3       /u01/oradata/bys3/undotbs01.dbf 209715200
4       /u01/oradata/bys3/user01.dbf    52428800
[oracle@bys3 ~]$ bbed parfile=par.bbd
Password:    --輸入預設密碼  blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Thu Nov 28 10:14:54 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show all   --如下面所示

一、關於BBED使用命令show all中顯示DBA的計算:

BBED> show all        ---這命令顯示了當前的檔案號、BLOCK號,偏移號、COUNT數等資訊。需要提前SET FILE SET BLOCKSIZE SET BLOCK等
        FILE#           1
        BLOCK#          1
        OFFSET          0
        DBA             0x00400001 (4194305 1,1)             -------表示的是當前的FILE 1的BLOCK 1
        FILENAME        /u01/oradata/bys3/system01.dbf
        BIFILE          bifile.bbd
        LISTFILE        bbedfile.txt
        BLOCKSIZE       8192
        MODE            Edit
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           80
        COUNT           512
        LOGFILE         log.bbd
        SPOOL           No
計算如下:
DBA(data block address)===file#(10bit)+block#(22bit)==32bit
16進位制中兩個字元表示1bytes,
DBA=0x00400001====> 轉換為二進位制為:00000000 01000000  00000000 00000001
 file#=00000000 01 -----1號檔案
 block#=000000  00000000 00000001  -->號塊

所以對於DBA=0x00400001的計算如下:
示例計算DBA=0x00400001前四個字元對應的二進位制數值:--注意要兩個兩個的計算,0x表示是16進位制,不是具體的數值。
BYS@ bys3>select number_to_bit(to_number('00','xxxxxxx')) num from dual;      ---這裡的number_to_bit函式系統沒有,自己建的,見:http://blog.csdn.net/q947817003/article/details/14103801
NUM
--------------------
00000000
BYS@ bys3>select number_to_bit(to_number('40','xxxxxxx')) num from dual;
NUM
--------------------
01000000
所以前四個字元合起來對應的是二進位制的:0000000001000000
二進位制中一個字元佔用一個bit,故10bit就相當於前10個字元:00000000010:
使用二進位制轉換為10進位制的函式進行轉換:
BYS@ bys3>col num format 99999
BYS@ bys3>select bit_to_number('0000000001')  from dual;
BIT_TO_NUMBER('0000000001')
---------------------------
                          1
故DBA=0x00400001對應的資料檔案號是1
同樣的方法計算DBA=0x00400001對應的block#:也為1
BYS@ bys3>select bit_to_number('0000000000000001')  from dual;
BIT_TO_NUMBER('0000000000000001')
---------------------------------
                                1
##########################################################################

二、使用BBED的map命令檢視1號塊

BBED> map
 File: /u01/oradata/bys3/system01.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
 Data File Header
 struct kcvfh, 860 bytes                    @0       
 ub4 tailchk                                @8188    

解讀:塊號是:1,塊的DBA:0x00400001   即1號資料檔案的1號塊                               
 Data File Header表示是資料檔案 頭
  struct kcvfh, 860 bytes 表示大小為860個bytes,據說在不同版本大小不一樣
 @0  表示從第一個位元組開始
  ub4 tailchk  表示4個塊表示檢驗  ub4 --unsigned byte 4 無符號位元組
  @8188  從8188開始,8188 8189 8190 8191 這四個。
  ########################
  BBED> map /v     --可以看到更詳細的資訊
 File: /u01/oradata/bys3/system01.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
 Data File Header
 struct kcvfh, 860 bytes                    @0       
    struct kcvfhbfh, 20 bytes               @0       
    struct kcvfhhdr, 76 bytes               @20      
    ub4 kcvfhrdb                            @96      
    struct kcvfhcrs, 8 bytes                @100     
    ub4 kcvfhcrt                            @108     
    ub4 kcvfhrlc                            @112     
    struct kcvfhrls, 8 bytes                @116     
    ub4 kcvfhbti                            @124     
    struct kcvfhbsc, 8 bytes                @128     
    ub2 kcvfhbth                            @136     
    ub2 kcvfhsta                            @138     
    struct kcvfhckp, 36 bytes               @484     
    ub4 kcvfhcpc                            @140     
    ub4 kcvfhrts                            @144     
    ub4 kcvfhccc                            @148     
    struct kcvfhbcp, 36 bytes               @152     
    ub4 kcvfhbhz                            @312     
    struct kcvfhxcd, 16 bytes               @316     
    sword kcvfhtsn                          @332     
    ub2 kcvfhtln                            @336     
    text kcvfhtnm[30]                       @338     
    ub4 kcvfhrfn                            @368     
    struct kcvfhrfs, 8 bytes                @372     
    ub4 kcvfhrft                            @380     
    struct kcvfhafs, 8 bytes                @384     
    ub4 kcvfhbbc                            @392     
    ub4 kcvfhncb                            @396     
    ub4 kcvfhmcb                            @400     
    ub4 kcvfhlcb                            @404     
    ub4 kcvfhbcs                            @408     
    ub2 kcvfhofb                            @412     
    ub2 kcvfhnfb                            @414     
    ub4 kcvfhprc                            @416     
    struct kcvfhprs, 8 bytes                @420     
    struct kcvfhprfs, 8 bytes               @428     
    ub4 kcvfhtrt                            @444    
 ub4 tailchk                                @8188    
 
 簡單解讀:
 struct kcvfhbfh, 20 bytes               @0       
    struct kcvfhhdr, 76 bytes               @20      
    ub4 kcvfhrdb                            @96   
    比如以上三條:truct kcvfhbfh, 20 bytes 從0bite到19bite
    struct kcvfhhdr, 76 bytes               @20 從20到95bit
    如果想查詢kcvfhhdr這76bit具體資訊,可以使用命令:print kcvfhbfh

################

三、計算DBID及DB_NAME

BBED> print kcvfhhdr   --列印出更詳細資訊,接上面。
struct kcvfhhdr, 76 bytes                   @20      
   ub4 kccfhswv                             @20       0x00000000
   ub4 kccfhcvn                             @24       0x0b200000
   ub4 kccfhdbi                             @28       0xc82c8d97
   text kccfhdbn[0]                         @32      B
   text kccfhdbn[1]                         @33      Y
   text kccfhdbn[2]                         @34      S
   text kccfhdbn[3]                         @35      3
   text kccfhdbn[4]                         @36       
   text kccfhdbn[5]                         @37       
   text kccfhdbn[6]                         @38       
   text kccfhdbn[7]                         @39       
   ub4 kccfhcsq                             @40       0x000017bd
   ub4 kccfhfsz                             @44       0x0000fa00
   s_blkz kccfhbsz                          @48       0x00
   ub2 kccfhfno                             @52       0x0001
   ub2 kccfhtyp                             @54       0x0003
   ub4 kccfhacid                            @56       0x00000000
   ub4 kccfhcks                             @60       0x00000000
   text kccfhtag[0]                         @64       
   text kccfhtag[1]                         @65       
   text kccfhtag[2]                         @66       
   text kccfhtag[3]                         @67       
   text kccfhtag[4]                         @68       
   text kccfhtag[5]                         @69       
   text kccfhtag[6]                         @70       
   text kccfhtag[7]                         @71       
   text kccfhtag[8]                         @72       
   text kccfhtag[9]                         @73       
   text kccfhtag[10]                        @74       
   text kccfhtag[11]                        @75       
   text kccfhtag[12]                        @76       
   text kccfhtag[13]                        @77       
   text kccfhtag[14]                        @78       
   text kccfhtag[15]                        @79       
   text kccfhtag[16]                        @80       
   text kccfhtag[17]                        @81       
   text kccfhtag[18]                        @82       
   text kccfhtag[19]                        @83       
   text kccfhtag[20]                        @84       
   text kccfhtag[21]                        @85       
   text kccfhtag[22]                        @86       
   text kccfhtag[23]                        @87       
   text kccfhtag[24]                        @88       
   text kccfhtag[25]                        @89       
   text kccfhtag[26]                        @90       
   text kccfhtag[27]                        @91       
   text kccfhtag[28]                        @92       
   text kccfhtag[29]                        @93       
   text kccfhtag[30]                        @94       
   text kccfhtag[31]                        @95       
####################
DBID是對應的:ub4 kccfhdbi           @28       0xc82c8d97   kccfhdbi--這個名字最後三位也能聯想下DBID
可以計算出DBID:16進位制c82c8d97,轉換為10進位制數字:

BYS@ bys3>select name,dbid from v$database;
NAME            DBID
--------- ----------
BYS3      3358363031
BYS@ bys3>select to_number('c82c8d97','xxxxxxxxxxxxx') from dual;
TO_NUMBER('C82C8D97','XXXXXXXXXXXXX')
-------------------------------------
                           3358363031
這裡使用print kcvfhhdr中的16進位制數不需要顛倒位元組順序,因為BBED裡面已經轉換過了。
解釋:ub4 kccfhdbi                             @28       0xc82c8d97
   text kccfhdbn[0]                         @32      B
這表示ub4 kccfhdbi具體是在28,29.30.31這中個塊上,
對應的DUMP是在:=見圖3  16進位制值是978d2cc8,需要顛倒一下即為:c82c8d97


DB_NAME從下面幾個位元組可以看出--不需要計算了:--也可以看出,DB_NAME不能超過8個字元的原因了
  text kccfhdbn[0]                         @32      B
   text kccfhdbn[1]                         @33      Y
   text kccfhdbn[2]                         @34      S
   text kccfhdbn[3]                         @35      3
   text kccfhdbn[4]                         @36       
   text kccfhdbn[5]                         @37       
   text kccfhdbn[6]                         @38       
   text kccfhdbn[7]                         @39       
這裡演示一下計算的方法:    --kccfhdbn 看起來最後幾個字母也像是DBNAME
32BIT-38BIT,對應的圖3中的42595333 00000000
因為是字元型 ,不需要顛倒。
可以使用以下兩種函式轉換:
BYS@ bys3>select chr(to_number((substr(replace('42595333 00000000',' '),rownum*2-1,2)),'xxxxxxxxxxx')) from dba_objects where rownum<9;

CHR(
----
B
Y
S
3





8 rows selected.
上一句:dba_objects在這裡是只來顯示相應的虛欄位值了,保險起見應該選用一個行數大於8位元組的表或檢視就可以。
BYS@ bys3>select UTL_RAW.CAST_TO_VARCHAR2 ('4259533300000000') from dual;   ---注意要去掉兩組數之間空格
UTL_RAW.CAST_TO_VARCHAR2('4259533300000000')
----------------------------------------------------------------------------------------------------
BYS3

相關文章