oracle 10G 表空间迁移 索引需要重建
2010-09-27 00:05
351 查看
昨天进行了表空间迁移的维护,维护后出现一个问题: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
针对该问题和其他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
相关文章推荐
- oracle 10G 表空间迁移 索引需要重建
- 分析oracle索引空间使用情况,以及索引是否需要重建
- 创建空间数据分区表及分区索引步骤(oracle 10g 且关键字非字符型)
- ORACLE重建索引需要考虑问题
- Oracle 迁移与审计相关表和索引的表空间
- Oracle中重建索引时如何解决“无法为表空间 XXXXXX 中的段创建INITIAL区”错误 .
- ORACLE重建索引需要考虑问题
- Oracle 10g 修改表空间和索引空间
- 如何找出Oracle中需要或值得重建的索引
- ORACLE关于索引是否需要定期重建争论的整理
- 如何找出Oracle中需要或值得重建的索引
- 分析oracle索引空间使用情况,以及索引是否需要重建
- Oracle中重建索引时如何解决“无法为表空间 XXXXXX 中的段创建INITIAL区”错误
- Oracle 10g DG 数据文件迁移的实现
- 个人需要,收集了一些关于Oracle 10g OCP认证的资料,与大家分享
- Oracle 10g 特性: 通过备份实现可传输表空间
- Oracle 8i迁移到10g注意问题
- Oracle中加速索引创建或重建的方法
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- DBA需要知道的Oracle 10g的审计内容