數據文件有時候因爲某種原因會導致損壞而導致無法啓動數據庫,那如何恢復呢?
下面是一次模擬實驗,如下
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
恢復完成!