ITPub博客

首页 > 数据库 > Oracle > [20210304]bbed的assign命令.txt

[20210304]bbed的assign命令.txt

原创 Oracle 作者:lfree 时间:2021-03-04 10:34:21 0 删除 编辑

[20210304]bbed的assign命令.txt

--//曾经写过一篇bbed的assign命令,实际上使用它使得使用bbed变得更加简单快捷,不用考虑大小头问题,比modify修改更加方便快捷。
--//昨天偶然发现assign还可以不写offset完成同样的功能以及assign存在的一些弊端。我通过一个删除记录并恢复部分记录来说明问题:

1.环境:
SCOTT@book> @ 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

SCOTT@book> create table deptx as select * from dept;
Table created.

SCOTT@book> select rowid,deptx.* from deptx;
ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAWHpAAEAAAAKrAAA         10 ACCOUNTING     NEW YORK
AAAWHpAAEAAAAKrAAB         20 RESEARCH       DALLAS
AAAWHpAAEAAAAKrAAC         30 SALES          CHICAGO
AAAWHpAAEAAAAKrAAD         40 OPERATIONS     BOSTON

SCOTT@book> @ rowid AAAWHpAAEAAAAKrAAA
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     90601          4        683          0  0x10002AB           4,683                alter system dump datafile 4 block 683 ;

SCOTT@book> delete deptx where deptno in (20,40);
2 rows deleted.

SCOTT@book> commit ;
Commit complete.

SCOTT@book> alter system checkpoint ;
System altered.

2.尝试恢复:
--//删除后表示从0x2c->0x3c,注意不包括出现行迁移的情况。

$ echo -e "set dba 4,683\nset offset 0\n$(seq 4 | xargs -IQ echo -e 'find /x 3c curr \nset offset +2')" | rlbbed
BBED: Release 2.0.0.0.0 - Limited Production on Thu Mar 4 09:29:29 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> set count 64
        COUNT           64
BBED> set width 160
        WIDTH           160
BBED>   DBA             0x010002ab (16777899 4,683)
BBED>   OFFSET          0
BBED>  File: /mnt/ramdisk/book/users01.dbf (4)
 Block: 683                                                  Offsets:  146 to  209                                               Dba:0x010002ab
------------------------------------------------------------------------------------------------------------------------------------------------
 3c1f241f 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 <64 bytes per line>

BBED>   OFFSET          148

BBED>  File: /mnt/ramdisk/book/users01.dbf (4)
 Block: 683                                                  Offsets: 8096 to 8159                                               Dba:0x010002ab
------------------------------------------------------------------------------------------------------------------------------------------------
 3c020302 c1290a4f 50455241 54494f4e 5306424f 53544f4e 2c000302 c11f0553 414c4553 07434849 4341474f 3c020302 c1150852 45534541 52434806 44414c4c

 <64 bytes per line>

BBED>   OFFSET          8098

BBED>  File: /mnt/ramdisk/book/users01.dbf (4)
 Block: 683                                                  Offsets: 8140 to 8191                                               Dba:0x010002ab
------------------------------------------------------------------------------------------------------------------------------------------------
 3c020302 c1150852 45534541 52434806 44414c4c 41532c00 0302c10b 0a414343 4f554e54 494e4708 4e455720 594f524b 03068098

 <64 bytes per line>

BBED>   OFFSET          8142
BBED> BBED-00212: search string not found
BBED>   OFFSET          8144
--//可以发现删除表示偏移在8096,8140。
--//正常执行如下:
assign dba  4,683 offset 8096=0x2c
assign dba  4,683 offset 8140=0x2c

--//可以去掉offset,执行如下,这是我不小心写错才发现可以这样操作:
assign dba  4,683 8096=0x2c
assign dba  4,683 8140=0x2c

BBED> assign dba 4,683  8096=0x2c
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub1 rowdata[0]                              @8096     0x2c
--//你可以发现修改的位置还是offset 8096的位置。

BBED> x  /rncc dba 4,683 offset 8096
rowdata[0]                                  @8096
----------
flag@8096: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8097: 0x02
cols@8098:    3
col    0[2] @8099: 40
col   1[10] @8102: OPERATIONS
col    2[6] @8113: BOSTON

BBED> sum apply  dba 4,683
Check value for File 4, Block 683:
current = 0xe1d0, required = 0xe1d0

BBED> verify dba 4,683
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 683

Block Checking: DBA = 16777899, Block Type = KTB-managed data block
data header at 0xf54e7c
kdbchk: the amount of space used is not equal to block size
        used=98 fsc=42 avsp=7946 dtl=8064
