整个过程不要关闭数据库
1.手动删除没有备份的数据文件。
rm -f /oracle/app/oradata/orcl/users01.dbf
2.尝试在删除文件上创建表,让数据库读取数据,模拟报错
SQL> create table tt (id number) tablespace users;
create table tt (id number) tablespace users
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/oracle/app/oradata/orcl/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
3.获取丢失文件列表
SQL>select file_id,file_name from dba_data_files where file_id in(select file# from v$datafile_header where name is null);
4.查看dbw后台进程id
[oracle@11g ~]$ ps -ef|grep dbw
oracle 1874 1 0 09:14 ? 00:00:00 ora_dbw0_orcl
oracle 1993 1962 0 09:35 pts/0 00:00:00 grep dbw
5.使用lsof命令查看dbw进程所持有的文件句柄
lsof -p 1874
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
...
oracle 1874 oracle 256u REG 8,3 9748480 789827 /oracle/app/oradata/orcl/control01.ctl
oracle 1874 oracle 257u REG 8,3 9748480 789830 /oracle/app/oradata/orcl/control02.ctl
oracle 1874 oracle 258uW REG 8,3 734011392 789836 /oracle/app/oradata/orcl/system01.dbf
oracle 1874 oracle 259uW REG 8,3 629153792 789839 /oracle/app/oradata/orcl/sysaux01.dbf
oracle 1874 oracle 260uW REG 8,3 209723392 789840 /oracle/app/oradata/orcl/undotbs01.dbf
oracle 1874 oracle 261uW REG 8,3 5251072 789846 /oracle/app/oradata/orcl/users01.dbf (deleted)
oracle 1874 oracle 262uW REG 8,3 20979712 789841 /oracle/app/oradata/orcl/temp01.dbf
...
注:误删文件标记为deleted.
误删文件(文件句柄信息为:/proc//fd/)
6.查看文件句柄信息
[oracle@11g ~]$ ll /proc/1874/fd/261
lrwx------ 1 oracle oinstall 64 Feb 3 09:19 /proc/1874/fd/261 -> /oracle/app/oradata/orcl/users01.dbf (deleted)
7.通过文件句柄信息,将丢失文件拷贝出来
[oracle@11g ~]$ cp /proc/1874/fd/261 /oracle/app/oradata/orcl/users02.dbf
8.离线失效文件(因为数据库为非归档模式,需要使用offline的drop选项)
SQL> alter database datafile 4 offline drop;
Database altered.
9.查看离线数据文件状态为recover。
select name,status from v$datafile;
NAME STATUS
------------------------------------------------------------ ------------------------------
/oracle/app/oradata/orcl/system01.dbf SYSTEM
/oracle/app/oradata/orcl/sysaux01.dbf ONLINE
/oracle/app/oradata/orcl/undotbs01.dbf ONLINE
/oracle/app/oradata/orcl/users01.dbf RECOVER
10.重命名丢失数据文件。
SQL> alter database rename file '/oracle/app/oradata/orcl/users01.dbf' to '/oracle/app/oradata/orcl/users02.dbf';
Database altered.
11.恢复数据文件。
SQL> recover datafile 4;
Media recovery complete.
12.上线数据文件
SQL> alter database datafile 4 online;
Database altered.
13.验证数据文件状态。
SQL> select name,status from v$datafile;
NAME STATUS
------------------------------------------------------------ ------------------------------
/oracle/app/oradata/orcl/system01.dbf SYSTEM
/oracle/app/oradata/orcl/sysaux01.dbf ONLINE
/oracle/app/oradata/orcl/undotbs01.dbf ONLINE
/oracle/app/oradata/orcl/users02.dbf ONLINE
14.验证数据文件是否可用。
SQL> create table tt (id number) tablespace users;
Table created.