Oracle 数据库模拟数据文件损坏恢复

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:991

[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]1. 首先创建一个表空间TEST,在创建一个表test在表空间test上[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> create tablespace test datafile '/u01/app/oracle/oradata/lhz/test01.dbf' size 10M;
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> create table test as select * from dba_objects;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Table created[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> alter table test move tablespace test;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Table altered[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> select count(*) from test;
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,] COUNT(*)[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]----------[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,] 50881
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]2. 然后用vi编辑数据文件
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,][oracle@odb1 ~]$ vi /u01/app/oracle/oradata/lhz/test01.dbf[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]3.随便输入什么字符,保存[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]4.关闭数据库实例[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> shutdown immediate;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database closed.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database dismounted.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]ORACLE instance shut down.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]5.启动实例[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> startup[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]ORACLE instance started.
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Total System Global Area 599785472 bytes[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Fixed Size 2098112 bytes[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Variable Size 243272768 bytes[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database Buffers 348127232 bytes[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Redo Buffers 6287360 bytes[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database mounted.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]ORA-01157: cannot identify/lock data file 9 - see DBWR trace file[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]ORA-01110: data file 9: '/u01/app/oracle/oradata/lhz/test01.dbf'
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]看到报错信息数据文件不能验证或锁定数据文件[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]6. 先将损坏数据文件offline,并打开数据库实例[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> alter database datafile '/u01/app/oracle/oradata/lhz/test01.dbf' offline;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database altered.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> alter database open;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database altered.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]7. 添加相同的表空间test[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> alter database create datafile '/u01/app/oracle/oradata/lhz/test01.dbf';[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database altered.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> recover datafile 9;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Media recovery complete.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> alter database datafile 9 online;[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]Database altered.[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]8.验证恢复结果:
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]SQL> select count(*) from andylhz.test;
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,] COUNT(*)[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]----------[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,] 50881
[p=28, null, left][color=rgb(85, 85, 85)][font=宋体,]恢复完成!

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】