程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 使用bbed編輯研究oracle數據塊結構

使用bbed編輯研究oracle數據塊結構

編輯:Oracle教程

使用bbed編輯研究oracle數據塊結構


bbed是隨oracle軟件發布的一款數據塊查看和編輯工具,作為一款內部工具,bbed的功能非常強大,但是如果使用不當可能給數據庫造成無法挽回的損失。因此。我們建議在使用bbed修改數據塊前備份被修改的數據文件,並且在成功修復數據塊後立即將數據庫數據導出,並新建數據庫。
  
編輯並使用bbed 

首次使用bbed前必須要經過鏈接編譯。編譯方法如下:

[oraten@yue lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
rm -f /home/app/oraten/product/10.2.0/db_1/rdbms/lib/bbed
gcc -o /home/app/oraten/product/10.2.0/db_1/rdbms/lib/bbed -L/home/app/oraten/product/10.2.0/db_1/rdbms/lib/ -L/home/app/oraten/product/10.2.0/db_1/lib/ -L/home/app/oraten/product/10.2.0/db_1/lib/stubs/  /home/app/oraten/product/10.2.0/db_1/lib/s0main.o /home/app/oraten/product/10.2.0/db_1/rdbms/lib/ssbbded.o /home/app/oraten/product/10.2.0/db_1/rdbms/lib/sbbdpt.o `cat /home/app/oraten/product/10.2.0/db_1/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 /home/app/oraten/product/10.2.0/db_1/rdbms/lib/defopt.o -ldbtools10 -lclntsh  `cat /home/app/oraten/product/10.2.0/db_1/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /home/app/oraten/product/10.2.0/db_1/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10  -lvsn10 -lcommon10 -lgeneric10 -lmm -lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /home/app/oraten/product/10.2.0/db_1/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /home/app/oraten/product/10.2.0/db_1/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10  -lvsn10 -lcommon10 -lgeneric10   -lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 -lclient10 -lnnetd10  -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10   `cat /home/app/oraten/product/10.2.0/db_1/lib/sysliblist` -Wl,-rpath,/home/app/oraten/product/10.2.0/db_1/lib -lm    `cat /home/app/oraten/product/10.2.0/db_1/lib/sysliblist` -ldl -lm   -L/home/app/oraten/product/10.2.0/db_1/lib

[oraten@yue lib]$ ll
-rwxr-xr-x 1 oraten dba  706118 9月  30 21:37 bbed
編譯完成後,就可以使用了,bbed默認密碼為:blockedit

Bbed提供了如下命令行參數:
[oraten@yue bin]$ ./bbed help=yes
PASSWORD - Required parameter
FILENAME - Database file name
BLOCKSIZE - Database block size
LISTFILE - List file name
MODE - [browse/edit]
SPOOL - Spool to logfile [no/yes]
CMDFILE - BBED command file name
LOGFILE - BBED log file name
PARFILE - Parameter file name
BIFILE - BBED before-image file name
REVERT - Rollback changes from BIFILE [no/yes]
SILENT - Hide banner [no/yes]
HELP - Show all valid parameters [no/yes]
istfile選項用listfile的路徑,listfile中存儲了需要編輯的數據文件的相關信息,如,
Listfile=/home/oracle/bbed/fileunix.log
[oracle@jode bbed] cat fileunix.log
1 /home/oracle/oradata/oraten/user01.dbf 216214400
2 /home/oracle/oradata/oraten/system01.dbf 335544320
注意,這裡的1 和 2 是在bbed中為各個文件指定的編號,與數據庫中的file#沒有任何關系,但是我們建議將兩者保持一致。我們可以通過如下語句來生成listfile的文件內容select file#||’ ‘||name||’ ‘||bytes from v$datafile;

bifile選項用來指定before image文件的位置。before image 文件中存放的是被bbed修改過的數據塊的前鏡像,該鏡像的取值始終是數據塊在bbed打開時的數據拷貝。例如,數據文件中某字段的初始內容為“abc”, 通過bbed多次修改後,該字段被修改成了“abc”=>”cde”=>”bbb”,那麼在bifile中存放的僅僅是“abc” 而不會存放後續的數據變化。
如果在bbed命令行選項中指定了revert=yes選項,那麼bbed會使用bifile中的內容來回滾上次bbed的所有修改,即相當於在上次的bbed修改過程中使用了revert命令。

bbed命令的使用方法

進入bbed後,可以通過help命令查看所有的bbed命令,如:
BBED: Release 2.0.0.0.0 - Limited Production on 星期三 10月 1 20:20:09 2014
Copyright (c) 1982, 2007, Oracle.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> help all
SET DBA [ dba | file#, block# ]
SET FILENAME 'filename'
SET FILE file#
SET BLOCK [+/-]block#
SET OFFSET [ [+/-]byte offset | symbol | *symbol ]
SET BLOCKSIZE bytes
SET LIST[FILE] 'filename'
SET WIDTH character_count
SET COUNT bytes_to_display
SET IBASE [ HEX | OCT | DEC ]
SET OBASE [ HEX | OCT | DEC ]
SET MODE  [ BROWSE | EDIT ]
SET SPOOL [ Y | N ]
SHOW [ <SET parameter> | ALL ]
INFO
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
</Nuf>:
N - a number which specifies a repeat count.
u - a letter which specifies a unit size:
  b - b1, ub1 (byte)
  h - b2, ub2 (half-word)
  w - b4, ub4(word)
  r - Oracle table/index row
f - a letter which specifies a display format:
  x - hexadecimal
  d - decimal
  u - unsigned decimal
  o - octal
  c - character (native)
  n - Oracle number
  t - Oracle date
  i - Oracle rowid
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
MODIFY[/x|d|u|o|c] numeric/character string
      [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
ASSIGN[/x|d|u|o] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ <bbed command> | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
set dba [dba | file#,block#]

用來設置需要查看和編輯的數據塊,該命令有兩種使用方法,一種是直接指定數據塊的dba,另一中是指定file#( listfile中的文件號)和block#。

BBED> set dba 5,1
  	DBA            	0x01400001 (20971521 5,1)
  
  BBED> find /c TBS3
   File: /home/app/oraten/oradata/oraten/tbs301.dbf (5)
   Block: 1                Offsets:  338 to  849           Dba:0x01400001
  ------------------------------------------------------------------------
   54425333 00000000 00000000 00000000 00000000 00000000 00000000 00000500 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00001bd5 3c33a9ec 05000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 0000a82a 0b000000 00008e05 4c330100 
   00001300 0000fd00 00001000 00000200 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000d00 0d000d00 01000000 00000000 
   00000000 00000200 40010000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
  
   <32 bytes per line>
  
  BBED> set dba 0x01400001
  	DBA            	0x01400001 (20971521 5,1)
  
  BBED> find /c TBS3
   File: /home/app/oraten/oradata/oraten/tbs301.dbf (5)
   Block: 1                Offsets:  338 to  849           Dba:0x01400001
  ------------------------------------------------------------------------
   54425333 00000000 00000000 00000000 00000000 00000000 00000000 00000500 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00001bd5 3c33a9ec 05000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 0000a82a 0b000000 00008e05 4c330100 
   00001300 0000fd00 00001000 00000200 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000d00 0d000d00 01000000 00000000 
   00000000 00000200 40010000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
   00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
  
   <32 bytes per line>
  我們知道,在bbed中file#指的是listfile文件中各個數據文件的變化,並不是數據字典中各個數據文件的file#,那麼bbed是如何根據DBA來定位文件和數據塊的那?原來在每個數據文件的頭部的kccfhfno位置存儲著該文件在數據庫中的文件編號。如
  
BBED> p kcvfhhdr 
  struct kcvfhhdr, 76 bytes                   @20      
     ub4 kccfhswv                             @20       0x00000000
     ub4 kccfhcvn                             @24       0x0a200500
     ub4 kccfhdbi                             @28       0xda0e3a18
     text kccfhdbn[0]                         @32      O
     text kccfhdbn[1]                         @33      R
     text kccfhdbn[2]                         @34      A
     text kccfhdbn[3]                         @35      T
     text kccfhdbn[4]                         @36      E
     text kccfhdbn[5]                         @37      N
     text kccfhdbn[6]                         @38       
     text kccfhdbn[7]                         @39       
     ub4 kccfhcsq                             @40       0x000006f3
     ub4 kccfhfsz                             @44       0x00000500
     s_blkz kccfhbsz                          @48       0x00
     ub2 kccfhfno                             @52       0x0005
     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    
  

Set file name

設定當前編輯的數據文件,文件名稱用單引號括起來
BBED> set filename '/home/app/oraten/oradata/oraten/tbs101.dbf'
	FILENAME       	/home/app/oraten/oradata/oraten/tbs101.dbf

Set width

設定當前的屏幕寬度,如果沒有設定,默認為80,例如
BBED> set width 120
	WIDTH          	120

Set ibase

設置與bbed交互的數字格式(僅僅是交互格式),默認為10進制,也可以設置為其他,如hex 等
BBED> set ibase hex
	IBASE          	Hex

BBED> set block B
	BLOCK#         	11

BBED> show block
	BLOCK#         	11

Set obase

設置bbed的輸出格式,默認是10,可以設置為其他,如 hex
BBED> set block 11
	BLOCK#         	0x0000000b

BBED> set obase dec
	OBASE          	Dec

BBED> set block 11
	BLOCK#         	11
Set mode
設置bbed工作模式(查看模式、編輯模式)

SET SPOOL
尚未實現

Map
顯示當前數據塊的數據布局信息,使用/v選項可以獲取詳細信息。如
BBED> map
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20                                    Dba:0x01400014
------------------------------------------------------------
 KTB Data Block (Table/Cluster)


 struct kcbh, 20 bytes                      @0       


 struct ktbbh, 72 bytes                     @20      


 struct kdbh, 14 bytes                      @100     


 struct kdbt[1], 4 bytes                    @114     


 sb2 kdbr[2]                                @118     


 ub1 freespace[8040]                        @122     


 ub1 rowdata[26]                            @8162    


 ub4 tailchk                                @8188    

BBED> map /v
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20                                    Dba:0x01400014
------------------------------------------------------------
 KTB Data Block (Table/Cluster)


 struct kcbh, 20 bytes                      @0       
    ub1 type_kcbh                           @0       
    ub1 frmt_kcbh                           @1       
    ub1 spare1_kcbh                         @2       
    ub1 spare2_kcbh                         @3       
    ub4 rdba_kcbh                           @4       
    ub4 bas_kcbh                            @8       
    ub2 wrp_kcbh                            @12      
    ub1 seq_kcbh                            @14      
    ub1 flg_kcbh                            @15      
    ub2 chkval_kcbh                         @16      
    ub2 spare3_kcbh                         @18      


 struct ktbbh, 72 bytes                     @20      
    ub1 ktbbhtyp                            @20      
    union ktbbhsid, 4 bytes                 @24      
    struct ktbbhcsc, 8 bytes                @28      
    b2 ktbbhict                             @36      
    ub1 ktbbhflg                            @38      
    ub1 ktbbhfsl                            @39      
    ub4 ktbbhfnx                            @40      
    struct ktbbhitl[2], 48 bytes            @44      


 struct kdbh, 14 bytes                      @100     
    ub1 kdbhflag                            @100     
    b1 kdbhntab                             @101     
    b2 kdbhnrow                             @102     
    sb2 kdbhfrre                            @104     
    sb2 kdbhfsbo                            @106     
    sb2 kdbhfseo                            @108     
    b2 kdbhavsp                             @110     
    b2 kdbhtosp                             @112     


 struct kdbt[1], 4 bytes                    @114     
    b2 kdbtoffs                             @114     
    b2 kdbtnrow                             @116     


 sb2 kdbr[2]                                @118     


 ub1 freespace[8040]                        @122     


 ub1 rowdata[26]                            @8162    


 ub4 tailchk                                @8188 
下面來詳細解釋各個區間的數據內容,

Structure /element

description

Struct kcbh,20 bytes

Block header structure

---- ub1 type_kcbh

Block type

01

Undo segment header

02

Undo data block

03

Save undo header

04

Save undo data bock

05

Data segment header(temp,index,data and so on)

06

KTB managed data block(with ITL)

07

Temp table data block(no ITL)

08

Sort Key

09

Sort Run

10

Segment free list block

11

Data file header

 

---ub1 frmt_kcb

Block format 1=oracle 7,2 =oracle 8+

---ub1 spare1_kcbh

Not used

---ub1 spare2_kchb

Not used

---ub4 rdba_kcbh

Rdba- relative data block address

---ub4 bas_kcbh

Scn base

----ub2 wrp_kcbh

Scn wrap

----ub1 seq_kcbh

Sequence number,incremented for every change made to the block at the sam scn

----ub1 flg_kcbh

Flag:

Ox01 new block

0x02 delayed logging change advanced scn/seq

0x04 check value saved - block XOR’s to zero

0x08 temporary block

----ub2 chkval_kcbh

Optional block checksun(if db_block_checksum=true)

-----ub2 spare3_kcbh

Not used

Struct ktbbh ,72 bytes

Transaction fixed header structure

------ub1 ktbbhtyp

Block type(1=data,2=index)

------union ktbbhsid,4 bytes

Segment/object id

------struct ktbbhcsc,8 bytes

Scn at last block cleanout

------b2 ktbbhict

Number of itl slots

------ub1 ktbbhflg

0=on the freelist

------ub1 ktbbhfsl

Itl tx freelist slot

------ub4 ktbbhfnx

Dba of next block on freelist

------struct ktbbhitl[2],48 bytes

Itl list index

Struct kdbh,14 bytes

Data header structure

---ub1 kdbhflag

N=pctfree hit(clusters);F=do not put on freelist;K=flushable cluster keys

---b1 kdbhntab

Number of tables(>1 in clusters)

----b2 kdbhnrow

Number of rows( 記錄刪除後,並不會立即在數據塊中清除記錄數據,僅僅是將記錄標記為已刪除,等真正需要已刪除記錄的空間時才會真正刪除記錄,此時kdbhnrow 的值才會發送變化)

-----sb2 kdbhfree

First free row entry index;-1=you have to add one

---sb2 kdbhfsbo

Freespace begin offset

----sb2 kdbhfseo

Freespace end offset

----b2 kdbhavsp

Available space in the block

-----b2 kdbhtosp

Total available space when all TXs commit

Struct kdbt[1],4 bytes

Table directory entry structure

---b2 kdbtoffs

 

----b2 kdbtnrow

 

Sb2 kdbr[1](1指記錄的數量)

Row directory, kdbr中的每條記錄存儲的是數據記錄在數據塊中的偏移量,該偏移量是針對kdbh計算的

Ub1 freespace[8030]

Free space

Ub1 rowdata[38](38指記錄占據字節數量)

Row data

Ub4 tailchkdocs

The tial of an oracle 8+ block is a concatenationof the lower order two bytes of the scn base,the block type and the scn sequence number.although the tail check value is generated form three components, oracle treats the final value as a single unsigned integer stored as a word(4 bytes). On litter-endian architecture machines,which include intel the value will stores as low-order byte first..e,g A tail check of 0x97280602 stored on an intl machine would be wirtten to disk as 02062897.


Dump
Dump命令將數據塊在內存中的數據按照地址由低到高的順序以十六進制形式展現到屏幕上,通過/v選項,可以顯示更為詳細的內容。可以直接指定需要dump的數據塊,也可以dump當前的數據塊。Dump命令展現的數據量是由count選項指定的,默認值是512bytes。
BBED> show all
	FILE#          	5
	BLOCK#         	20
	OFFSET         	0
	DBA            	0x01400014 (20971540 5,20)
	FILENAME       	/home/app/oraten/oradata/oraten/tbs101.dbf
	BIFILE         	bifile.bbd
	LISTFILE       	/home/oraten/filelist.txt
	BLOCKSIZE      	8192
	MODE           	Edit
	EDIT           	Unrecoverable
	IBASE          	Dec
	OBASE          	Dec
	WIDTH          	80
	COUNT          	512
	LOGFILE        	log.bbd
	SPOOL          	No


BBED> find /c nnn
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20               Offsets: 8169 to 8191           Dba:0x01400014
------------------------------------------------------------------------
 6e6e6e2c 000202c1 0301622c 000202c1 02016101 06aee7 


 <32 bytes per line>


BBED> dump
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20               Offsets: 8169 to 8191           Dba:0x01400014
------------------------------------------------------------------------
 6e6e6e2c 000202c1 0301622c 000202c1 02016101 06aee7 


 <32 bytes per line>


BBED> dump /v
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20      Offsets: 8169 to 8191  Dba:0x01400014
-------------------------------------------------------
 6e6e6e2c 000202c1 0301622c 000202c1 l nnn,......b,....
 02016101 06aee7                     l ..a....


 <16 bytes per line>
PRINT
Print命令比較復雜一些,在某種程度上print命令和map命令是異曲同工的。只是map命令顯示的是整個數據塊的結構,而print顯示的是當前offset位置下的數據結構,print命令側重於以raw格式顯示數據塊的數據結構(顯示格式並不是在內存中的存儲格式,不受大小尾的影響,例如以p tailchk命令和dump命令顯示的tailchk內容在字節順序上是不一樣的),而下面的example命令側重於顯示數據內容。我們可以向print提供兩類參數,一類是offset,另一類是數據塊內數據結構的名稱。當我們指定offset時,print命令顯示當前offset下的數據結構,如
BBED> show all
	FILE#          	5
	BLOCK#         	20
	OFFSET         	0
	DBA            	0x01400014 (20971540 5,20)
	FILENAME       	/home/app/oraten/oradata/oraten/tbs101.dbf
	BIFILE         	bifile.bbd
	LISTFILE       	/home/oraten/filelist.txt
	BLOCKSIZE      	8192
	MODE           	Edit
	EDIT           	Unrecoverable
	IBASE          	Dec
	OBASE          	Dec
	WIDTH          	80
	COUNT          	512
	LOGFILE        	log.bbd
	SPOOL          	No


BBED> p
kcbh.type_kcbh
--------------
ub1 type_kcbh                               @0        0x06

我們也可以在數據結構名稱前使用*符合來打印數據結構指針所指向的offset,如
BBED> p kdbr (這是第二類用法,即指定數據結構名稱)
sb2 kdbr[0]                                 @118      8062
sb2 kdbr[1]                                 @120      8072


BBED> print *kdbr[0]
rowdata[0]
----------
ub1 rowdata[0]                              @8162     0x2c

Print 命令默認使用16進制顯示數據,當然我們也可以指定bbed使用其他格式顯示數據,如下所示:
Switch Display formatt
/x Hex
/d Signed decimal
/u Unsigned decimal
/o Octal
/c Character
/n Oracle number
/t Oracle date
/i Oracle rowid
BBED> print
rowdata[7]
----------
ub1 rowdata[7]                              @8169     0x6e


BBED> print /c
rowdata[7]
----------
ub1 rowdata[7]                              @8169    n


BBED> print /n
rowdata[7]
----------
ub1 rowdata[7]                              @8169     110
我們也可以指定數據結構的名稱,來打印顯示該結構的詳細信息,如
BBED> p kcbh
struct kcbh, 20 bytes                       @0       
   ub1 type_kcbh                            @0        0x06
   ub1 frmt_kcbh                            @1        0xa2
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x01400014
   ub4 bas_kcbh                             @8        0x0006e7ae
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0xcc8e
   ub2 spare3_kcbh                          @18       0x0000

EXAMPLE

Example命令用來顯示數據塊中的數據,可以直接指定dba offset,也可以直接使用當前的dba offset。我們可以指定example按照不同的格式顯示數據塊數據,其中比較有意義的是我們可以使用example來查看數據記錄。如下所示:
Switch Display format
/b B1 .ub1(byte)
/h B2,ub2 (half-word)
/w B4,ub4 (word)
/l B8,ub8 (long)(was b4/ub4 in oracle 7)
/r Oracle table/index row

數據表ta的結構和數據如下
SQL> desc scott.ta
 Name					   Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID						    NUMBER
 NAME						    VARCHAR2(10)
 RIQI						    DATE


SQL> select * from scott.ta;


	ID NAME       RIQI
---------- ---------- -------------------
	 1 nnn	      2014-10-07 13:19:00
	 2 b	      2014-10-07 13:19:00
	 3 ss	      2014-10-07 14:00:15
	 4 lll	      2014-10-07 14:03:09
使用bbed查看數據塊數據:
BBED> map  
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 21                                    Dba:0x01400015
------------------------------------------------------------
 KTB Data Block (Table/Cluster)


 struct kcbh, 20 bytes                      @0       


 struct ktbbh, 72 bytes                     @20      


 struct kdbh, 14 bytes                      @100     


 struct kdbt[1], 4 bytes                    @114     


 sb2 kdbr[2]                                @118     


 ub1 freespace[8031]                        @122     


 ub1 rowdata[35]                            @8153    


 ub4 tailchk                                @8188    
BBED> p *kdbr[0]
rowdata[18]
-----------
ub1 rowdata[18]                             @8171     0x2c


BBED> x /rnct
rowdata[18]                                 @8171    
-----------
flag@8171: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8172: 0x01
cols@8173:    3


col    0[2] @8174: 3 
col    1[2] @8177: ss
col    2[7] @8180: 2014-10-07 14:00:15 

BBED> x /b
rowdata[18]                                 @8171    
-----------
 0x2c 


BBED> x /h
rowdata[18]                                 @8171    
-----------
 0x012c 


BBED> x /w
rowdata[18]                                 @8171    
-----------
 0x0203012c 


BBED> x /l
rowdata[18]                                 @8171    
-----------
 0x0203012c 


BBED> set offset 8153
	OFFSET         	8153


BBED> x /2rnct
rowdata[0]                                  @8153    
----------
flag@8153: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8154: 0x02
cols@8155:    3


col    0[2] @8156: 4 
col    1[3] @8159: lll
col    2[7] @8163: 2014-10-07 14:03:09 


rowdata[18]                                 @8171    
-----------
flag@8171: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8172: 0x01
cols@8173:    3


col    0[2] @8174: 3 
col    1[2] @8177: ss
col    2[7] @8180: 2014-10-07 14:00:15 
Find

Find命令用來在數據塊中查找數據,可以按照十進制、十六進制、八進制和字符格式進行查找,如

Switch Datatype
/x Hexadecimal
/d Decimal
/u Unsigned decimal
/o Octal
/c Character(native)
注意:目前不支持數字和日期類型的查找方式
BBED> find /c n
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20               Offsets: 8151 to 8191           Dba:0x01400014
------------------------------------------------------------------------
 6e6e6e07 78720a07 0e14012c 000202c1 02036e6e 6e2c0002 02c10301 622c0002 
 02c10201 61010694 51 


 <32 bytes per line>


BBED> f
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20               Offsets: 8152 to 8191           Dba:0x01400014
------------------------------------------------------------------------
 6e6e0778 720a070e 14012c00 0202c102 036e6e6e 2c000202 c1030162 2c000202 
 c1020161 01069451 


 <32 bytes per line>


BBED> f
 File: /home/app/oraten/oradata/oraten/tbs101.dbf (5)
 Block: 20               Offsets: 8153 to 8191           Dba:0x01400014
------------------------------------------------------------------------
 6e077872 0a070e14 012c0002 02c10203 6e6e6e2c 000202c1 0301622c 000202c1 
 02016101 069451 


 <32 bytes per line>
Copy
數據塊拷貝命令,注意:使用該命令會使bifile被清空。
BBED> copy dba 1,16 to dba 3,11

Modify
編輯命令,使用方式於find命令相似,不再重復

Assign
Assign命令用來為數據結構賦值,使用方法如下:
BBED> help assign
ASSIGN[/x|d|u|o] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]
使用過程中,我們可以省略源或者目標,省略部分被當前offset所在的數據結構代替。在使用assign命令時,雖然我們可以指定offset,但實際上被賦值的是offset所在位置的數據結構,如:
BBED> print kcbh
struct kcbh, 20 bytes                       @0       
   ub1 type_kcbh                            @0        0x06
   ub1 frmt_kcbh                            @1        0x02
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x01400014
   ub4 bas_kcbh                             @8        0x00075194
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0xae67
   ub2 spare3_kcbh                          @18       0x0000


BBED> assign 9=1
ub4 bas_kcbh                                @8        0x00000001


BBED> print  kcbh
struct kcbh, 20 bytes                       @0       
   ub1 type_kcbh                            @0        0x06
   ub1 frmt_kcbh                            @1        0x02
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x01400014
   ub4 bas_kcbh                             @8        0x00000001
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0xae67
   ub2 spare3_kcbh                          @18       0x0000


BBED> assign 9=0x00075194
ub4 bas_kcbh                                @8        0x00075194
Sum
Sum命令被用來檢測和設置數據塊的校驗值,
BBED> help sum
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]

Revert
Revert命令用來將數據文件恢復到bbed剛打開時的狀態。

Undo
Undo命令用來撤銷上次的編輯操作,如果再次undo又會重做上次的編輯。

Verify
用來對數據塊的完整性進行驗證,類似dbv工具。

Corrupt
用來標示數據塊為物理損壞

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved