ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ORA-01502 state unusable错误成因和解决方法(转)

ORA-01502 state unusable错误成因和解决方法(转)

原创 Linux操作系统 作者:jcszjswkzhou 时间:2019-04-28 07:51:06 0 删除 编辑
ORA-01502 state unusable错误成因和解决方法(二),sql,sql教程,Oracle基础

SQL> create table t(a number);

Table created.

现在我们建立一个唯一索引来看看:
SQL> create unique index idx_t on t(a);

Index created.

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='T';

no rows selected

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE VALID

SQL> insert into t values(1);

1 row created.

SQL> commit;

Commit complete.

将索引手工修改为unusable状态(模拟发生索引失效的情况):
SQL> alter index idx_t unusable;

Index altered.

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE UNUSABLE

我们看到这是已经不能正常往表中插入数据:
SQL> insert into t values(2);
insert into t values(2)
*
ERROR at line 1:
ORA-01502: index 'MISC.IDX_T' or partition of such index is in unusable state

首先我们通过重建索引(rebuild index)的方法来解决问题:
SQL> alter index idx_t rebuild;

Index altered.

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE VALID

SQL> insert into t values(2);

1 row created.

SQL> commit;

Commit complete.

SQL>

现在我们再次模拟索引失效(unusable状态):
SQL> alter index idx_t unusable;

Index altered.

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE UNUSABLE

SQL> insert into t values(3);
insert into t values(3)
*
ERROR at line 1:
ORA-01502: index 'MISC.IDX_T' or partition of such index is in unusable state

然后看看是否可以通过设置参数skip_unusable_indexes=true来解决问题:
SQL> alter session set skip_unusable_indexes=true;

Session altered.

SQL> insert into t values(3);
insert into t values(3)
*
ERROR at line 1:
ORA-01502: index 'MISC.IDX_T' or partition of such index is in unusable state

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE UNUSABLE

SQL> alter index idx_t rebuild;

Index altered.

SQL> select index_name,index_type,tablespace_name,table_type,status from user_indexes where index_name='IDX_T';

INDEX_NAME INDEX_TYPE TABLESPACE_NAME TABLE_TYPE STATUS
------------------------------ --------------------------- ------------------------------ ----------- --------
IDX_T NORMAL DATA_DYNAMIC TABLE VALID

SQL> insert into t values(3);

1 row created.

SQL> commit;

Commit complete.

SQL>
很显然对于unique index通过简单的设置参数是不能解决问题的要解决unique index 失效的问题只能通过重建索引来实现

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-122196/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-08-29

  • 博文量
    3488
  • 访问量
    2621534