标签归档:bbed

通过bbed查看数据块结构

BBED> map /v
 File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
 Block: 530                                   Dba:0x00800212
------------------------------------------------------------
 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                      @92      
    ub1 kdbhflag                            @92      
    b1 kdbhntab                             @93      
    b2 kdbhnrow                             @94      
    sb2 kdbhfrre                            @96      
    sb2 kdbhfsbo                            @98      
    sb2 kdbhfseo                            @100     
    b2 kdbhavsp                             @102     
    b2 kdbhtosp                             @104     

 struct kdbt[1], 4 bytes                    @106     
    b2 kdbtoffs                             @106     
    b2 kdbtnrow                             @108     

 sb2 kdbr[101]                              @110     

 ub1 freespace[4270]                        @312     

 ub1 rowdata[3606]                          @4582    

 ub4 tailchk                                @8188    


BBED> 


////////////////////////////////////////////////////////////////////////////////////////
//////////// Block Header Structure,  20 bytes//////////////////////////////////////////
BBED> p kcbh
struct kcbh, 20 bytes                       @0       
    ub1 type_kcbh                           @0    -- Block Type 
                                                  -- 01 - Undo segment header
                                                  -- 02 - Undo data block
                                                  -- 03 - Save undo header
                                                  -- 04 - Save undo data block
                                                  -- 05 - Data segment header  
                                                  -- 06 - Trans data, 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_kcbh                           @1    -- Block Format 1=Oracle7, 2=Oracle8+   
    ub1 spare1_kcbh                         @2    -- Not used, filler field   
    ub1 spare2_kcbh                         @3    -- Not used, filler field   
    ub4 rdba_kcbh                           @4    -- RDBA (4 bytes) - Relative Data Block Address   
    ub4 bas_kcbh                            @8    -- SCN Base (4 bytes)  
    ub2 wrp_kcbh                            @12   -- SCN Wrap (2 bytes)   
    ub1 seq_kcbh                            @14   -- Sequence Number, incremented for every change made to the block at the same SCN    
    ub1 flg_kcbh                            @15   -- Flag:   
                                                  -- 0x01 New Block
                                                  -- 0x02 Delayed Logging Chang advanced SCN/seq 
                                                  -- 0x04 Check value saved - block XOR's to Zero
                                                  -- 0x08 Temporary block
    ub2 chkval_kcbh                         @16   -- Optional block checksum (if DB_BLOCK_CHECKSUM=TRUE)   
    ub2 spare3_kcbh                         @18   -- Not used, filler field  
 
 /////////////////////////////////////////////////////////////////////////////////////////
/////////Transaction Fixed Header Structure, 72 Bytes////////////////////////////////////
BBED> p ktbbh
 struct ktbbh, 72 bytes                     @20      
    ub1 ktbbhtyp                            @20     -- Block type (1=DATA, 2=INDEX) 
    union ktbbhsid, 4 bytes                 @24     -- Segment/Object ID
    struct ktbbhcsc, 8 bytes                @28     -- SCN at last block cleanout 
    b2 ktbbhict                             @36     -- Number of ITL slots 
    ub1 ktbbhflg                            @38     -- 0=on the freelist 
    ub1 ktbbhfsl                            @39     -- ITL TX freelist slot 
    ub4 ktbbhfnx                            @40     -- DBA of next block on the freelist 
    struct ktbbhitl[2], 48 bytes            @44     -- ITL list index, each ITL takes up 24 bytes 

//////////////////////////////////////////////////////////////////////////////////////////
///////////////Data Header Structure, 14 bytes////////////////////////////////////////////
BBED> p kdbh
 struct kdbh, 14 bytes                      @100     
    ub1 kdbhflag                            @100    -- N=pctfree hit(clusters)
                                                    -- F=do not put on freelist
                                                    -- K=flushable cluster keys 
    b1 kdbhntab                             @101    -- Number of tables (>1 in clusters) 
    b2 kdbhnrow                             @102    -- Number of rows (2 bytes)
    sb2 kdbhfrre                            @104    -- First free row entry index; -1=you have to add one 
    sb2 kdbhfsbo                            @106    -- Freespace begin offset 
    sb2 kdbhfseo                            @108    -- Freespace end offset 
    b2 kdbhavsp                             @110    -- Available space in the block 
    b2 kdbhtosp                             @112    -- Total available space when all TXs commit 

////////////////////////////////////////////////////////////////////////////////////////
/////////////////////Table Directory Entry Structure, 4 bytes///////////////////////////
BBED> p kdbt
 struct kdbt[1], 4 bytes                    @114     
    b2 kdbtoffs                             @114     
    b2 kdbtnrow                             @116     

