首頁 資料庫 mysql教程 【翻译自mos文章】在unix/linux中使用文件描述符(FileDescripto

【翻译自mos文章】在unix/linux中使用文件描述符(FileDescripto

Jun 07, 2016 pm 03:59 PM
linux unix 使用 文件 文章

在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

在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 tablespace
SQL> 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 datafile
SQL> 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 ''| grep ''
$ 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.dbf

Command 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/ / '/

$ 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
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1321
25
PHP教程
1269
29
C# 教程
1249
24
Linux體系結構:揭示5個基本組件 Linux體系結構:揭示5個基本組件 Apr 20, 2025 am 12:04 AM

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

git怎麼查看倉庫地址 git怎麼查看倉庫地址 Apr 17, 2025 pm 01:54 PM

要查看 Git 倉庫地址,請執行以下步驟:1. 打開命令行並導航到倉庫目錄;2. 運行 "git remote -v" 命令;3. 查看輸出中的倉庫名稱及其相應的地址。

vscode上一步下一步快捷鍵 vscode上一步下一步快捷鍵 Apr 15, 2025 pm 10:51 PM

VS Code 一步/下一步快捷鍵的使用方法:一步(向後):Windows/Linux:Ctrl ←;macOS:Cmd ←下一步(向前):Windows/Linux:Ctrl →;macOS:Cmd →

notepad怎麼運行java代碼 notepad怎麼運行java代碼 Apr 16, 2025 pm 07:39 PM

雖然 Notepad 無法直接運行 Java 代碼,但可以通過借助其他工具實現:使用命令行編譯器 (javac) 編譯代碼,生成字節碼文件 (filename.class)。使用 Java 解釋器 (java) 解釋字節碼,執行代碼並輸出結果。

sublime寫好代碼後如何運行 sublime寫好代碼後如何運行 Apr 16, 2025 am 08:51 AM

在 Sublime 中運行代碼的方法有六種:通過熱鍵、菜單、構建系統、命令行、設置默認構建系統和自定義構建命令,並可通過右鍵單擊項目/文件運行單個文件/項目,構建系統可用性取決於 Sublime Text 的安裝情況。

laravel安裝代碼 laravel安裝代碼 Apr 18, 2025 pm 12:30 PM

要安裝 Laravel,需依序進行以下步驟:安裝 Composer(適用於 macOS/Linux 和 Windows)安裝 Laravel 安裝器創建新項目啟動服務訪問應用程序(網址:http://127.0.0.1:8000)設置數據庫連接(如果需要)

Linux的主要目的是什麼? Linux的主要目的是什麼? Apr 16, 2025 am 12:19 AM

Linux的主要用途包括:1.服務器操作系統,2.嵌入式系統,3.桌面操作系統,4.開發和測試環境。 Linux在這些領域表現出色,提供了穩定性、安全性和高效的開發工具。

git軟件安裝 git軟件安裝 Apr 17, 2025 am 11:57 AM

安裝 Git 軟件包括以下步驟:下載安裝包運行安裝包驗證安裝配置 Git安裝 Git Bash(僅限 Windows)

See all articles