ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 移植索引表空间

移植索引表空间

原创 Linux操作系统 作者:lonesashimi 时间:2010-01-11 16:11:11 0 删除 编辑
Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 适用版本:9.2.0.5

问题描述:

查看bdump目录下alter.log文件,可以看到索引表空间上出现坏块,无法进行RMAN全库备份:

***

Corrupt block relative dba: ……

Bad check value found during backing up datafile

Data in bad block -

 type: 6 format: 2 rdba: ……

 last change scn: ….. seq: … flg: …

 consistency value in tail: ……

 check value in block header: ……, computed block checksum: ……

 spare1: 0x0, spare2: 0x0, spare3: 0x0

***

Reread of blocknum=……, file=……. found same corrupt data

……

Errors in file .trc:

ORA-27037: unable to obtain file status

Linux-ia64 Error: 2: No such file or directory

Additional information: 4

 

其中,file和block参数说明了坏块存在的位置。这里采用移植索引的办法处理,新建表空间,将原表空间下所有的索引,重建到新的表空间中。

 

执行步骤

1.         建立新的表空间,参考:



CREATE TABLESPACE

  DATAFILE ' ' SIZE 1024 M

  extent management local uniform. size 1M

  segment space management auto;

 

ALTER TABLESPACE   ONLINE;

 

ALTER DATABASE DATAFILE

' ' AUTOEXTEND ON NEXT 50M;


 

2.         重建原表空间中的索引;

1)        生成执行脚本

对于索引:user_indexes包含所有索引信息,使用如下语句重建:

alter index rebuild tablespace online nologging;

 


select 'alter index '||index_name||' rebuild tablespace online nologging;'
from dba_indexes where tablespace_name = ''
order by table_name,num_rows desc;

 

对于分区索引:user_ind_partitions包含所有分区索引信息,使用如下语句重建:

alter index rebuild partition tablespace ;

 

2)        执行

执行 sqlplus /@ < rebuild_index.sql > rebuild_index.log

执行之后,查看rebuild_index.log,对于busy,未重建成功的索引,重新执行rebuild语句,直到提示“Index altered”,完成重建。

 

3.         分析重建索引

也可以在上一步中,增加compute statistics子句,但是这样可能会造成执行计划的改变;

1)        生成执行脚本

对于索引,语法:analyze index compute statistics;


select 'analyze index '||index_name||' compute statistics;'
from user_indexes
where tablespace_name = ' ’

 

 

对于分区索引,语法:analyze index   partition() compute statistics;

按照上面的语法,建立分析脚本。

2)        执行

同样存成脚本文件,使用sqlplus /@ < re_analyze.sql > re_analyze.log

查看re_analyze.log日志文件。

 

4.         将索引改为归档模式

1)        生成执行脚本

对于索引,语法: alter index logging; 将所有logging = NO的索引,改为归档模式。


select 'alter index '||index_name||' logging;'
from user_indexes
where logging = 'NO';

 

 

 

对于分区索引,语法:alter index modify partition logging;

 


select 'alter index '||index_name||' MODIFY partition '||partition_name||' logging;'
from user_ind_partitions
where logging = 'NO';

 

 

2)        执行

sqlplus  /@ < alter_logging.sql > alter_logging.log

 

删除原表空间

执行下面脚本,判断原表空间是否还在使用:

select * from dba_extents where tablespace_name = '';

若返回为空行,则删除表空间:

drop tablespace ;

在操作系统下删除文件:

rm

 

特殊说明

对于某些主键索引的列宽超过3215,需要停掉应用,重新建立。

步骤如下:

1.         停掉应用;

执行ps fax |grep LOCAL=NO 查看没有外部应用;

2.         备份建立索引的脚本;

3.         删除该主键及其索引

4.         修改脚本中tablespace 子句的值,指定新表空间;

5.         对新建的索引进行分析;

6.         重建成功,重启应用;

 

 

本次操作的脚本包括:

Ø         建立表空间,及其执行日志:

create_tableSpace.log

create_tableSpace.sql

 

Ø         生成DDL脚本

generate_script_RebuiltIndex.sql

generate_script_Analyze.sql

generate_script_Log.sql

 

Ø         用于执行的DDL脚本

exe_rebuild_index.sql

exe_analyze.sql

exe_logging.sql

 

Ø         执行结果日志

rebuild_index.log

analyze.log

logging.log

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

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-01-11

  • 博文量
    1
  • 访问量
    5346