在之前的博客中我们看了smon_scn_time表的相关说明:
Oracle smon_scn_time 表 说明
http://www.cndba.cn/dave/article/1285
这里我们看一下如何重建smon_scn_time表上的索引。
1. 背景说明
一般我们不会重建smon_scn_time表上的索引,但如果数据库遇到了ORA-8102错误。 就需要重建表上的索引。
从日志看,该错误会在SMON进程上体现出来,因为在上篇文章中提过, smon_scn_time 表是由SMON 进程维护的。
Errors in file /opt/bdump/emrep_smon_1241286.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-08102: index key not found, obj#
[[email protected] ~]$ 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
[[email protected] ~]$
实际上,这里的ORA-08102的错误就表明表上的相关索引出现了损坏。
测试如果执行:
SQL> analyze table SMON_SCN_TIME validate structure ;
Table analyzed.
没有异常。
但如果执行:
SQL> analyze table SMON_SCN_TIME validate structure cascade online ;
则会报:ORA-1499的错误。
[[email protected] ~]$ oerr ora 1499
01499, 00000, "table/index cross reference failure - see trace file"
// *Cause:
// *Action:
[[email protected] ~]$
2. 重建索引
要解决smon_scn_time 表上的ORA-08102的错误,需要重建该表上的索引。
首先:确认该表是否有任何损坏:
SQL> analyze table SMON_SCN_TIME validate structure ;
Table analyzed.
查看表上的索引:
SQL> set lines 120
SQL> col index_name for a40
SQL> col index_type for a20
SQL> col owner for a20
SQL> select index_name,index_type,owner from dba_indexes where table_name='SMON_SCN_TIME' ;
INDEX_NAME INDEX_TYPE OWNER
---------------------------------------- -------------------- --------------------
SMON_SCN_TIME_TIM_IDX NORMAL SYS
SMON_SCN_TIME_SCN_IDX NORMAL SYS
SQL>
获取索引的DDL语法:
SQL> set long 10000000
SQL> select dbms_metadata.get_ddl('INDEX','SMON_SCN_TIME_TIM_IDX','SYS') FROM DUAL ;
DBMS_METADATA.GET_DDL('INDEX','SMON_SCN_TIME_TIM_IDX','SYS')
--------------------------------------------------------------------------------
CREATE UNIQUE INDEX "SYS"."SMON_SCN_TIME_TIM_IDX" ON "SYS"."SMON_SCN_TIME" ("TIME_MP")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX"
SQL> select dbms_metadata.get_ddl('INDEX','SMON_SCN_TIME_SCN_IDX','SYS') FROM DUAL ;
DBMS_METADATA.GET_DDL('INDEX','SMON_SCN_TIME_SCN_IDX','SYS')
--------------------------------------------------------------------------------
CREATE UNIQUE INDEX "SYS"."SMON_SCN_TIME_SCN_IDX" ON "SYS"."SMON_SCN_TIME" ("SCN")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX"
删除索引:
SQL> drop index sys.SMON_SCN_TIME_TIM_IDX ;
Index dropped.
SQL> drop index sys.SMON_SCN_TIME_SCN_IDX ;
Index dropped.
验证SMON_SCN_TIME表的有效性:
SQL> analyze table SMON_SCN_TIME validate structure cascade online ;
Table analyzed.
如果没有问题,那么运行之前获取的DDL语句,重建2个索引:
CREATE UNIQUE INDEX "SYS"."SMON_SCN_TIME_TIM_IDX"
ON "SYS"."SMON_SCN_TIME" ("TIME_MP")
PCTFREE 10
INITRANS 2
MAXTRANS 255
COMPUTE STATISTICS
STORAGE (INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ;
CREATE UNIQUE INDEX "SYS"."SMON_SCN_TIME_SCN_IDX"
ON "SYS"."SMON_SCN_TIME" ("SCN")
PCTFREE 10
INITRANS 2
MAXTRANS 255
COMPUTE STATISTICS
STORAGE (INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ;
最后在验证SMON_SCN_TIME表的状态:
SQL> analyze table SMON_SCN_TIME validate structure cascade online ;
Table analyzed.
恢复正常,也不会报ORA-08102的错误了。
参考:
How to Resolve ORA-08102 Reported on Table SMON_SCN_TIME (文档 ID 978502.1)
版权声明:本文为博主原创文章,未经博主允许不得转载。
重建 SMON_SCN_TIME 表上的索引