解决Ora 14098分区交换索引不匹配错误

769 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
769
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

解决Ora 14098分区交换索引不匹配错误

  1. 1. 解决 ORA-14098 分区交换 索引不匹配错误 by Maclean.liu liu.maclean@gmail.com www.oracledatabase12g.comowner=&OWNER1
  2. 2. About Mel Email:liu.maclean@gmail.coml Blog:www.oracledatabase12g.coml Oracle Certified Database Administrator Master 10gand 11gl Over 6 years experience with Oracle DBA technologyl Over 7 years experience with Linux technologyl Member Independent Oracle Users Groupl Member All China Users Groupl Presents for advanced Oracle topics: RAC,DataGuard, Performance Tuning and Oracle Internal.
  3. 3. 上周在客户一套 BRM 系统上执行分区交换 Exchange Partition 操作的时候出现了 ORA-14098错误,该错误是由于分区表上的 LOCAL 分区索引与非分区表上的索引不匹配造成的,我们来看一下这个错误:[oracle@rh2 ~]$ oerr ora 1409814098, 00000, "index mismatch for tables in ALTER TABLE EXCHANGE PARTITION"// *Cause: The two tables specified in the EXCHANGE have indexes which are// not equivalent// *Action: Ensure that the indexes for the two tables have indexes which// follow this rule// For every non partitioned index for the non partitioned table,// there has to be an identical LOCAL index on the partitioned// table and vice versa. By identical, the column position, type// and size have to be the same.SQL> ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 withtable SALES_TMP INCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXES;ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 withtable SALES_TMP INCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXES *ERROR at line 1:ORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITION如果表上有很多的索引,以至于你无法确定到底是哪个索引引发了 ORA-14098 错误,那么我们可以通过 trace 的方式来协助定位到具体的索引:SQL> select * from v$version;BANNER----------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64biPL/SQL Release 10.2.0.4.0 - ProductionCORE 10.2.0.4.0 ProductionTNS for Linux: Version 10.2.0.4.0 - ProductionNLSRTL Version 10.2.0.4.0 - ProductionSQL> select * from global_name;GLOBAL_NAME--------------------------------------------------------------------------------www.oracledatabase12g.comSQL> alter session set max_dump_file_size = unlimited;Session altered.
  4. 4. SQL> alter session set events 10046 trace name context forever, level 12;Session altered.SQL> alter session set events 14098 trace name errorstack forever, level 4;Session altered.##SQL> alter system flush buffer_cache;System altered.Rerun Exchange Partition DDLSQL> ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 with table SALES_TMPINCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXES;ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 with table SALES_TMPINCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXES *ERROR at line 1:ORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITION11g 中直接查询 v$diag_info 就可以得到 trace 的路径,10g 执行 gettracename.sqlSELECT d.VALUE || / || LOWER (RTRIM (i.INSTANCE, CHR (0))) || _ora_ || p.spid || .trc trace_file_name FROM (SELECT p.spid FROM v$mystat m, v$session s, v$process p WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p, (SELECT t.INSTANCE FROM v$thread t, v$parameter v WHERE v.NAME = thread AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i, (SELECT VALUE FROM v$parameter WHERE NAME = user_dump_dest) d;TRACE_FILE_NAME--------------------------------------------------------------------------------/s01/admin/G10R2/udump/g10r2_ora_17749.trc==========================10046/errorstack tracecontents========================PARSING IN CURSOR #1 len=127 dep=0 uid=64 oct=15 lid=64 tim=1277655207436065hv=1207961095 ad=9098f018ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 with table SALES_TMPINCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXESEND OF STMTPARSE #1:c=0,e=1145,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=1277655207436059BINDS #1:STAT #2 id=2 cnt=0 pid=1 pos=1 obj=98001 op=INDEX FULL SCAN SALES_UNID_TMP(cr=1 pr=0 pw=0 time=39 us)*** 2011-06-17 21:55:32.417ksedmp: internal or fatal errorORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITIONCurrent SQL statement for this session:ALTER TABLE sales EXCHANGE PARTITION SALES_Q4_2003 with table SALES_TMP
  5. 5. INCLUDING INDEXES WITH VALIDATION UPDATE GLOBAL INDEXES我们可以在 trace 中看到在出现 ORA-14098 错误前,正在对索引 SALES_UNID_TMP 的 Fast Full Scan除了通过 10046/errorstack 的 trace 信息诊断外,更多的问题可以直接从 DDL 语句中发现,在以上示例中非分区表的 DDL 语句:-- Create tablecreate table SALES_TMP( UNI_ID NUMBER NOT NULL, PROD_ID NUMBER not null, CUST_ID NUMBER not null, TIME_ID DATE not null, CHANNEL_ID NUMBER not null, PROMO_ID NUMBER not null, QUANTITY_SOLD NUMBER(10,2) not null, AMOUNT_SOLD NUMBER(10,2) not null);create index SALES_CHANNEL_TMP ON SALES_TMP (CHANNEL_ID) ;create index SALES_CUST_TMP ON SALES_TMP (CUST_ID) ;create index SALES_UNID_TMP ON SALES_TMP (UNI_ID,TIME_ID); --注意细节该索引是非 UNIQUE 的create index SALES_PROD_TMP ON SALES_TMP (PROD_ID) ;create index SALES_PROMO_TMP ON SALES_TMP (PROMO_ID) ;create index SALES_TIME_TMP ON SALES_TMP (TIME_ID) ;下为分区表的 DDL 语句:-- Create tablecreate table SALES( UNI_ID NUMBER NOT NULL, PROD_ID NUMBER not null, CUST_ID NUMBER not null, TIME_ID DATE not null, CHANNEL_ID NUMBER not null, PROMO_ID NUMBER not null, QUANTITY_SOLD NUMBER(10,2) not null, AMOUNT_SOLD NUMBER(10,2) not null)partition by range (TIME_ID)...............create index SALES_CHANNEL ON SALES (CHANNEL_ID) LOCAL;create index SALES_CUST ON SALES (CUST_ID) LOCAL;create UNIQUE index SALES_UNID ON SALES (UNI_ID,TIME_ID) LOCAL; -- 对应的索引是 UNIQUE 的create index SALES_PROD ON SALES (PROD_ID) LOCAL;create index SALES_PROMO ON SALES (PROMO_ID) LOCAL;create index SALES_TIME ON SALES (TIME_ID) LOCAL;
  6. 6. 解决 ORA-14098 错误的要点是要找出引发错误的原因。当我们交换分区的时候,我们要确保所有交换表上的索引和分区表上的本地索引匹配。这意味 着如果在分区表上有 N 个LOCAL INDEXES,那么在交换表上就应当有 N 个等价的索引。这里的等价要求存在映射关系的 2 个索引,在列的位置、类型、大小及 UNIQUE/NON- UNIQUE 都要一致。可以利用如下 SQL 语句来找出分区表和交换表上索引的差异:set linesize 160 pagesize 1400col TABLE_NAME for a30col INDEX_NAME for a30col COLUMN_NAME for a30col COLUMN_POSITION for 99col COLUMN_LENGTH for 99col CHAR_LENGTH for 99col DESCEND for a4Select TABLE_NAME,INDEX_NAME, COLUMN_NAME,COLUMN_POSITION, COLUMN_LENGTH,CHAR_LENGTH, DESCENDFROM SYS.DBA_IND_COLUMNS DICNWHERE INDEX_OWNER = &own and DICN.TABLE_NAME in (&TABNAME1,&TABNAME2)ORDER BY INDEX_NAME, COLUMN_POSITION/select TABLE_NAME, INDEX_NAME, INDEX_TYPE, UNIQUENESS, PARTITIONED from dba_indexes where owner=&OWNER and TABLE_NAME in (&TABNAME1, &TABNAME2) order by index_name/
  7. 7. 也可以使用 Toad 的 Single Schema Object Compare 功能来对比检验索引:对于存在主键的分区表,可以在主键上以 DISABLE VALIDATE 方式创建 unique constraint 约束,以代替全局的主键索引。若交换表(Exchange Table)上存在主键索引的话,那么建议在交换前暂时将该索引 drop 掉,待交换完成后再重建。如果实在无法解决该 ORA-14098 错误,那么可以尝试使用 EXCLUDING INDEXES 子句以跳过索引维护,而在交换完成后重建相关失效索引。© 2011, www.oracledatabase12g.com. 版权所有.文章允许转载,但必须以链接方式注明源地址,否则追求法律责任.

×