Oracle恢復實驗(二)

wallimn發表於2011-09-26
環境:Oracle10g、Red Hat 4,Oracle執行在歸檔模式。

場景:資料檔案user01.dbf損壞,開啟資料庫情況下進行恢復。

具體步驟:
[b]1、刪除user01.dbf檔案模擬資料檔案損壞,關閉資料庫,嘗試開啟。[/b]
!rm -f /home/oracle/oracle/product/oradata/orcl、users01.dbf
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 130023424 bytes
Fixed Size 1218100 bytes
Variable Size 62917068 bytes
Database Buffers 62914560 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/home/oracle/oracle/product/oradata/orcl/users01.dbf'
可以看到:資料檔案4找不到,無法開啟資料庫,資料庫啟動到Mount狀態

[b]2、將損壞資料檔案離線[/b]
SQL> alter database datafile 4 offline;

Database altered.

[b]3、開啟資料庫[/b]
SQL> alter database open;

Database altered.
離線後,資料庫可以正常開啟。

[b]4、複製資料檔案,嘗試將資料檔案聯機[/b]
SQL> !cp /disk2/bak/users01.dbf /home/oracle/oracle/product/oradata/orcl

SQL> alter database datafile 4 online;
alter database datafile 4 online
*
ERROR at line 1:
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/home/oracle/oracle/product/oradata/orcl/users01.dbf'
此時Oracle會提示需要介質恢復

[b]5、介質恢復[/b]
recover tablespace users;

[b]6、將表空間聯機[/b]
SQL> select name,status from v$datafile;

NAME STATUS
------------------------------------------------------------ -------
/home/oracle/oracle/product/oradata/orcl/system01.dbf SYSTEM
/home/oracle/oracle/product/oradata/orcl/undotbs01.dbf ONLINE
/home/oracle/oracle/product/oradata/orcl/sysaux01.dbf ONLINE
/home/oracle/oracle/product/oradata/orcl/users01.dbf OFFLINE

SQL> alter database datafile 4 online;

Database altered.


[b]7、檢查資料[/b]
SQL> select count(*) from scott.recover_test;

COUNT(*)
----------
448

相關文章