////////////////////////////////////////////////////////////////////////////////////////
////////////////// Row Directory ///////////////////////////////////////////////////////
BBED> p kdbr[100]
 sb2 kdbr[100]                                @310     


////////////////////////////////////////////////////////////////////////////////////////
///////////////// Free Space ///////////////////////////////////////////////////////////
BBED> p freespace[4269]
 ub1 freespace[4269]                        @4581     

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////Row Data//////////////////////////////////////////////////////////
BBED> p rowdata[3605]
ub1 rowdata[3605]                           @8187     0x00   
 
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////Block Tail Check, 4 bytes////////////////////////////////////////
BBED> p tailchk
ub4 tailchk                                 @8188     0x24500601  

说明事宜:
1、tailchk=Lower order two bytes of SCN Base(bas_kcbh) + Block Type(type_kcbh) + SCN Seq(seq_kcbh)
2、块的scn为:scn=wrp_kcbh+bas_kcbh
求scn语句:select to_char(to_number(‘scn’,’xxxxxxxxxx’),’999999999999′) from dual;
3、dba求文件号,块号为:

set serveroutput on
declare
   p_dba   VARCHAR2 (255) :='0x00800212';
   l_str   VARCHAR2 (255) DEFAULT NULL;
BEGIN
    l_str :=
         'datafile# is:'
      || DBMS_UTILITY.data_block_address_file (TO_NUMBER (LTRIM (p_dba, '0x'),'xxxxxxxx'))
      || chr(10)||'datablock is:'
      || DBMS_UTILITY.data_block_address_block (TO_NUMBER (LTRIM (p_dba, '0x'),'xxxxxxxx'));
   dbms_output.put_line(l_str);
END;
发表在 非常规恢复 | 标签为 | 评论关闭

bbed恢复删除数据

一、创建模拟环境
SQL> create table hr.xifenfei (id number,name varchar2(20)) tablespace xff;

Table created.

SQL> insert into hr.xifenfei values(1,’xifenfei’);

1 row created.

SQL> insert into hr.xifenfei values(2,’xff’);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from hr.xifenfei;

ID NAME
———- ——————–
1 xifenfei
2 xff

SQL> select rowid,
2 dbms_rowid.rowid_relative_fno(rowid)rel_fno,
3 dbms_rowid.rowid_block_number(rowid)blockno,
4 dbms_rowid.rowid_row_number(rowid) rowno
5 from hr.xifenfei;

ROWID REL_FNO BLOCKNO ROWNO
—————— ———- ———- ———-
AAAHy3AACAAAAISAAA 2 530 0
AAAHy3AACAAAAISAAB 2 530 1
查询file#,block,后面恢复要用

SQL> delete from hr.xifenfei where id=2;

1 row deleted.

SQL> commit;

Commit complete.

SQL> select * from hr.xifenfei;

ID NAME
———- ——————–
1 xifenfei

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

二、bbed恢复删除数据
[oracle@localhost ~]$ bbed parfile=/tmp/parfile.cnf
Password:

BBED: Release 2.0.0.0.0 – Limited Production on Mon Aug 22 01:52:52 2011

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

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

BBED> show all
FILE# 2
BLOCK# 1
OFFSET 0
DBA 0×00800001 (8388609 2,1)
FILENAME /opt/oracle/oradata/xifenfei/xff01.dbf
BIFILE bifile.bbd
LISTFILE /tmp/list
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No

BBED> set dba 2,530
DBA 0×00800212 (8389138 2,530)

BBED> find /c xff
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8170 to 8191 Dba:0×00800212
————————————————————————
7866662c 000202c1 02087869 66656e66 65690106 80e2

<32 bytes per line>

BBED> dump /v
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8170 to 8191 Dba:0×00800212
——————————————————-
7866662c 000202c1 02087869 66656e66 l xff,……xifenf
65690106 80e2 l ei….

<16 bytes per line>

BBED> dump /v offset 8160
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8160 to 8191 Dba:0×00800212
——————————————————-
0000003c 020202c1 03037866 662c0002 l …<......xff,.. 02c10208 78696665 6e666569 010680e2 l ....xifenfei.... <16 bytes per line>

BBED> dump /v offset 8164
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8164 to 8191 Dba:0×00800212
——————————————————-
020202c1 03037866 662c0002 02c10208 l ……xff,……
78696665 6e666569 010680e2 l xifenfei….

<16 bytes per line>

BBED> dump /v offset 8162
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8162 to 8191 Dba:0×00800212
——————————————————-
003c0202 02c10303 7866662c 000202c1 l .<......xff,.... 02087869 66656e66 65690106 80e2 l ..xifenfei.... <16 bytes per line>

