oracle检查数据库是否有坏块的命令

来源:互联网 发布:淘宝网买的学车模拟器 编辑:程序博客网 时间:2024/05/19 23:02

原文地址:http://blog.itpub.net/16111659/viewspace-663907/

oracle检查数据库是否有坏块的命令

dbv是检查物理上是否有坏块的命令

#su - oracle
#dbv file=/oracleruanko/app/oracle/oracle/product/10.2.0/ruanko/dbs/ruankotest blocksize=8192

DBVERIFY: Release 10.2.0.1.0 - Production on Fri May 28 09:56:37 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

DBVERIFY - Verification starting : FILE = /oracleruanko/app/oracle/oracle/product/10.2.0/ruanko/dbs/ruankotest


DBVERIFY - Verification complete

Total Pages Examined         : 2560
Total Pages Processed (Data) : 356
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 255
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 112
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1837
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Highest block SCN            : 140907784 (0.140907784)

2:analyze 是检查逻辑上是否有坏块的,还可以对表进行统计分析优化,

SQL>analyze table ruankosystem.RSYS_ACC_ACCOUNT
  2  validate structure cascade;

Table analyzed.

SQL>analyze index ruankosystem.PK_RSYS_ACC_ACCOUNT
  2  validate structure;

Index analyzed.


3:db_block_checking是逻辑上的,是初始化参数:
是实时的控制和扫描每一个块,对性能有一点点的影响
可以通过alter session 或alter system deferred 命令对神经过敏进行设置

4:db_block_checksum是物理上的检查,也是初始化的参数对io来进入实时的

5:dblock media recovery是逻辑和物理上都可以
这个是用RMAN做的如:
rman> blockrecover batafile 6 block3:

-查一下 V$database_bloce_corruption有多少个坏块

rman > blockrecover corruption list 
    >restore until time 'sysdate-10';

-查一下v$dackup_corruption视图显示数据库文件备份中的损坏块清单
-v$copy_corruption 视图文件副本中的坏块清单


6:exp/expdb导出的时候就会进行扫描,是物理上的检查和恢复
7:flashback是逻辑上的

8:dbms_repalr是逻辑上的专是做恢复用的包
有的功能是
-CHECK_OBJECT
-FIX_CORRUPT_BLOCKS
-DUMP_ORPHAN_KEYS
-REBUILD_FREELISTS
-SEGMENT_FIX_STATUS
-SKIP_CORRUPT_BLOCKS
-ADMIN_TABLES



如:先检查ruankoystem这个用户下的RSYS_ACC_ACCOUNT表是否有坏块
set serveroutput on
declare num_corrupt int;
begin
  num_corrupt := 0;
  dbms_repair.check_object (
  schema_name => 'ruankoystem',
  object_name => 'RSYS_ACC_ACCOUNT'
  repair_table_name => 'repair_table',
  corrupt_count => num_corrupt);
end;

如何修复
set serveroutput on
declare num_fix int;
begin
  num_fix := 0;
  dbms_repair.fix_corrup_blocks (
  schema_name => 'ruankoystem',
  object_name => 'RSYS_ACC_ACCOUNT'
  object_type => dbms_repair.table_object,
  repair_table_name => 'repair_table',
  fix_count => num_fix );
end;

修理index和重建丢失的数据
set serveroutput on 
declare num_orphans int:
begin 
 num_orphans := 0;
 dbms_repair.dump_orphan_reys()
  sehema_name => 'ruankosystem'
  object_name => 'PK_rsys_acc_acount'
  object_type => dbms_repair.index_object,
  repair_table_name => 'orpman_key_table',
  orphan_table_name => 'ORPMAN_KEY_TABLE',
  key_count => num_orphans);
 dbms_output.put_line('orphan key count: '|| to_char(num_orphans)
);
end;




表数据可以是坏的,但是index(索引一定要是好的)

set serveroutput on

declare 
nrows number;
badrows number;
vyhdabh varchar2(50);
vfgsbh varchar2(50);
vjbh varchar2(50);
begin
badrows := 0;
nrows := 0;
for i in (select /*+ index (tabl1) */ rowid, fgsbh from id_data.yh_dnbtab1) loop
begin 

 insert into ld_data.newtb select from ld_data.yh_dnb where rowid=i.orwid;

 if (mod (nrows,20000)=0) then cmmit; end if;

  exception wher others then
  badrows := badrows+1;
  select / *+ index(a YH_DNB_IND_2) */ yhdabh,fgsbh,jbh into
 vyhdabh,ufgsbh,ujbh form. id_data.yh_dnb a where rowid=i.rowid;

 insert into bad_rows values (i.rowid,vfgsbh,vyhdabh,vjbh);
commit;
end;
nrow:=nrows+1;
end loop;
dbms_output.put_line('total rows: '||to_char(nrows)||'bad rows:'||to_char(badrows));
commit;
end;
/



用上面那个查出了那些记录坏了,就可以手动补单了
修复后再用dbms_repair make所有坏块做一个标识