[20190226]测试使用bbed恢复索引.txt

--//上午做tab$删除恢复测试时发现,tab$的索引i_tab1很小.可以尝试使用bbed解决这个问题.
--//首先在普通表上做一个测试看看.

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 empy as select * from emp ;
Table created.

SCOTT@book> create index i_empy_empno on empy(empno);
Index created.

SCOTT@book> select rowid,empy.* from empy where rownum=1;
ROWID                   EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
------------------ ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
AAAWPZAAEAAAAILAAA       7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

SCOTT@book> @ rowid AAAWPZAAEAAAAILAAA
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     91097          4        523          0  0x100020B           4,523                alter system dump datafile 4 block 523 ;

SCOTT@book> select HEADER_FILE,HEADER_BLOCK,segment_name from dba_segments where owner=user and segment_name=‘I_EMPY_EMPNO‘;
HEADER_FILE HEADER_BLOCK SEGMENT_NAME
----------- ------------ --------------------
          4          530 I_EMPY_EMPNO
--//索引的roor节点在dba=4,531.

2.删除记录看看:

SCOTT@book> delete from empy where empno not in (7369);
13 rows deleted.

SCOTT@book> commit ;
Commit complete.

--//仅仅保留1条.并且这条是empy表最小的empno号.

SCOTT@book> alter system checkpoint ;
System altered.

3.先恢复表:
BBED> set dba 4,523
        DBA             0x0100020b (16777739 4,523)

BBED> x /rnccntnnn *kdbr[0]
rowdata[529]                                @8150
------------
flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8151: 0x00
cols@8152:    8

col    0[3] @8153: 7369
col    1[5] @8157: SMITH
col    2[5] @8163: CLERK
col    3[3] @8169: 7902
col    4[7] @8173: 1980-12-17 00:00:00
col    5[2] @8181: 800
col    6[0] @8184: *NULL*
col    7[2] @8185: 20
--//这条记录保留.

BBED> x /rnccntnnn *kdbr[1]
rowdata[486]                                @8107
------------
flag@8107: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH)
lock@8108: 0x02
cols@8109:    0

--//执行如下生成bbed脚本:
$ seq 1 13 | xargs -I{} echo ‘x /rnccntnnn dba 4,523 *kdbr[{}]‘ | rlbbed | grep -B1 "^lock@" | grep "^flag@.*=0x3c" | cut -d: -f1| cut -d"@" -f2 | xargs -I{} echo assign dba 4,523 offset {}=0x2c
assign dba 4,523 offset 8107=0x2c
assign dba 4,523 offset 8064=0x2c
assign dba 4,523 offset 8023=0x2c
assign dba 4,523 offset 7978=0x2c
assign dba 4,523 offset 7937=0x2c
assign dba 4,523 offset 7896=0x2c
assign dba 4,523 offset 7856=0x2c
assign dba 4,523 offset 7818=0x2c
assign dba 4,523 offset 7775=0x2c
assign dba 4,523 offset 7737=0x2c
assign dba 4,523 offset 7699=0x2c
assign dba 4,523 offset 7660=0x2c
assign dba 4,523 offset 7621=0x2c

--//执行如上脚本,去除删除标识.

BBED> sum apply
Check value for File 4, Block 523:
current = 0x8c05, required = 0x8c05

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 523

Block Checking: DBA = 16777739, Block Type = KTB-managed data block
data header at 0x7f6d56b9427c
kdbchk: the amount of space used is not equal to block size
        used=613 fsc=503 avsp=7451 dtl=8064
Block 523 failed with check code 6110

--//dtl-used-fsc = avsp

BBED> p ktbbh.ktbbhitl[1]._ktbitun._ktbitfsc
sb2 _ktbitfsc                               @86       503

BBED> assign ktbbh.ktbbhitl[1]._ktbitun._ktbitfsc=0
sb2 _ktbitfsc                               @86       0

BBED> sum apply
Check value for File 4, Block 523:
current = 0x8df2, required = 0x8df2

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 523

Block Checking: DBA = 16777739, Block Type = KTB-managed data block
data header at 0xe9427c
kdbchk: space available on commit is incorrect
        tosp=7980 fsc=0 stb=0 avsp=7451
Block 523 failed with check code 6111

--//avsp+fsc+stb=tops.

BBED> assign kdbh.kdbhtosp=kdbh.kdbhavsp
sb2 kdbhtosp                                @136      7451

