環境:RHEL 5.4 + Oracle 11.2.0.3
背景:數據庫沒有備份,數據庫文件被誤操做rm,此時數據庫還沒有關閉,也就是對應句柄存在,如何快速恢復?數據庫
1.1 模擬5號數據文件被rm誤刪除oracle
SQL> select name, open_mode from v$database; NAME OPEN_MODE --------- -------------------- PROD2 READ WRITE SQL> col name for a55 SQL> select file#, name from v$datafile; FILE# NAME ---------- ------------------------------------------------------- 1 /u03/oradata/PROD2/system01.dbf 2 /u03/oradata/PROD2/sysaux01.dbf 3 /u03/oradata/PROD2/undotbs01.dbf 4 /u03/oradata/PROD2/users01.dbf 5 /u03/oradata/PROD2/example01.dbf SQL> !ls -lrth /u03/oradata/PROD2/example01.dbf -rw-r----- 1 oracle oinstall 346M May 20 10:58 /u03/oradata/PROD2/example01.dbf SQL> !rm /u03/oradata/PROD2/example01.dbf SQL> !ls -lrth /u03/oradata/PROD2/example01.dbf ls: /u03/oradata/PROD2/example01.dbf: No such file or directory SQL> exit
1.2 依據句柄號拷貝恢復5號數據文件測試
[oracle@edbjr2p2 PROD2]$ pwd /u03/oradata/PROD2 [oracle@edbjr2p2 PROD2]$ ls -lrth total 1.7G -rw-r----- 1 oracle oinstall 21M May 20 02:50 temp01.dbf -rw-r----- 1 oracle oinstall 5.1M May 20 10:58 users01.dbf -rw-r----- 1 oracle oinstall 51M May 20 10:58 redo03.log -rw-r----- 1 oracle oinstall 51M May 20 10:58 redo01.log -rw-r----- 1 oracle oinstall 91M May 20 15:34 undotbs01.dbf -rw-r----- 1 oracle oinstall 731M May 20 15:34 system01.dbf -rw-r----- 1 oracle oinstall 751M May 20 15:34 sysaux01.dbf -rw-r----- 1 oracle oinstall 51M May 20 15:38 redo02.log -rw-r----- 1 oracle oinstall 9.3M May 20 15:38 control01.ctl [oracle@edbjr2p2 PROD2]$ ps -ef|grep dbw0_PROD2|grep -v grep oracle 28526 1 0 10:58 ? 00:00:01 ora_dbw0_PROD2 [oracle@edbjr2p2 PROD2]$ cd /proc/28526/fd/ [oracle@edbjr2p2 fd]$ ls -lrth|grep deleted lrwx------ 1 oracle oinstall 64 May 20 15:39 261 -> /u03/oradata/PROD2/example01.dbf (deleted) [oracle@edbjr2p2 fd]$ cp 261 /u03/oradata/PROD2/example01.dbf
恢復以後,數據庫沒有發現有異常報錯,繼續進行操做或重啓庫都沒有問題。spa
若是是全部數據文件被刪除,恢復的方法和上面同樣,但測試這種狀況通常還須要特殊處理後才能夠開庫。
好比我這裏的實驗遇到了2個錯誤:code
具體現象以下:文檔
SQL> select file#, checkpoint_change# from v$datafile 2 ; FILE# CHECKPOINT_CHANGE# ---------- ------------------ 1 2150244 2 2150244 3 2150244 4 2150244 5 2150244 SQL> select file#, checkpoint_change# from v$datafile_header; FILE# CHECKPOINT_CHANGE# ---------- ------------------ 1 2150244 2 2150244 3 2150244 4 2150244 5 2150244 SQL> alter database open; alter database open * ERROR at line 1: ORA-00600: internal error code, arguments: [kcratr_scan_lastbwr], [], [], [], [], [], [], [], [], [], [], [] SQL> recover database; ORA-00600: internal error code, arguments: [3020], [3], [2070], [12584982], [], [], [], [], [], [], [], [] ORA-10567: Redo is inconsistent with data block (file# 3, block# 2070, file offset is 16957440 bytes) ORA-10564: tablespace UNDOTBS1 ORA-01110: data file 3: '/u03/oradata/PROD2/undotbs01.dbf' ORA-10560: block type 'KTU UNDO BLOCK' RMAN> recover database until scn 2150244; Starting recover at 20-MAY-19 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=10 device type=DISK starting media recovery Oracle Error: ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to be consistent ORA-01110: data file 1: '/u03/oradata/PROD2/system01.dbf' media recovery complete, elapsed time: 00:00:01 Finished recover at 20-MAY-19 RMAN> SQL> select file#, checkpoint_change# from v$datafile; FILE# CHECKPOINT_CHANGE# ---------- ------------------ 1 2150244 2 2150244 3 2150244 4 2150244 5 2150244 SQL> select file#, checkpoint_change# from v$datafile_header; FILE# CHECKPOINT_CHANGE# ---------- ------------------ 1 2150244 2 2150244 3 2150244 4 2150244 5 2150244 SQL> alter database open resetlogs; alter database open resetlogs * ERROR at line 1: ORA-01194: file 1 needs more recovery to be consistent ORA-01110: data file 1: '/u03/oradata/PROD2/system01.dbf'
此時嘗試設置隱藏參數:get
_allow_resetlogs_corruption=true
再次嘗試成功開庫:it
SQL> alter database open resetlogs; Database altered.