OS:
Oracle Linux Server release 5.7
DB:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
首先创建yoon数据库
SQL> create tablespace yoon datafile '/u01/oracle/oradata/yoon/yoon01.dbf' size 50m;
Tablespace created.
SQL> create user yoon identified by yoon default tablespace yoon;
User created.
SQL> grant dba to yoon;
Grant succeeded.
SQL> create table yoon.yoon as select * from scott.emp;
Table created.
在操作中误删除数据文件yoon01.dbf
rm -rf yoon01.dbf
select ts#,file#,name,bytes,status from v$datafile;
ps -ef | grep dbw
cd /proc/..../fd
一、在线恢复:
[oracle@b28-122 yoon]$ rm -rf yoon01.dbf
[oracle@b28-122 yoon]$ ps -ef |grep dbw |grep -v grep
oracle
[oracle@b28-122 yoon]$ cd /proc/17417/fd
[oracle@b28-122 fd]$ cp 267 /u01/oracle/oradata/yoon/newyoon01.dbf
SQL> alter database datafile 6 offline;
Database altered.
SQL> alter database rename file '/u01/oracle/oradata/yoon/yoon01.dbf' to '/u01/oracle/oradata/yoon/newyoon01.dbf';
Database altered.
SQL> recover datafile 6;
Media recovery complete.
SQL> alter database datafile 6 online;
Database altered.
二、离线恢复
rm -rf yoon01.dbf
ps -ef | grep dbw | grep -v grep
cp /proc/.../fd/...
shutdown immediate
startup
recover database;
alter database open;
[oracle@b28-122 yoon]$ rm -rf yoon01.dbf
[oracle@b28-122 yoon]$ ps -ef | grep dbw | grep -v grep
oracle
[oracle@b28-122 yoon]$ cd /proc/18743/fd
[oracle@b28-122 fd]$ cp 265 /u01/oracle/oradata/yoon/yoon01.dbf
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/oracle/oradata/yoon/yoon01.dbf'
SQL> recover database;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> select * from yoon.yoon;
---------- ------------------------------ --------------------------- ---------- ------------------ ---------- ---------- ----------
14 rows selected.