昨天進行了表空間遷移的維護,維護后出現(xiàn)一個問題:MYTEST用戶下的表表空間遷移后索引存在失效。
針對該問題和其他DBA進行了一些溝通,大家理解并不統(tǒng)一。后通過實際測試發(fā)現(xiàn),表空間遷移后沒有數(shù)據(jù)的表索引正常,但有數(shù)據(jù)的表的相關索引確實會失效,
解決的方法是REBUILD索引(今早rubuild MYTEST下的所有索引,通過select INDEX_NAME,status from user_indexes確認status均為VALID的正常狀態(tài))。
進一步查找資料發(fā)現(xiàn):
Moving a table changes the rowids of the rows in the table. This causes indexes on the table to be marked UNUSABLE,
and DML accessing the table using these indexes will receive an ORA-01502 error. The indexes on the table must be dropped or rebuilt.
Likewise, any statistics for the table become invalid and new statistics should be collected after moving the table.
移動表會導致行的rowid變化,導致該表上面的index不可用,即標記為UNUSABLE,當用DML來操作該表時用到該索引,會引發(fā)ORA-01502 error,因此索引必須drop或者rebuild。
該表的統(tǒng)計信息也會失效,所以需要重新對該表進行統(tǒng)計分析,即analyze table *** compute statistics。)
但是針對ORA-01502,實際測試時并不存在
測試步驟:
SQL> create table test_altertablespace (col1 number) tablespace USERS;------------------------------------------------------創(chuàng)建測試表,表空間為USERS
Table created
SQL> create index idx_test_altertablespace on test_altertablespace(col1);----------------------------------------------------創(chuàng)建索引
Index created
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態(tài)為VALID
TABLESPACE_NAME STATUS
------------------------------ --------
IN_MYTEST_DATA VALID
SQL> alter table test_altertablespace move tablespace IN_MYTEST_DATA;--------------------------------------------------遷移表空間到IN_MYTEST_DATA
Table altered
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態(tài)為VALID
TABLESPACE_NAME STATUS
------------------------------ --------
IN_MYTEST_DATA VALID
SQL> insert into test_altertablespace values(1);------------------------------------------------------------------------------------------插入數(shù)據(jù)
1 row inserted
SQL> commit;
Commit complete
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態(tài)為VALID
TABLESPACE_NAME STATUS
------------------------------ --------
IN_MYTEST_DATA VALID
SQL> alter table test_altertablespace move tablespace users;----------------------------------------------------------------------移動表空間到USERS
Table altered
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態(tài)為UNUSABLE
TABLESPACE_NAME STATUS
------------------------------ --------
IN_MYTEST_DATA UNUSABLE
本文出自 “麥地塢” 博客,請務必保留此出處http://yunlongzheng.blog.51cto.com/788996/397758