Oracle坏块修复处理实验
2015-10-15 20:08
615 查看
坏块分为物理坏块和逻辑坏块,前者是硬件问题产生,后者是oracle内部数据有问题,本次实验针对后者。
给数据库开启归档模式
1.创建实验所需的表空间、用户、表和相关实验数据
1.1创建相关表空间和用户
切换检查点,将数据写入数据文件
4.使用dbv检测
这里会显示出坏块的数量和坏块所在的数据文件id号和block id号,也可以通过查询v$database_block_corruption视图
5.此时使用rman和exp导出文件时会提示错误
5.1.exp导出
解决方法:
通过设置坏块的最大数量来备份
查看损失的记录数
给数据库开启归档模式
[oracle@cancer ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 15 17:09:40 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> archive log lst SP2-0718: illegal ARCHIVE LOG option SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 4 Current log sequence 6 SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 784998400 bytes Fixed Size 2257352 bytes Variable Size 515903032 bytes Database Buffers 264241152 bytes Redo Buffers 2596864 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered. SQL> select open_mode from v$database; OPEN_MODE -------------------- READ WRITE
1.创建实验所需的表空间、用户、表和相关实验数据
1.1创建相关表空间和用户
--创建一个大小为1m的表空间 create tablespace test datafile '/u01/oracle/oradata/orcl/test01.dbf' size 1m; --创建test用户 create user test identified by test default tablespace test temporary tablespace temp profile DEFAULT; --授予相关的测试权限 grant connect,dba,resource,unlimited tablespace to test;1.2创建表和模拟数据
SQL> create table test tablespace test as select * from scott.emp; Table created. SQL> insert into test select * from test; 14 rows created. SQL> insert into test select * from test; 28 rows created. ..... 3584 rows created. SQL> insert into test select * from test; 7168 rows created. SQL> commit; Commit complete. SQL> insert into test select * from test; insert into test select * from test * ERROR at line 1: ORA-01653: unable to extend table TEST.TEST by 8 in tablespace TEST SQL> select count(*) from test; COUNT(*) ---------- 14336给表增加索引
SQL> create index idx_test on test(ename); Index created
切换检查点,将数据写入数据文件
SQL> alter system checkpoint; System altered.2.破坏前先用rman备份表空间,得到可以修复的备份
[oracle@cancer ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 18:01:08 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1420957945) RMAN> backup tablespace "TEST" tag=tt; Starting backup at 15-OCT-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/oracle/oradata/orcl/test01.dbf channel ORA_DISK_1: starting piece 1 at 15-OCT-15 channel ORA_DISK_1: finished piece 1 at 15-OCT-15 piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp tag=TT comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 15-OCT-153.shutdown之后,使用ultraedit修改数据文件 --修改的时候不要开头部,启动oracle后,查询表会提示出错
SQL> select count(*) from test; select count(*) from test * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 6, block # 19) ORA-01110: data file 6: '/u01/oracle/oradata/orcl/test01.dbf'
4.使用dbv检测
[oracle@cancer ~]$ dbv file=/u01/oracle/oradata/orcl/test01.dbf DBVERIFY: Release 11.2.0.4.0 - Production on Thu Oct 15 18:12:45 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/oracle/oradata/orcl/test01.dbf Page 19 is marked corrupt Corrupt block relative dba: 0x01800013 (file 6, block 19) --坏块的数据文件号和坏块号 Bad check value found during dbv: Data in bad block: type: 6 format: 2 rdba: 0x01800013 last change scn: 0x0000.000f0427 seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0x04270601 check value in block header: 0x6c9f computed block checksum: 0x8700 Page 86 is marked corrupt Corrupt block relative dba: 0x01800056 (file 6, block 86) --坏块的数据文件号和坏块号 Bad check value found during dbv: Data in bad block: type: 6 format: 2 rdba: 0x01800056 last change scn: 0x0000.000f044b seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0x044b0601 check value in block header: 0x38f5 computed block checksum: 0xe335 Page 92 is marked corrupt Corrupt block relative dba: 0x0180005c (file 6, block 92) --坏块的数据文件号和坏块号 Bad check value found during dbv: Data in bad block: type: 6 format: 2 rdba: 0x0180005c last change scn: 0x0000.000f044b seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0x044b0601 check value in block header: 0x5b61 computed block checksum: 0x3edf DBVERIFY - Verification complete Total Pages Examined : 128 Total Pages Processed (Data) : 107 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 17 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 1 Total Pages Marked Corrupt : 3 --这里会显示出有3个坏块 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 984304 (0.984304)
这里会显示出坏块的数量和坏块所在的数据文件id号和block id号,也可以通过查询v$database_block_corruption视图
SQL> select * from v$database_block_corruption; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE ---------- ---------- ---------- ------------------ --------------- 6 19 1 0 CHECKSUM 6 86 1 0 CHECKSUM 6 92 1 0 CHECKSUM
5.此时使用rman和exp导出文件时会提示错误
5.1.exp导出
[oracle@cancer ~]$ exp test/test file=/server/backup/test.dmp Export: Release 11.2.0.4.0 - Production on Thu Oct 15 18:33:45 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in US7ASCII character set and AL16UTF16 NCHAR character set server uses ZHS16GBK character set (possible charset conversion) About to export specified users ... . exporting pre-schema procedural objects and actions . exporting foreign function library names for user TEST . exporting PUBLIC type synonyms . exporting private type synonyms . exporting object type definitions for user TEST About to export TEST's objects ... . exporting database links . exporting sequence numbers . exporting cluster definitions . about to export TEST's tables via Conventional Path ... . . exporting table TEST EXP-00056: ORACLE error 1578 encountered ORA-01578: ORACLE data block corrupted (file # 6, block # 19) ORA-01110: data file 6: '/u01/oracle/oradata/orcl/test01.dbf' . exporting synonyms . exporting views . exporting stored procedures . exporting operators . exporting referential integrity constraints . exporting triggers . exporting indextypes . exporting bitmap, functional and extensible indexes . exporting posttables actions . exporting materialized views . exporting snapshot logs . exporting job queues . exporting refresh groups and children . exporting dimensions . exporting post-schema procedural objects and actions . exporting statistics Export terminated successfully with warnings.
解决方法:
ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10' ;exp导出后
ALTER SYSTEM SET EVENTS='10231 trace name context off' ;5.2rman导出
RMAN> backup tablespace "TEST" tag=badblock; Starting backup at 15-OCT-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/oracle/oradata/orcl/test01.dbf channel ORA_DISK_1: starting piece 1 at 15-OCT-15 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/15/2015 18:37:04 ORA-19566: exceeded limit of 0 corrupt blocks for file /u01/oracle/oradata/orcl/test01.dbf解决方法:
通过设置坏块的最大数量来备份
RMAN> run 2> {set maxcorrupt for datafile 6 to 10; 3> backup tablespace "TEST" tag=badblock;} executing command: SET MAX CORRUPT Starting backup at 15-OCT-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/oracle/oradata/orcl/test01.dbf channel ORA_DISK_1: starting piece 1 at 15-OCT-15 channel ORA_DISK_1: finished piece 1 at 15-OCT-15 piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_BADBLOCK_c1z0k7dh_.bkp tag=BADBLOCK comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 15-OCT-15
查看损失的记录数
SQL> select count(*) from test; COUNT(*) ---------- 13825 --得到损失的记录数 SQL> select 14336-13825 from dual; 14336-13825 ----------- 5116.使用rman备份的文件来修复
[oracle@cancer ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 18:57:19 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1420957945) RMAN> blockrecover from tag=tt datafile 6 block 19,86,92; Starting recover at 15-OCT-15 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=52 device type=DISK channel ORA_DISK_1: restoring block(s) channel ORA_DISK_1: specifying block(s) to restore from backup set restoring blocks of datafile 00006 channel ORA_DISK_1: reading from backup piece /u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp channel ORA_DISK_1: piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp tag=TT channel ORA_DISK_1: restored block(s) from backup piece 1 channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01 starting media recovery media recovery complete, elapsed time: 00:00:01 Finished recover at 15-OCT-15查询此时的记录数
SQL> select count(*) from test; COUNT(*) ---------- 143367.使用dbv再次验证file6数据文件
[oracle@cancer ~]$ dbv file=/u01/oracle/oradata/orcl/test01.dbf DBVERIFY: Release 11.2.0.4.0 - Production on Thu Oct 15 19:03:03 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/oracle/oradata/orcl/test01.dbf DBVERIFY - Verification complete Total Pages Examined : 128 Total Pages Processed (Data) : 110 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 17 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 1 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 984304 (0.984304)或者使用rman来验证(以下结果是另外一个实验结果)
[oracle@cancer ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 19:29:50 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1420957945) RMAN> BACKUP CHECK LOGICAL VALIDATE DATAFILE 6; Starting backup at 15-OCT-15 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=44 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/oracle/oradata/orcl/test01.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 6 FAILED 0 1 128 984304 File Name: /u01/oracle/oradata/orcl/test01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 1 110 Index 0 0 Other 0 17 validate found one or more corrupt blocks See trace file /u01/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_26126.trc for details Finished backup at 15-OCT-15
相关文章推荐
- Oracle 11g安装图文攻略
- Oracle's Business Intelligence Applications Configuration Manager 基本概念
- Oracle坏块问题总结
- Oracle 健康监控器(Health Monitor)
- Oracle 中多个字段显示成一列
- Oracle中对现有表增加列
- Oracle 事件打包服务(Incident Packaging Service,IPS)
- Oracle 自动诊断信息库(Automatic Diagnostic Repository,ADR)
- RedHat6.5 安装Oracle 12c RAC
- 快速解决IMP中的ORA-00959
- Oracle ERROR: ORA-12560: TNS: 协议适配器错误
- Oracle的SUN服务器支持VirtualCD
- 在Maven仓库中添加Oracle JDBC驱动
- linux下OCI基础:配置Instant Client连oracle数据库
- Oracle中在不同的用户下的表之间创建关联关系
- oracle数据库,局域网实现多台电脑登录,查看同一数据库
- ORA-01722:invalid number
- Oracle的列操作(增加列,修改列,删除列),包括操作多列
- ORACLE递归查询(适用于ID,PARENTID结构数据表)
- 修改oracle的字符集