bbed恢复updata数据实验

oracle修改表字段数据时,当修改数据数据长度不变时,oracle将在数据块行数据中直接修改数据。
如果修改数据长度变长或者变短,oracle将在数据块中新加入一行数据,故如若oracle数据库中数据
被修改,可以通过修改数据块row directory指针指向,找回旧值。

SQL> create table t1 (id int,name varchar2(10)) tablespace test;

Table created.

SQL> insert into t1 values(1,'AAAAA');

1 row created.

SQL> commit;

Commit complete.

SQL> select id,name,dbms_rowid.ROWID_RELATIVE_FNO(rowid) file#,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block# from t1;
ID NAME FILE# BLOCK#
---------- ------------------------------------------------------------ ------------- ----------
1 AAAAA 6 135

SQL> update t1 set name='BBBBBB' where name='AAAAA';

1 row updated.

SQL> commit;

Commit complete.

SQL> select id,name,dbms_rowid.ROWID_RELATIVE_FNO(rowid) file#,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block# from t1;

ID NAME FILE# BLOCK#
---------- ---------- ---------- ----------
1 BBBBBB 6 135
BBED> set file 6 block 135
FILE# 6
BLOCK# 135

BBED> dump /v offset 8000 count 193
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8000 to 8191 Dba:0x01800087
-------------------------------------------------------
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0000002c 020202c1 02064242 42424242 l ...,...BBBBB
2c000202 c1020541 41414141 0206c4d4 l ,...AAAA..

<16 bytes per line>

可以看到数据从块底部向上添加,旧值在最后,新值在旧值前。

找回旧值需要以下步骤:

1、将行指针信息的新值地址改为旧值地址;

2、更改事务槽;

3、有效空间设置。

BBED> p kdbr
sb2 kdbr[0] @118 8063

BBED> p *kdbr[0]
rowdata[0]
----------
ub1 rowdata[0] @8163 0x2c

BBED> x /rnccc
rowdata[0] @8163
----------
flag@8163: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8164: 0x02
cols@8165: 2

col 0[2] @8166: 1
col 1[6] @8169: BBBBBB

1、将行指针信息的新值地址改为旧值地址。需要计算出旧值的偏移量,每行16字节,8191-15=8176
2c000202 c1020541 41414141 0206c4d4
BBED> set offset 8176 count 111
OFFSET 8176
COUNT 111

BBED> dump /v
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8176 to 8191 Dba:0x01800087
-------------------------------------------------------
2c000202 c1020541 41414141 0206c4d4 l ,...AAAA..

SQL> select to_char(8176-100,'xxxxxx') from dual;
TO_CHAR
-------
1f8c

BBED> dump /v offset 118 count 16
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 118 to 133 Dba:0x01800087
-------------------------------------------------------
7f1f0000 00000000 00000000 00000000 l ................

BBED> m /x 8c offset 118
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 118 to 133 Dba:0x01800087
------------------------------------------------------------------------
8c1f0000 00000000 00000000 00000000

<32 bytes per line>

2、将新值的itl更改为00
BBED> dump /v offset 8000 count 199
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8000 to 8191 Dba:0x01800087
-------------------------------------------------------
00000000 00000000 00000000 00000000 l ................
0000002c 020202c1 02064242 42424242 l ...,...BBBBB
2c000202 c1020541 41414141 0206c4d4 l ,...AAAA..

3、将旧值的itl更改为01
BBED> set file 6 block 135
FILE# 6
BLOCK# 135

BBED> p *kdbr[0]
rowdata[13]
-----------
ub1 rowdata[13] @8176 0x2c

BBED> x /rnccc
rowdata[13] @8176
-----------
flag@8176: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8177: 0x00
cols@8178: 2

col 0[2] @8179: 1
col 1[5] @8182: AAAAA

BBED> m /x 00 offset 8164
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8164 to 8191 Dba:0x01800087
------------------------------------------------------------------------
000202c1 02064242 42424242 2c000202 c1020541 41414141 0206c4d4

