数据文件有时候因为某种原因会导致损坏而导致无法启动数据库,那如何恢复呢?
下面是一次模拟实验,如下
1. 首先创建一个表空间TEST,在创建一个表test在表空间test上
SQL> create tablespace test datafile '/u01/app/oracle/oradata/lhz/test01.dbf' size 10M;
SQL> create table test as select * from dba_objects;
Table created
SQL> alter table test move tablespace test;
Table altered
SQL> select count(*) from test;
COUNT(*)
----------
50881
2. 然后用vi编辑数据文件
[oracle@odb1 ~]$ vi /u01/app/oracle/oradata/lhz/test01.dbf
3.随便输入什么字符,保存
4.关闭数据库实例
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
5.启动实例
SQL> startup
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 2098112 bytes
Variable Size 243272768 bytes
Database Buffers 348127232 bytes
Redo Buffers 6287360 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 9 - see DBWR trace file
ORA-01110: data file 9: '/u01/app/oracle/oradata/lhz/test01.dbf'
看到报错信息数据文件不能验证或锁定数据文件
6. 先将损坏数据文件offline,并打开数据库实例
SQL> alter database datafile '/u01/app/oracle/oradata/lhz/test01.dbf' offline;
Database altered.
SQL> alter database open;
Database altered.
7. 添加相同的表空间test
SQL> alter database create datafile '/u01/app/oracle/oradata/lhz/test01.dbf';
Database altered.
SQL> recover datafile 9;
Media recovery complete.
SQL> alter database datafile 9 online;
Database altered.
8.验证恢复结果:
SQL> select count(*) from andylhz.test;
COUNT(*)
----------
50881
恢复完成!
本文转自andylhz 51CTO博客,原文链接:http://blog.51cto.com/andylhz2009/1197954,如需转载请自行联系原作者