Block 683 failed with check code 6110

--//我仅仅恢复1条,理论将修改fsc,这样比较麻烦。
--//dtl - used -fsc = avsp.
--//8064-98-42 = 7924

BBED> set dba 4,683
        DBA             0x010002ab (16777899 4,683)

BBED> p kdbh.kdbhavsp
sb2 kdbhavsp                                @134      7946
--//偏移在134. 占2个字节。

BBED> assign 134=7924;
sb2 kdbhavsp                                @134      7924

--//我还可以写成:
BBED> assign 135=7925;
sb2 kdbhavsp                                @134      7925

--//bbed的assign会通过偏移计算正确的位置,对齐赋值。当然我并不建议这样操作,最佳的方式应该执行如下:

BBED> assign kdbh.kdbhavsp=7924;
sb2 kdbhavsp                                @134      7924


BBED> sum apply  dba 4,683
Check value for File 4, Block 683:
current = 0xe02e, required = 0xe02e

BBED> verify dba 4,683
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 683

Block Checking: DBA = 16777899, Block Type = KTB-managed data block
data header at 0xf76e7c
kdbchk: space available on commit is incorrect
        tosp=7992 fsc=42 stb=2 avsp=7924
Block 683 failed with check code 6111

--//avsp+stb+fsc=tosp.
--//7924+2+42 = 7968
BBED> p kdbh.kdbhtosp
sb2 kdbhtosp                                @136      7992

BBED> assign 136=7968
sb2 kdbhtosp                                @136      7968

BBED> sum apply  dba 4,683
Check value for File 4, Block 683:
current = 0xe036, required = 0xe036

BBED> verify dba 4,683
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 683

3.验证看看。
SCOTT@book> alter system flush buffer_cache ;
System altered.

SCOTT@book> select rowid,deptx.* from deptx;
ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAWHpAAEAAAAKrAAA         10 ACCOUNTING     NEW YORK
AAAWHpAAEAAAAKrAAC         30 SALES          CHICAGO
AAAWHpAAEAAAAKrAAD         40 OPERATIONS     BOSTON
--//恢复正确。

4.继续尝试:
--//不过我发现assign也存在1个缺点
BBED> p dba 4,683 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        0x010002ab
   ub4 bas_kcbh                             @8        0x17689880
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ub2 wrp_kcbh                             @12       0x0003
   ub1 seq_kcbh                             @14       0x03
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0xe036
   ub2 spare3_kcbh                          @18       0x0000

--//尝试修改kcbh.bas_kcbh.
BBED> assign 8=0x77689880
ub4 bas_kcbh                                @8        0x77689880
--//0x77689880 = 2003343488

BBED> assign 8=2003343488
ub4 bas_kcbh                                @8        0x77689880
--//10,16 进制一样没有问题。
--//但是这样修改存在缺点:
BBED> assign 8=0x87689880
BBED-00206: out of range offset (87689880)
--//第1位不能大于0x8.
--//0x87689880 = 2271778944

BBED> assign 8=2271778944
BBED-00207: invalid offset specifier (2271778944)

BBED> assign 8=0xa7689880
BBED-00207: invalid offset specifier (a7689880)
--//0xa7689880 = 2808649856

BBED> assign 8=2808649856
BBED-00207: invalid offset specifier (2808649856)
--//注意两个提示无一样。
--//也就是assign无法修改4字节内容时,第1位不能是大于0x8.

BBED> assign kcbh.bas_kcbh=0x87689880
BBED-00206: out of range offset (87689880)

BBED> assign kcbh.bas_kcbh=0xa7689880
BBED-00207: invalid offset specifier (a7689880)

--//如果你的修改遇到这样的情况就比较麻烦了,感觉这个是bbed的bug。

BBED> assign kcbh.bas_kcbh=0x17689880
ub4 bas_kcbh                                @8        0x17689880

BBED> assign offset 8 = 0xa7
ub4 bas_kcbh                                @8        0x000000a7
--//你可以发现这个时候assign将偏移转换为一个整体,只能使用modify修改,实际上modify一样有这个问题存在。
--//注意modify修改要考虑大小头问题。
--//我以前的测试:
BBED> modify /x 8affffff dba 101,1 offset 40
BBED-00209: invalid number (8affffff)
------------
--//还原:
BBED> assign kcbh.bas_kcbh=0x17689880
ub4 bas_kcbh                                @8        0x17689880

5.总结:
--//总之知道bbed assign与modify这些缺点,才能更好的利用这个工具。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2761047/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2894
  • 访问量
    6672993