BBED> sum apply
Check value for File 4, Block 523:
current = 0x8fc5, required = 0x8fc5

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 523

--//OK, 现在对应块已经修复.

SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> select * from empy ;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1600        300         30
      7521 WARD       SALESMAN        7698 1981-02-22 00:00:00       1250        500         30
      7566 JONES      MANAGER         7839 1981-04-02 00:00:00       2975                    20
      7654 MARTIN     SALESMAN        7698 1981-09-28 00:00:00       1250       1400         30
      7698 BLAKE      MANAGER         7839 1981-05-01 00:00:00       2850                    30
      7782 CLARK      MANAGER         7839 1981-06-09 00:00:00       2450                    10
      7788 SCOTT      ANALYST         7566 1987-04-19 00:00:00       3000                    20
      7839 KING       PRESIDENT            1981-11-17 00:00:00       5000                    10
      7844 TURNER     SALESMAN        7698 1981-09-08 00:00:00       1500          0         30
      7876 ADAMS      CLERK           7788 1987-05-23 00:00:00       1100                    20
      7900 JAMES      CLERK           7698 1981-12-03 00:00:00        950                    30
      7902 FORD       ANALYST         7566 1981-12-03 00:00:00       3000                    20
      7934 MILLER     CLERK           7782 1982-01-23 00:00:00       1300                    10
14 rows selected.

SCOTT@book> select * from empy where empno in(7499,7369);
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

--//可以发现走索引仅仅找到1条.

SCOTT@book> ANALYZE TABLE empy VALIDATE STRUCTURE CASCADE;
ANALYZE TABLE empy VALIDATE STRUCTURE CASCADE
*
ERROR at line 1:
ORA-01499: table/index cross reference failure - see trace file
--//一般普通表的索引不用恢复,根据表重建就ok了.但是对于sys.tab$的索引不行,这也是做这个测试的原因.

4.恢复索引看看.
BBED> set dba 4,531
        DBA             0x01000213 (16777747 4,531)

BBED> p kd_off
sb2 kd_off[0]                               @132      8032
sb2 kd_off[1]                               @134      0
sb2 kd_off[2]                               @136      8019
sb2 kd_off[3]                               @138      8006
sb2 kd_off[4]                               @140      7993
sb2 kd_off[5]                               @142      7980
sb2 kd_off[6]                               @144      7967
sb2 kd_off[7]                               @146      7954
sb2 kd_off[8]                               @148      7941
sb2 kd_off[9]                               @150      7928
sb2 kd_off[10]                              @152      7915
sb2 kd_off[11]                              @154      7902
sb2 kd_off[12]                              @156      7889
sb2 kd_off[13]                              @158      7877

--//可以发现bbed查看索引有问题,kd_off[0],kd_off[1]看到的偏移是不对的.实际上kd_off偏移从136开始kd_off[2].

BBED> x /rnx *kd_off[2]
rowdata[172]                                @8119
------------
flag@8119:     0x00 (NONE)
lock@8120:     0x00
data key:
col    0[3] @8122: 7369
col    1[6] @8126:  0x01  0x00  0x02  0x0b  0x00  0x00

--//这个表的第一条记录(最小值),我没有删除.empno=7369.

BBED> x /rnx *kd_off[3]
rowdata[159]                                @8106
------------
flag@8106:     0x01 (KDXRDEL)
lock@8107:     0x02
data key:
col    0[3] @8109: 7499
col    1[6] @8113:  0x01  0x00  0x02  0x0b  0x00  0x01
--//对比删除与不删除的可以看出.flag不同,删除的flag=0x01.

$ seq 2 13 | xargs -I{} echo ‘x /rnx dba 4,531 *kd_off[{}]‘ | rlbbed | grep -B1 "^lock@.*:*0x02$" | grep "flag@.*0x01" | cut -d: -f1 | cut -d@ -f2 |xargs -I{} echo assign dba 4,531 offset {}=0x00
assign dba 4,531 offset 8106=0x00
assign dba 4,531 offset 8093=0x00
assign dba 4,531 offset 8080=0x00
assign dba 4,531 offset 8067=0x00
assign dba 4,531 offset 8054=0x00
assign dba 4,531 offset 8041=0x00
assign dba 4,531 offset 8028=0x00
assign dba 4,531 offset 8015=0x00
assign dba 4,531 offset 8002=0x00
assign dba 4,531 offset 7989=0x00
assign dba 4,531 offset 7977=0x00
--//仅仅修改11条,还有2条需要修改标识.

