11 ORA-8102:Index Corruption解析

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[12]
rowdata[0]
----------
ub1 rowdata[0]                              @920      0x2c

BBED> x /rccnn
rowdata[0]                                  @920     
----------
flag@920:  0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@921:  0x01
cols@922:     4

col    0[1] @923: .
col   1[16] @925: _NEXT_CONSTRAINT
col    2[4] @942: 11763 ##这个11763和上面查到的一致
col    3[1] @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[12]
rowdata[0]
----------
ub1 rowdata[0]                              @920      0x2c

BBED> x /rccnn
rowdata[0]                                  @920     
----------
flag@920:  0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@921:  0x01
cols@922:     4

col    0[1] @923: .
col   1[16] @925: _NEXT_CONSTRAINT
col    2[4] @942: 11764 ###修改为11763+1
col    3[1] @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[1942] flag: ---D--, lock: 3, len=13, data:(6):  00 41 57 47 00 61
col 0; len 4; (4):  c3 02 12 3f
row#358[1955] flag: ------, lock: 0, len=13, data:(6):  00 40 01 21 00 0c ---1955 相对位置
col 0; len 4; (4):  c3 02 12 40
----- 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

---正常。

posted @ 2019-07-10 15:13  春困秋乏夏打盹  阅读(667)  评论(0编辑  收藏  举报