您好,登錄后才能下訂單哦!
做系統管理的都是這樣,難免會誤刪文件,某天要是把某個Oracle數據文件刪除,那該如何恢復呢?(這里數據庫是OPEN的,并且未關閉)
建立測試表空間
創建測試用戶
插入測試數據
刪除數據文件
恢復數據庫文件
建立測試表空間
SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /opt/oracle/oradata/member/system01.dbf /opt/oracle/oradata/member/sysaux01.dbf /opt/oracle/oradata/member/undotbs01.dbf /opt/oracle/oradata/member/users01.dbf SQL> create tablespace test datafile '/opt/oracle/oradata/member/test01.dbf' size 10m; Tablespace created. SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /opt/oracle/oradata/member/system01.dbf /opt/oracle/oradata/member/sysaux01.dbf /opt/oracle/oradata/member/undotbs01.dbf /opt/oracle/oradata/member/users01.dbf /opt/oracle/oradata/member/test01.dbf
2.創建測試賬戶
SQL> create user test identified by test default tablespace test; SQL> grant connect,resource to test;
3.插入測試數據
SQL> conn test/test SQL> create table t1(id int); SQL> insert into t1 values(1); SQL> select * from t1; ID ---------- 1
4.刪除數據文件
[oracle@db2 ~]$ rm -f /opt/oracle/oradata/member/test01.dbf [oracle@db2 ~]$ sqlplus test/test SQL> create table t2 as select * from t1; create table t2 as select * from t1 * ERROR at line 1: ORA-01116: error in opening database file 5 ORA-01110: data file 5: '/opt/oracle/oradata/member/test01.dbf' ORA-27041: unable to open file Linux-x86_64 Error: 2: No such file or directory Additional information: 3 SQL> select table_name,tablespace_name from user_tables; TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ T1 TEST
數據文件被刪除了,這怎么辦呢?這個時候千萬別重啟數據庫,否則數據就丟失了
5.數據文件恢復
[oracle@db2 ~]$ ps -ef |grep dbw0 oracle 3309 1 0 12:07 ? 00:00:00 ora_dbw0_member oracle 6217 5105 0 15:29 pts/0 00:00:00 grep dbw0 #找到ora_dbw0_SID的進程號3309 [oracle@db2 ~]$ cd /proc/3309/fd #以上3309就是進程號,然后執行ls -al查看文件的鏈接
可以看到文件27就是被刪除的文件
[oracle@db2 fd]$ cp 27 /opt/oracle/oradata/member/test01.dbf
查看test表空間狀態
SQL> select name,status from v$datafile; NAME STATUS ---------------------------------------- ------- /opt/oracle/oradata/member/system01.dbf SYSTEM /opt/oracle/oradata/member/sysaux01.dbf ONLINE /opt/oracle/oradata/member/undotbs01.dbf ONLINE /opt/oracle/oradata/member/users01.dbf ONLINE /opt/oracle/oradata/member/test01.dbf ONLINE
下線test01表文件
SQL> alter database datafile '/opt/oracle/oradata/member/test01.dbf' offline; SQL> recover datafile '/opt/oracle/oradata/member/test01.dbf'; Media recovery complete. SQL> alter database datafile '/opt/oracle/oradata/member/test01.dbf' online; Database altered.
#以上就成功恢復了,若是出現
SQL> recover datafile '/opt/oracle/oradata/member/test01.dbf'; ORA-00283: recovery session canceled due to errors ORA-01110: data file 5: '/opt/oracle/oradata/member/test01.dbf' ORA-01157: cannot identify/lock data file 5 - see DBWR trace file ORA-01110: data file 5: '/opt/oracle/oradata/member/test01.dbf'
則有可能是/opt/oracle/oradata/member/test01.dbf文件的權限問題引起,在root用戶下
[root@db2 ~]# chown -R oracle.oinstall /opt/oracle/oradata/member/test01.dbf 再recover datafile '/opt/oracle/oradata/member/test01.dbf'
實驗完成后,刪除測試用戶及測試表空間
SQL> drop user test cascade; SQL> drop tablespace test INCLUDING CONTENTS AND DATAFILES;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。