<32 bytes per line>
BBED> sum apply
Check value for File 6, Block 135:
current = 0xeec2, required = 0xeec2
BBED> verify 验证时报错,row locked by non-existent transaction ,再改成02看看
DBVERIFY - Verification starting
FILE = /oradata/ORCLDBTEST/datafile/test01.dbf
BLOCK = 135

Block Checking: DBA = 25165959, Block Type = KTB-managed data block
data header at 0x7f2afe030264
kdbchk: row locked by non-existent transaction
table=0 slot=0
lockid=1 ktbbhitc=2
Block 135 failed with check code 6101

DBVERIFY - Verification complete

Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 1
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED


BBED> p *kdbr[0]
rowdata[13]
-----------
ub1 rowdata[13] @8176 0x2c

BBED> d
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8176 to 8191 Dba:0x01800087
------------------------------------------------------------------------
2c010202 c1020541 41414141 0206c4d4

<32 bytes per line>

BBED> x /rnc
rowdata[13] @8176
-----------
flag@8176: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8177: 0x01
cols@8178: 2

col 0[2] @8179: 1
col 1[5] @8182: AAAAA


BBED> m /x 02 offset 8177
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 8177 to 8191 Dba:0x01800087
------------------------------------------------------------------------
020202c1 02054141 41414102 06c4d4

<32 bytes per line>

BBED> sum apply
Check value for File 6, Block 135:
current = 0xedc2, required = 0xedc2

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/ORCLDBTEST/datafile/test01.dbf
BLOCK = 135

Block Checking: DBA = 25165959, Block Type = KTB-managed data block
data header at 0x9e6c64
kdbchk: the amount of space used is not equal to block size 所使用的空间量不等于块大小
used=32 fsc=0 avsp=8055 dtl=8088
Block 135 failed with check code 6110

DBVERIFY - Verification complete

Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 1
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED
改成02后,出现空间错误。

4、空间设置,更改kdbhavsp和kdbhtosp的值为dtl-used。
SQL> select to_char(8056,'XXXX') from dual;

TO_CH
-----
1F78
BBED> p kdbh
struct kdbh, 14 bytes @100
ub1 kdbhflag @100 0x00 (NONE)
sb1 kdbhntab @101 1
sb2 kdbhnrow @102 1
sb2 kdbhfrre @104 -1
sb2 kdbhfsbo @106 20
sb2 kdbhfseo @108 8063
sb2 kdbhavsp @110 8055
sb2 kdbhtosp @112 8055
BBED> set offset 110
OFFSET 110

BBED> d /v
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 110 to 125 Dba:0x01800087
-------------------------------------------------------
771f771f 00000100 8c1f0000 00000000 l w.w.............

<16 bytes per line>

BBED> m /x 781f
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 110 to 125 Dba:0x01800087
------------------------------------------------------------------------
781f771f 00000100 8c1f0000 00000000

<32 bytes per line>

BBED> sum apply
Check value for File 6, Block 135:
current = 0xedcd, required = 0xedcd

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/ORCLDBTEST/datafile/test01.dbf
BLOCK = 135

Block Checking: DBA = 25165959, Block Type = KTB-managed data block
data header at 0x9e6c64
kdbchk: avsp(8056) > tosp(8055)
Block 135 failed with check code 6128

DBVERIFY - Verification complete

Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 1
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED

BBED> set offset 112
OFFSET 112

BBED> m /x 781f
File: /oradata/ORCLDBTEST/datafile/test01.dbf (6)
Block: 135 Offsets: 112 to 127 Dba:0x01800087
------------------------------------------------------------------------
781f0000 01008c1f 00000000 00000000

<32 bytes per line>

BBED> sum apply
Check value for File 6, Block 135:
current = 0xedc2, required = 0xedc2

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/ORCLDBTEST/datafile/test01.dbf
BLOCK = 135


DBVERIFY - Verification complete

Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED

5、数据验证
SQL> select * from t1;

ID NAME
---------- ----------
1 BBBBBB

SQL> alter system flush buffer_cache;

System altered.

SQL> select * from t1;

ID NAME
---------- ----------
1 AAAAA

原文地址:https://www.cnblogs.com/historynote/p/13372640.html