11 ORA-8102:Index Corruption解析

[oracle@DSI ~]$ oerr ora 8102
08102, 00000, "index key not found, obj# %s, file %s, block %s (%s)"
// *Cause: Internal error: possible inconsistency in index
// *Action: Send trace file to your customer support representative, along
// with information on reproducing the error
常见于索引键值与表上存的值不一致,可能是ORACLE的bug,也可能是由于硬件I/O错误所引起!
硬件或者I/O子系统由于丢失写 Lost Write造成块的逻辑上讹误,当一个Lost Io发生,包含对key的修改或者没有写入到ORACLE数据文件上,
这即可能发生在表块上也可能发生在索引块上。

ORA-8102:Index Corruption解析(Cont…)
创建索引-->更新数据块-->1号文件52号块-->con$
-->更新索引块-->1号文件xxx块-->con$
--二者不相等就会报错8102

--人为构建8102错误

SQL> conn test/***
Connected.
SQL> create table yhq_test(id int,name varchar2(100)); Table created. SQL> begin
for i in 1 .. 5000 loop
insert into yhq_test values(i,'yhq'||i);
commit;
end loop;
end;
/ 2 3 4 5 6 7 PL/SQL procedure successfully completed. SQL> select user_id,username from dba_users where username='TEST'; USER_ID USERNAME
---------- ------------------------------
83 TEST SQL> alter table yhq_test add primary key(id); Table altered. SQL> select CONSTRAINT_NAME from dba_constraints where table_name='YHQ_TEST'; CONSTRAINT_NAME
------------------------------
SYS_C0011762

--查看索引文件块号

SQL> conn / as sysdba
Connected.
SQL> select dbms_rowid.rowid_relative_fno(rowid) file#,dbms_rowid.rowid_block_number(rowid) block#,
dbms_rowid.rowid_row_number(rowid) row#
from con$
where name='_NEXT_CONSTRAINT'; 2 3 4 FILE# BLOCK# ROW#
---------- ---------- ----------
1 289 12
SQL> select /*+ FULL(t1) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11763 SQL> select /*+ index(t1 I_CON2) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11763
--这两个值相等是正常的
SQL> select * from bootstrap$ where obj#=52;

     LINE#     OBJ#
---------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
52 52
CREATE UNIQUE INDEX I_CON2 ON CON$(CON#) PCTFREE 10 INITRANS 2 MAXTRANS 255 STOR
AGE ( INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 O
BJNO 52 EXTENTS (FILE 1 BLOCK 464))

--用bbed查看并修改

BBED> set file 1 block 289
FILE# 1
BLOCK# 289
BBED> map /v
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 289 Dba:0x00400121 BBED> p *kdbr[]
rowdata[]
----------
ub1 rowdata[] @920 0x2c BBED> x /rccnn
rowdata[] @920
----------
flag@920: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@921: 0x01
cols@922: 4 col 0[] @923: .
col 1[] @925: _NEXT_CONSTRAINT
col 2[] @942: 11763 ##这个11763和上面查到的一致
col 3[] @947: 0

--11763 修改为11764

--十进制转换
SQL> select dump(11763,16) from dual; DUMP(11763,16)
-----------------------
Typ=2 Len=4: c3,2,12,40 SQL> select dump(11764,16) from dual; DUMP(11764,16)
-----------------------
Typ=2 Len=4: c3,2,12,41
SQL> alter system flush buffer_cache;
System altered.

--修改并查看

BBED> d /v offset 942 count 32
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 289 Offsets: 942 to 973 Dba:0x00400121
-------------------------------------------------------
04c30212 4001802c 00040180 105f4e45 l .n.@..,....._NE
58545f43 4f4e5354 5241494e 5403c302 l XT_CONSTRAINT.n <16 bytes per line>
BBED> modify /x 41 offset 946
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 289 Offsets: 946 to 977 Dba:0x00400121
------------------------------------------------------------------------
4101802c 00040180 105f4e45 58545f43 4f4e5354 5241494e 5403c302 1201802c <32 bytes per line> BBED> sum apply
Check value for File 1, Block 289:
current = 0xf014, required = 0xf014 BBED> d /v offset 942 count 32
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 289 Offsets: 942 to 973 Dba:0x00400121
-------------------------------------------------------
04c30212 4101802c 00040180 105f4e45 l .n.A..,....._NE
58545f43 4f4e5354 5241494e 5403c302 l XT_CONSTRAINT.n <16 bytes per line>
BBED> p *kdbr[]
rowdata[]
----------
ub1 rowdata[] @920 0x2c BBED> x /rccnn
rowdata[] @920
----------
flag@920: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@921: 0x01
cols@922: 4 col 0[] @923: .
col 1[] @925: _NEXT_CONSTRAINT
col 2[] @942: 11764 ###修改为11763+1
col 3[] @947: 0

--重启数据库,查看,并重建索引

--重启数据库
SQL> startup;
ORACLE instance started. Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 297795584 bytes
Redo Buffers 6791168 bytes
Database mounted.
Database opened.
SQL>
SQL>
SQL> select /*+ FULL(t1) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11764 SQL> select /*+ index(t1 I_CON2) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11763
--两个值不一样
SQL> conn test/test
Connected.
SQL> alter table yhq_test drop primary key; Table altered. SQL> alter table yhq_test add primary key(id);
alter table yhq_test add primary key(id)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-08102: index key not found, obj# 52, file 1, block 78302 (2)

--查看错误日志

[oracle@DSI ~]$ tail -n 30 /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_14127.trc
REDO RECORD - Thread:1 RBA: 0x000026.00004836.0010 LEN: 0x0074 VLD: 0x05
SCN: 0x0000.009c8d44 SUBSCN: 1 07/10/2019 09:52:46
(LWN RBA: 0x000026.00004836.0010 LEN: 0003 NST: 0001 SCN: 0x0000.009c8d44)
CHANGE #1 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:18.3 ENC:0
Reuse redo entry
Object reuse: tsn=5 objd=88123 REDO RECORD - Thread:1 RBA: 0x000026.00004839.018c LEN: 0x0048 VLD: 0x01
SCN: 0x0000.009c8d47 SUBSCN: 3 07/10/2019 09:52:46
(LWN RBA: 0x000026.00004839.0010 LEN: 0001 NST: 0001 SCN: 0x0000.009c8d47)
CHANGE #1 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:18.3 ENC:0
Reuse redo entry
Range reuse: tsn=5 base=20984144 nblks=8
END OF DUMP REDO
KQRCMT: Write failed with error=604 po=0x885dde30 cid=12
diagnostics : cid=12 hash=28d84319 flag=2a
[oracle@DSI ~]$ tail -n 30 /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log

--dump索引块--存放索引信息

SQL> alter system dump datafile 1 block 78302;
System altered.
[oracle@DSI ~]$ vim /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_14148.trc Block header dump: 0x004131de
Object id on Block? Y
seg/obj: 0x34 csc: 0x00.9c8d42 itc: 3 flg: O typ: 2 - INDEX
fsl: 0 fnx: 0x4131df ver: 0x01
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0006.002.00005b68 0x00c07d95.01df.01 CB-- 0 scn 0x0000.0096102a
0x02 0x0009.018.00005c53 0x00c00102.01f8.11 C--- 0 scn 0x0000.009c713e
0x03 0x0008.003.00007a05 0x00c01bfd.0225.01 --U- 1 fsc 0x000f.009c8d43
Leaf block dump
===============
header address 139990239005300=0x7f520477ca74
kdxcolev 0
KDXCOLEV Flags = - - -
kdxcolok 0
kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y
kdxconco 1
kdxcosdc 1
kdxconro 359
kdxcofbo 754=0x2f2
kdxcofeo 1942=0x796
kdxcoavs 2591
kdxlespl 0
kdxlende 1
kdxlenxt 0=0x0
kdxleprv 4272605=0x4131dd
kdxledsz 6
kdxlebksz 8008 row#357[] flag: ---D--, lock: 3, len=13, data:(6): 00 41 57 47 00 61
col 0; len 4; (4): c3 02 12 3f
row#[] flag: ------, lock: 0, len=13, data:(6): 00 40 01 21 00 0c ---1955 相对位置
col ; len ; (): c3
----- end of leaf block dump -----
End dump data blocks tsn: 0 file#: 1 minblk 78302 maxblk 78302

--使用bbed查看并修改

BBED> set file 1 block 78302;
FILE# 1
BLOCK# 78302
BBED> p ktbbh SQL> select utl_raw.cast_to_number(replace('c3 02 12 40',' ')) from dual; --转成成十进制 UTL_RAW.CAST_TO_NUMBER(REPLACE('C3021240',''))
----------------------------------------------
11763 BBED> d /v offset 1955 count 32 ------注意1955的来源
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 78302 Offsets: 1955 to 1986 Dba:0x004131de
-------------------------------------------------------
00000041 574600e8 04c30211 19010000 l ...AWF.毃......
40012100 0c04c302 111a0000 00415746 l @.!...n.....AWF <16 bytes per line> SQL> select 1955+20+24+24*3+8 from dual; --索引加124 1955+20+24+24*3+8
-----------------
2079 BBED> d /v offset 2079 count 32
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 78302 Offsets: 2079 to 2110 Dba:0x004131de
-------------------------------------------------------
04c30212 40000000 41574700 6004c302 l .n.@...AWG.`.n
123e0100 00400121 000c04c3 02123f00 l .>...@.!...n.?. <16 bytes per line>
BBED> modify /x 41 offset 2083
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
Block: 78302 Offsets: 2083 to 2114 Dba:0x004131de
------------------------------------------------------------------------
41000000 41574700 6004c302 123e0100 00400121 000c04c3 02123f00 00004157 <32 bytes per line> BBED> sum apply
Check value for File 1, Block 78302:
current = 0x35c8, required = 0x35c8

--重启db,并重建索引

-重启
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started. Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 297795584 bytes
Redo Buffers 6791168 bytes
Database mounted.
Database opened.
--修改为2个值一样
SQL> select /*+ FULL(t1) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11764 SQL> select /*+ index(t1 I_CON2) */ owner#,name,con# from con$ t1 WHERE NAME='_NEXT_CONSTRAINT'; OWNER# NAME CON#
---------- ------------------------------ ----------
0 _NEXT_CONSTRAINT 11764 SQL> conn test/***
Connected.
SQL> alter table yhq_test add primary key(id); Table altered. SQL> select CONSTRAINT_NAME from dba_constraints where table_name='YHQ_TEST'; CONSTRAINT_NAME
------------------------------
SYS_C0011764

---正常。

11 ORA-8102:Index Corruption解析的更多相关文章

  1. 微信小程序0.11.122100版本新功能解析

    微信小程序0.11.122100版本新功能解析   新版本就不再吐槽了,整的自己跟个愤青似的.人老了,喷不动了,把机会留给年轻人吧.下午随着新版本开放,微信居然破天荒的开放了开发者论坛.我很是担心官方 ...

  2. [nRF51822] 11、基础实验代码解析大全 · 实验16 - 内部FLASH读写

     一.实验内容: 通过串口发送单个字符到NRF51822,NRF51822 接收到字符后将其写入到FLASH 的最后一页,之后将其读出并通过串口打印出数据. 二.nRF51822芯片内部flash知识 ...

  3. 2016.11.25 activiti的配置文件解析

    参考来自activiti的用户手册.   activiti的配置文件解析 1.processEngine的配置 注意,单独创建流程引擎与spring方式创建流程引擎是不一样的,区别在于:process ...

  4. 11 Scrapy框架之递归解析和post请求

    一.递归爬取解析多页页面数据 - 需求:将糗事百科所有页码的作者和段子内容数据进行爬取切持久化存储 - 需求分析:每一个页面对应一个url,则scrapy工程需要对每一个页码对应的url依次发起请求, ...

  5. 11、testng.xml文件解析

    我们可以从以下几种方式调用testng 用testng.xml ant 命令行 我们本次重点介绍testng.xml,testng.xml 文件来配置测试用例的执行 ,testng.xml 文件可以很 ...

  6. JUC 并发编程--11, AQS源码原理解析, ReentrantLock 源码解读

    这里引用别人博客,不重复造轮子 https://blog.csdn.net/u012881584/article/details/105886486 https://www.cnblogs.com/w ...

  7. Oracle特殊恢复原理与实战(DSI系列)

    1.深入浅出Oracle(DSI系列Ⅰ) 2.Oracle特殊恢复原理与实战(DSI系列Ⅱ) 3.Oracle SQL Tuning(DSI系列Ⅲ)即将开设 4.Oracle DB Performan ...

  8. 这可能是vue-cli最全的解析了……

    题言: 相信很多vue新手,都像我一样,只是知道可以用vue-cli直接生成一个vue项目的架构,并不明白,他究竟是怎么运行的,现在我们一起来研究一下... 一.安装vue-cli,相信你既然会用到v ...

  9. Oracle的tnsnames.ora配置(PLSQL Developer)

    首先打开tnsnames.ora的存放目录,一般为D:\app\Administrator\product\11.2.0\client_1\network\admin,就看安装具体位置了. 步骤阅读 ...

随机推荐

  1. C++ STL(二)vector的用法

    ##### vector的定义 ```#include <iostream>#include <string>#include <vector>using name ...

  2. 多线程使用@Async注解创建多线程,自定义线程池

    转载自博客https://www.jianshu.com/p/7ac04a501eba

  3. flask+gevent的异步框架

    一:flask本身的框架时什么? 基于Wsgi的Web应用框架 二:为什么要实现异步架构? 增加并发处理能力 三:实现异步架构 from gevent import monkey from geven ...

  4. python技巧31[移植python2.x到3.x]

    我们都知道python从2.x升级到3.x的过程中有一些不兼容的改动,但是有时还我们不得不将2.x的程序升级到3.x. 主要不兼容如下图: 移植过程: 1) 确保存在的代码有足够的测试覆盖.从2.x到 ...

  5. oracle基本语句(第五章、数据库逻辑存储结构管理)

    1.使用SYS用户以SYSDBA身份登录到SQL Plus,使用视图V$TABLESPACE查看表空间信息 SELECT * FROM V$TABLESPACE; 2.查看视图DBA_TABLESPA ...

  6. 参数类型*&是什么意思?

    前两天摸鱼聊天的时候遇到一个问题,一个链表的函数中,有一个参数显得很奇怪 (大概是一个样子的)ListNode<T>*& l 这个参数l除了用了一个*之外还用了一个&,直觉 ...

  7. linux运维、架构之路-Logstash启动时指定jdk版本

    一.修改bin/logstash vim /app//logstash-6.7.0/bin/logstash export JAVA_CMD="/app/jdk1.8.0_11/bin&qu ...

  8. css-div中文字过多(内容超出div宽度)后自动换行

    故事是这样的: 买家秀:(refuse)                                                                                ...

  9. 使用bitmap实现对一千万个无重复的正整数(范围1~1亿)快速排序

    1 Bytes(字节) == 8 bit 1 KBytes == 1024 Bytes 思路: 1)申请长度为1亿的保存二进制位的数组 a, 2)通过位运算,将整数做为索引,将数组a对应的索引位置为1 ...

  10. Apollo配置中心环境搭建(Linux)

    官方教程:https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2 方式二:使用apol ...