当前位置:操作系统 > Unix/Linux >>

不小心删除数据文件的处理方式

不小心删除数据文件的处理方式
 
一,不小心删除了一个数据文件,非归档模式,为了把危害降到最低,打算强制打开数据库,这时候的操作方法。
 
我们先删除一个数据文件,现在打开数据库
 
[html] 
SQL> shutdown abort;  
ORACLE instance shut down.  
SQL> startup;  
ORA-32004: obsolete and/or deprecated parameter(s) specified  
ORACLE instance started.  
  
Total System Global Area  167772160 bytes  
Fixed Size          1218316 bytes  
Variable Size          79694068 bytes  
Database Buffers       83886080 bytes  
Redo Buffers            2973696 bytes  
Database mounted.  
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file  
ORA-01110: data file 7: '/u01/app/oracle/oradata/orcl/tsp_test01.dbf'  
  
  
SQL> alter database open;  
alter database open  
*  
ERROR at line 1:  
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file  
ORA-01110: data file 7: '/u01/app/oracle/oradata/orcl/tsp_test01.dbf'  
我们可以看出来,数据库在停止在mount阶段,开始open的时候报错,报错显示出:不能识别和锁定file_id=7的数据文件,这个文件正是我刚才删除的。
那么现在必须打开数据库,该怎么办呢?我们可以将这个数据文件设为脱机(OFFLINE),如下:
 
 
[html] 
SQL> alter database datafile '/u01/app/oracle/oradata/orcl/tsp_test01.dbf' offline;  
  
Database altered.  
现在打开数据库:
 
[html] 
SQL> alter database open;  
  
Database altered.  
数据库被打开。
那么现在打开数据库了,我们得确认一下这个数据文件的丢失对数据库的那些对象产生的影响,这样我们才可以清楚的了解到失误对数据库造成了多大的伤害,所以,下面我们要找到这些收影响的对象,首先我们知道这个数据文件所代表的表空间
 
 
[html] 
SQL> select tablespace_name from dba_data_files where file_id = '7';  
  
TABLESPACE_NAME  
------------------------------  
TSP_TEST  
得到了这个表空间的名字是:TSP_TEST,下面找到这个表空间中的对象
 
[html] 
SQL> select OWNER,TABLESPACE_NAME,EXTENTS,HEADER_FILE,SEGMENT_NAME from dba_segments where tablespace_name = 'TSP_TEST';   
  
OWNER                  TABLESPACE_NAME           EXTENTS HEADER_FILE SEGMENT_NAME  
------------------------------ ------------------------------ ---------- ----------- ---------------------------------------------------------------------------------  
TEST                   TSP_TEST                   21       7 BIN$5Jl2esAloA7gQAB/AQB4Dg==$0  
TEST                   TSP_TEST                   21       7 TEST7  
这样我们可以清楚地为下一步的拯救做基础。
二,不小心删除了数据文件,归档模式,我们将怎么来恢复数据库
 
创建表空间tp_test,表test10,索引ind_test10
 
 
[html] 
SQL> create tablespace tp_test datafile '/u01/app/oracle/oradata/orcl/tp_test01.dbf' size 10M;  
  
Tablespace created.  
  
SQL> create table test10 (v_num number)tablespace tp_test;  
  
Table created.  
  
SQL> create index ind_test10 on test10(v_num) tablespace tp_test;  
  
Index created.  
手工删除数据文件,模拟断电关闭数据库,然后启动
 
[html] 
SQL> shutdown abort  
ORACLE instance shut down.  
SQL> startup  
ORA-32004: obsolete and/or deprecated parameter(s) specified  
ORACLE instance started.  
  
Total System Global Area  167772160 bytes  
Fixed Size          1218316 bytes  
Variable Size          67111156 bytes  
Database Buffers       96468992 bytes  
Redo Buffers            2973696 bytes  
Database mounted.  
ORA-01157: cannot identify/lock data file 8 - see DBWR trace file  
ORA-01110: data file 8: '/u01/app/oracle/oradata/orcl/tp_test01.dbf'  
发现启动到mount阶段,不能open
接下来我们要恢复数据库,创建数据文件,打开自动恢复功能,恢复数据文件
 
[html] 
SQL> alter database create datafile '/u01/app/oracle/oradata/orcl/tp_test01.dbf';  
  
Database altered.  
  
SQL> set autorecovery on;  
SQL> recover datafile '/u01/app/oracle/oradata/orcl/tp_test01.dbf';  
Media recovery complete.  
SQL> alter database open;  
  
Database altered.  
  
SQL> select * from test10;  
  
no rows selected  
 
这样我们在查询表,发现表还是完整的存在。
 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,