恢復rm -f物理刪除資料檔案

parknkjun發表於2016-01-30
1、在資料庫open的時候,直接刪除users表空間中的資料庫檔案;
SYS@jzh>select name from v$dbfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/jzh/users01.dbf
/u01/app/oracle/oradata/jzh/undotbs01.dbf
/u01/app/oracle/oradata/jzh/sysaux01.dbf
/u01/app/oracle/oradata/jzh/system01.dbf
/u01/app/oracle/oradata/jzh/example01.dbf

SYS@jzh>host rm /u01/app/oracle/oradata/jzh/users01.dbf
[oracle@jzh5 ~]$ cd /u01/app/oracle/oradata/jzh/
[oracle@jzh5 jzh]$ ll
total 1879452
-rw-r----- 1 oracle oinstall   9748480 Jan 30 09:38 control01.ctl
-rw-r----- 1 oracle oinstall 328343552 Jan 30 09:35 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:38 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo03.log
-rw-r----- 1 oracle oinstall 576724992 Jan 30 09:35 sysaux01.dbf
-rw-r----- 1 oracle oinstall 744497152 Jan 30 09:35 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Dec  8 03:50 temp01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jan 30 09:35 undotbs01.dbf
users0.dbf已經被刪除了
2、在表空間users中建立測試表
SYS@jzh>create table jzh (id int,name varchar2(10)) tablespace USERS;
create table jzh (id int,name varchar2(10)) tablespace USERS
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/u01/app/oracle/oradata/jzh/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
------報錯了
3、檢查dbwr程式的PID
[oracle@jzh5 jzh]$ ps -ef | grep dbw0 | grep -v grep
oracle    3182     1  0 09:35 ?        00:00:00 ora_dbw0_jzh
4、dbwr程式會開啟所有資料檔案的控制程式碼,在proc目錄中可以查到,目錄名是程式PID,fd表示檔案描述符
[oracle@jzh5 3182]$ cd /proc/3182/fd
[oracle@jzh5 fd]$ ll
total 0
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 30 09:47 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 10 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 12 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 13 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 14 -> /proc/3182/fd
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 15 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkJZH
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 18 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
l-wx------ 1 oracle oinstall 64 Jan 30 09:47 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 256 -> /u01/app/oracle/oradata/jzh/control01.ctl
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 257 -> /u01/app/oracle/fast_recovery_area/jzh/control02.ctl
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 258 -> /u01/app/oracle/oradata/jzh/system01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 259 -> /u01/app/oracle/oradata/jzh/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 260 -> /u01/app/oracle/oradata/jzh/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 261 -> /u01/app/oracle/oradata/jzh/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 262 -> /u01/app/oracle/oradata/jzh/example01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 263 -> /u01/app/oracle/oradata/jzh/temp01.dbf
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 4 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 5 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 6 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 7 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 8 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 9 -> /dev/null
以上標紅檔案被標記為deleted
5、直接cp該控制程式碼檔名回原位置
[oracle@jzh5 fd]$ cp 261 /u01/app/oracle/oradata/jzh/users01.dbf
6、進行資料檔案recover
SYS@jzh>alter database datafile 4 offline;            
Database altered.
SYS@jzh>recover datafile 4;
Media recovery complete.
SYS@jzh>alter database datafile 4 online;
Database altered.
[oracle@jzh5 fd]$ cd /u01/app/oracle/oradata/jzh
[oracle@jzh5 jzh]$ ll
total 1884592
-rw-r----- 1 oracle oinstall   9748480 Jan 30 09:53 control01.ctl
-rw-r----- 1 oracle oinstall 328343552 Jan 30 09:35 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:52 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo03.log
-rw-r----- 1 oracle oinstall 576724992 Jan 30 09:52 sysaux01.dbf
-rw-r----- 1 oracle oinstall 744497152 Jan 30 09:52 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Dec  8 03:50 temp01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jan 30 09:52 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Jan 30 09:52 users01.dbf
users01.dbf檔案回來了!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10271187/viewspace-1984550/,如需轉載,請註明出處,否則將追究法律責任。

相關文章