BBED> dump  offset 160 count 4
 File: /mnt/ramdisk/book/users01.dbf (4)
 Block: 531             Offsets:  160 to  163   Dba:0x01000213
---------------------------------------------------------------
 b81eab1e

<64 bytes per line>

--// 说明: kd_off[13]的偏移量记录在偏移158,下面2条记录的偏移记录从160算起.
--// b81e 颠倒过来就是  1eb8=7864 , 记录相对偏移从kdxle算起(当前是100), 7864+100 = 7964
--// ab1e 颠倒过来就是  1eab=7851 , 记录相对偏移从kdxle算起(当前是100), 7851+100  = 7951

BBED> x /rnx offset 7964
rowdata[17]                                 @7964
-----------
flag@7964:     0x01 (KDXRDEL)
lock@7965:     0x02
data key:
col    0[3] @7967: 7902
col    1[6] @7971:  0x01  0x00  0x02  0x0b  0x00  0x0c

BBED> x /rnx offset 7951
rowdata[4]                                  @7951
----------
flag@7951:     0x01 (KDXRDEL)
lock@7952:     0x02
data key:
col    0[3] @7954: 7934
col    1[6] @7958:  0x01  0x00  0x02  0x0b  0x00  0x0d

--//也就是要补充执行如下:
assign dba 4,531 offset 7964=0x00
assign dba 4,531 offset 7951=0x00

--//执行如下脚本:
--//补充如果你仔细看就可以发现键值是按照行目录排序的.如果有记录插入,oracle是通过2分法定位插入行目录的位置,
--//你可以发现后面的偏移不是有序的,这也就是索引的块内无序,块间有序,但是如果索引分裂,oracle会重新排序.

assign dba 4,531 offset 8106=0x00
assign dba 4,531 offset 8093=0x00
assign dba 4,531 offset 8080=0x00
assign dba 4,531 offset 8067=0x00
assign dba 4,531 offset 8054=0x00
assign dba 4,531 offset 8041=0x00
assign dba 4,531 offset 8028=0x00
assign dba 4,531 offset 8015=0x00
assign dba 4,531 offset 8002=0x00
assign dba 4,531 offset 7989=0x00
assign dba 4,531 offset 7977=0x00
assign dba 4,531 offset 7964=0x00
assign dba 4,531 offset 7951=0x00

BBED> sum apply
Check value for File 4, Block 531:
current = 0x91b5, required = 0x91b5

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 531

Block Checking: DBA = 16777747, Block Type = KTB-managed data block
**** actual free space = 7593 < kdxcoavs = 7787
**** actual rows marked deleted = 0 != kdxlende = 13
---- end index block validation
Block 531 failed with check code 6401

BBED> p kdxle.kdxlende
sb2 kdxlende                                @118      13

BBED> assign  kdxle.kdxlende=0
sb2 kdxlende                                @118      0

BBED> sum apply
Check value for File 4, Block 531:
current = 0x91b8, required = 0x91b8

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 531

Block Checking: DBA = 16777747, Block Type = KTB-managed data block
**** actual free space = 7593 < kdxcoavs = 7787
---- end index block validation
Block 531 failed with check code 6401

BBED> p kdxle.kdxlexco.kdxcoavs
sb2 kdxcoavs                                @114      7787

BBED> assign kdxle.kdxlexco.kdxcoavs=7593
sb2 kdxcoavs                                @114      7593

BBED> sum apply
Check value for File 4, Block 531:
current = 0x927a, required = 0x927a

BBED> verify
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/users01.dbf
BLOCK = 531

--//OK,现在完全修复了.

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

SCOTT@book> select * from empy where empno in(7499,7369);
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1600        300         30

--//通过索引能定位行记录.
SCOTT@book> ANALYZE TABLE empy VALIDATE STRUCTURE CASCADE;
Table analyzed.

--//ANALYZE TABLE empy VALIDATE STRUCTURE CASCADE;一切ok,证明修复没有任何问题.

总结:
--//使用bbed修复索引有点繁琐,主要kd_off记录的偏移不对,从kd_off[2]算起.并且遗漏2条键值记录.

