欢迎投稿

今日深度:

使用bbed编辑研究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
用来标示数据块为物理损坏

www.htsjk.Com true http://www.htsjk.com/oracle/22412.html NewsArticle 使用bbed编辑研究oracle数据块结构 bbed是随oracle软件发布的一款数据块查看和编辑工具,作为一款内部工具,bbed的功能非常强大,但是如果使用不当可能给数据库造成无法挽回的损失。因...
评论暂时关闭