BBED> dump /v offset 8163
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8163 to 8191 Dba:0×00800212
——————————————————-
3c020202 c1030378 66662c00 0202c102 l <......xff,..... 08786966 656e6665 69010680 e2 l .xifenfei.... <16 bytes per line>
通过尝试,推断出来3c的offset

BBED> modify /x 2c
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 530 Offsets: 8163 to 8191 Dba:0×00800212
————————————————————————
2c020202 c1030378 66662c00 0202c102 08786966 656e6665 69010680 e2

<32 bytes per line>
修改3c为2c

BBED> sum apply
Check value for File 2, Block 530:
current = 0xb1b9, required = 0xb1b9

三、核对结果
SQL> startup
ORACLE instance started.

Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from hr.xifenfei;

ID NAME
———- ——————–
1 xifenfei
2 xff

说明:
1)如果数据未删除:row flag的值为 32+8+4=44或者0x2c
2)如果数据被删除:row flag的值为 32+16+8+4=60或者0x3c

发表在 非常规恢复 | 标签为 | 评论关闭

bbed修改数据内容

1、创建模拟表
SQL> create table hr.b(id number,name varchar2(100)) tablespace xff;
Table created.
SQL> insert into hr.b values(1,’aaa’);
1 row created.
Commit complete.
2、查看数据位置
QL>  select   rowid,
2   dbms_rowid.rowid_relative_fno(rowid)rel_fno,
3   dbms_rowid.rowid_block_number(rowid)blockno,
4   dbms_rowid.rowid_row_number(rowid) rowno
5   from hr.b;
ROWID                 REL_FNO    BLOCKNO      ROWNO
—————— ———- ———- ———-
AAAHytAACAAAAIKAAA          2        522          0
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
虽然bbed 可以在db open 状态来进行修改,但是建议在做任何修改操作之前先shutdown db。 这样避免checkpoint 进程重写bbed 对block 的修改。 也避免oracle 在bbed 修改完成之前读block 或者申明block 为corrupt。
[oracle@localhost ~]$ bbed parfile=/tmp/parfile.cnf(/tmp/parfile.cnf文件见bbed破坏数据文件
Password:
BBED: Release 2.0.0.0.0 – Limited Production on Sat Aug 20 17:10:24 2011
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show all
FILE#           2
BLOCK#          1
OFFSET          0
DBA             0×00800001 (8388609 2,1)
FILENAME        /opt/oracle/oradata/xifenfei/xff01.dbf
BIFILE          bifile.bbd
LISTFILE        /tmp/list
BLOCKSIZE       8192
MODE            Edit
EDIT            Unrecoverable
IBASE           Dec
OBASE           Dec
WIDTH           80
COUNT           512
LOGFILE         log.bbd
SPOOL           No
3、设置dba位置
BBED> set dba 2,522
DBA             0x0080020a (8389130 2,522)
4、查询aaa位置
BBED> find /c aaa
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 522              Offsets: 8185 to 8191           Dba:0x0080020a
————————————————————————
61616101 067735
<32 bytes per line>
5、查看该位置内容
BBED> dump /v offset 8185
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 522     Offsets: 8185 to 8191  Dba:0x0080020a
——————————————————-
61616101 067735                     l aaa..w5
<16 bytes per line>
BBED> show all
FILE#           2
BLOCK#          522
OFFSET          8185
DBA             0x0080020a (8389130 2,522)
FILENAME        /opt/oracle/oradata/xifenfei/xff01.dbf
BIFILE          bifile.bbd
LISTFILE        /tmp/list
BLOCKSIZE       8192
MODE            Edit
EDIT            Unrecoverable
IBASE           Dec
OBASE           Dec
WIDTH           80
COUNT           512
LOGFILE         log.bbd
SPOOL           No
6、修改aaa为bbb
BBED> modify /c bbb
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 522              Offsets: 8185 to 8191           Dba:0x0080020a
————————————————————————
62626201 067735
<32 bytes per line>
BBED> dump /v
File: /opt/oracle/oradata/xifenfei/xff01.dbf (2)
Block: 522     Offsets: 8185 to 8191  Dba:0x0080020a
——————————————————-
62626201 067735                     l bbb..w5
<16 bytes per line>
7、应用变更
BBED> sum
Check value for File 2, Block 522:
current = 0xa285, required = 0xa286
此时 current checksum 是0xa285,requiredchecksum 是0xa286
BBED> sum apply
Check value for File 2, Block 522:
current = 0xa286, required = 0xa286
加上apply参数,使checksum一致。即之前的修改生效。
8、开启数据测试
SQL> startup
ORACLE instance started.
Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> col name for a20
SQL> select * from hr.b;
ID NAME
———- ——————–
1 bbb
发表在 非常规恢复 | 标签为 | 一条评论