oracle 10G 表空间迁移 索引需要重建
昨天進行了表空間遷移的維護,維護后出現一個問題:MYTEST用戶下的表表空間遷移后索引存在失效。
針對該問題和其他DBA進行了一些溝通,大家理解并不統一。后通過實際測試發現,表空間遷移后沒有數據的表索引正常,但有數據的表的相關索引確實會失效,
解決的方法是REBUILD索引(今早rubuild MYTEST下的所有索引,通過select INDEX_NAME,status from user_indexes確認status均為VALID的正常狀態)。
進一步查找資料發現:
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來操作該表時用到該索引,會引發ORA-01502 error,因此索引必須drop或者rebuild。
該表的統計信息也會失效,所以需要重新對該表進行統計分析,即analyze table *** compute statistics。)
但是針對ORA-01502,實際測試時并不存在
測試步驟:
SQL> create table test_altertablespace (col1 number) tablespace USERS;------------------------------------------------------創建測試表,表空間為USERS
Table created
SQL> create index idx_test_altertablespace on test_altertablespace(col1);----------------------------------------------------創建索引
Index created
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態為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';--確認索引的狀態為VALID
TABLESPACE_NAME??????????????? STATUS
------------------------------ --------
IN_MYTEST_DATA??????????????????? ?VALID
SQL> insert into test_altertablespace values(1);------------------------------------------------------------------------------------------插入數據
1 row inserted
SQL> commit;
Commit complete
SQL> select tablespace_name,status from user_indexes where index_name = 'IDX_TEST_ALTERTABLESPACE';--確認索引的狀態為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';--確認索引的狀態為UNUSABLE
TABLESPACE_NAME??????????????? STATUS
------------------------------ --------
IN_MYTEST_DATA???????????????????? UNUSABLE
?
轉載于:https://blog.51cto.com/yunlongzheng/397758
總結
以上是生活随笔為你收集整理的oracle 10G 表空间迁移 索引需要重建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: scvmm2008R2创建委派管理员角色
- 下一篇: 可耻的中国互联网