【翻譯自mos文章】在unix/linux中使用檔案描述符(File Descriptors)來找回被刪掉的檔案(資料檔案or redo log),怎麼刪掉分節符號

來源:互聯網
上載者:User

【翻譯自mos文章】在unix/linux中使用檔案描述符(File Descriptors)來找回被刪掉的檔案(資料檔案or redo log),怎麼刪掉分節符號
在unix/linux中使用檔案描述符(File Descriptors)來找回被刪掉的檔案(資料檔案or redo log)
參考原文:
Retrieve deleted files on Unix / Linux using File Descriptors (Doc ID 444749.1)
適用於:
Oracle Database - Enterprise Edition - Version 8.1.7.0 to 11.2.0.3 [Release 8.1.7 to 11.2]
Linux x86
Oracle Solaris on SPARC (64-bit)
Linux x86-64
***Checked for relevance on 24-Nov-2010***
目標:在資料庫沒有被重啟的情況下,從作業系統中找回被刪掉的datafile和logfile
解決方案:
當符合下列狀態時,我們可以藉助unix/linux中的proc 檔案系統,找回(retrieve)被刪除的datafile和logfile
1.) Database is not restarted. 
2.) Server is not restarted. 
3.) The file was not offline before deletion. 
後台進程(DBWR, PMON, SMON etc)訪問被本資料庫開啟的所有datafiles,因此,藉助於lsof命令,可以看到被進程open的 檔案清單。
被進程開啟的任何一個檔案,都有一個檔案描述符(fd)與該檔案相關聯。若是該檔案被從作業系統中誤刪除了,該檔案的條目(entry)並沒有從proc 檔案系統中被刪除,藉助於該entry,我們可以重建被刪除的file(datafile or logfile)
如下是一個例子:

1.) Create a tablespaceSQL> create tablespace my_test datafile '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' size 200k; Tablespace created.2.) Accidentally, the datafile belonging to this tablespace was deleted $ rm /emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf 3.) Try resizing the datafileSQL> alter database datafile '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' resize 250k; alter database datafile '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' resize 250k * ERROR at line 1: ORA-01565: error in identifying file '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' ORA-27037: unable to obtain file status SVR4 Error: 2: No such file or directory Additional information: 3 

搶救該檔案的步驟
1.)找到dbwr進程的os pid
--> $ ps -ef |grep '<SID>'| grep '<name_of_background_process>'
$ ps -ef |grep EMR102U6|grep dbw emrdbms 21943 1 0 10:27:08 ? 0:00 ora_dbw0_EMR102U6
2.)使用lsof命令為該 ospid 找到開啟的檔案
$ lsof -p 21943 |grep /emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbfCommand PID   USER    FD    TYPE DEVICE SIZE/OFF     NODE                            NAME oracle 21943 emrdbms 270uW  VREG 304,25 212992     11273825 /emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf 
注意:
If you are using NAS then the file name in the above command may not be displayed properly and hence this procedure should not be used under these circumstances.
注意上面的fd值--270
3.)到fd目錄下

--> $ cd /proc/ <process_id> / <file_descriptor_directory>'/

$ cd /proc/21943/fd/

4.)將該資料表空間read only
alter tablespace my_test read only; 
將資料表空間置為read only 凍結了檔案頭,防止檔案頭的更新。因為 當database 處於open時,只有在datafile 處於read only狀態下 才可能copy 該file。
read only 允許使用者select 該資料表空間,但不允許 對該資料表空間的insert ,update,delete

5.)對該檔案做一個copy

$ cat 270 > /emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf

6.)為了確保 該file 的copy在 copy後沒有被使用,執行如下:
a) Take datafile offline    alter tablespace my_test offline;   Query the view v$datafile to verify the datafile is offline:   select status from v$datafile where file#=<file number>;b) Bring datafile back online     alter tablespace my_test online;

7.)將該資料表空間置為read write
alter tablespace my_test read write;
Query view dba_tablespaces to check status of the tablespace:
select tablespace_name,status from dba_tablespaces where tablespace_name='MY_TEST';
8.)對該資料檔案的resize操作就正常了。
SQL> alter database datafile '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' resize 250k;
Database altered.

注意:該過程也適用於找回被刪除的 current redo logfile
linux 檔案描述符最大是哪個?怎計算的?

檔案描述符是一個簡單的整數,用以標明每一個被進程所開啟的檔案和socket。第一個開啟的檔案是0,第二個是1,依此類推。Unix 作業系統通常給每個進程能開啟的檔案數量強加一個限制。更甚的是,unix 通常有一個系統級的限制。

os.chinaunix.net/....shtml
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.