原文地址:https://www.cnblogs.com/lfree/p/10438177.html

时间: 2024-08-02 00:41:02

[20190226]测试使用bbed恢复索引.txt的相关文章

[20190531]ORA-600 kokasgi1故障模拟与恢复(后续).txt

--//http://blog.itpub.net/267265/viewspace-2646340/=>[20190531]ORA-600 kokasgi1故障模拟与恢复.txt--//后续有一些恢复没做,补充测试看看. --//先更正链接http://blog.itpub.net/267265/viewspace-2646340/的一些错误:--//1.前面做坏块恢复时,少写了执行步骤:.BBED> assign kcbh.seq_kcbh = 0x01--//2.使用system用户登录

恢复索引时碰到的六个问题(莫非编程行业的坑特别多?)

恢复索引时碰到的六个问题:1. 切记不要使用外部sqlite工具打开观察数据库情况,看的时候舒服,调试的时候却忘了关闭它,导致无论怎么关闭数据库都不行(rename文件总是失败) 2. 解压缩到当前目录,哪一个目录要写清楚(默认可能会解压缩到可执行文件的目录下),但是解压缩后的文件名不用写,因为压缩包里的文件是什么名字就是什么名字 3. 必须要等m_database对象消失了,才能移除这个数据库 http://doc.qt.io/qt-5/qsqldatabase.html#removeData

RMAN 0级恢复测试---RAC+ASM恢复到单机

最近做了一次RMAN 0 级恢复测试,测试模拟了生产数据库发生灾难性故障,只剩下rman全备份的备份片,利用备份的spfile.控制文件.数据文件.归档日志恢复数据的过程. 首先说一下环境,网上很多文章都是互相粘贴,并不一定适用于你的测试环境.我这次测试的生产环境是2个节点的RAC,存储使用了ASM去管理,操作系统为RHEL6.4,Oracle11.2.0.4,rman每日全备份,使用全备份去恢复数据.恢复的机器选择了1台PC机,安装RHEL6.4,操作系统.Oracle版本均和服务器一致,区别

利用BBED恢复UPDATE修改前的值

实验过程如下: 1.创建表guo_test1 [email protected]> create table guoyJoe_t1(id int,name varchar2(10)); Table created. [email protected]> insert into guoyJoe_t1 values(1,'guoyJoe'); 1 row created. [email protected]> insert into guoyJoe_t1 values(1,'tom'); 1

Lucene 4.9索引txt文件

暂时只是跑起来了,不知道是否正确,困了,睡觉了,改天再弄.搜索那块是分页的,也没仔细弄... 参考着 http://blog.csdn.net/kingskyleader/article/details/8444739 在data下放了三个txt... S:\lucene\data\永生.txt S:\lucene\data\1.txt S:\lucene\data\2.txt 永生是本小说,汉语的应该没有英文. 1.txt 内容: hello 2.txt 内容: hi hello  哈哈 程序

利用BBED恢复数据文件头

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/31018075 @@@@@@@利用BBED模拟损坏5文件1号块(文件头) BBED> copy file 4 block 4 to file 5 block 1 File: /u01/app/oracle/oradata/PROD/tp01.dbf (5) Block: 1 Offsets: 0 to 19 Dba:0x01400001 --------------------------

【Oracle】使用bbed恢复update的数据

使用bbed不仅仅可以找回已经delete的数据还可以恢复update的数据,当然过程要比恢复delete的数据复杂一些. 实验过程如下: [email protected]>create table bbed_test(x int,y varchar2(20)); Table created. [email protected]>insert into bbed_test values(1,'BADLY9'); 1 row created. [email protected]>inse

lucene3.0+版本中文分词测试+搜索结果+创建索引测试

lucene3.0+版本中文分词测试+搜索结果+创建索引测试 import java.io.File; import java.io.IOException; import java.io.StringReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.

利用 BBED 恢复非归档模式下 OFFLINE 数据文件

今天来模拟一个非归档模式下恢复OFFLINE数据文件的场景,主要有2种情况: 一种是在线日志没有被覆盖,另一种是在线日志被覆盖. 第一种情况比较简单,数据库自身就能处理,而第二种情况稍显复杂,但也并不难,下面开始整个实验过程: 一.在线日志没有被覆盖的场景 --切换数据库到非归档模式 SQL> archive log list Database log mode       Archive Mode Automatic archival       Enabled Archive destina