[Translated from mos] in unix/linux, how does one delete a shard by using a File descriptor (File Descriptors) to retrieve the deleted File (Data File or redo log )?
Use File Descriptors in unix/linux to retrieve deleted files (Data Files or redo logs)
Reference Original:
Retrieve deleted files on Unix/Linux using File Descriptors (Doc ID 444749.1)
Applicable:
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 iSCSI (64-bit)
Linux x86-64
* ** Checked for relevance on 24-Nov-2010 ***
Objective: To retrieve the deleted datafile and logfile from the operating system without the database being restarted
Solution:
When the following conditions are met, we can use the proc file system in unix/linux to retrieve the deleted datafile and logfile
1.) Database is not restarted.
2.) Server is not restarted.
3.) The file was not offline before deletion.
The background process (DBWR, PMON, SMON etc) accesses all datafiles opened by the database. Therefore, the list of files opened by the process can be seen through the lsof command.
Any file opened by a process has a file descriptor (fd) associated with the file. If the file is accidentally deleted from the operating system, the entry of the file is not deleted from the proc file system, we can recreate the deleted file (datafile or logfile)
The following is an example:
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
Procedure
1) Find the OS pid OF THE dbwr Process
--> $ 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) use the lsof command to find the opened file for the 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
Note:
If you are using NAS then the file name in the above command may not be displayed properly and hence this procedure shocould not be used under these circumstances.
Note that the above fd value is -- 270
3) to the fd directory
--> $ Cd/proc/<process_id>/<file_descriptor_directory> '/
$ Cd/proc/21943/fd/
4.) read the tablespace only
alter tablespace my_test read only;
The tablespace is set to read only to freeze the file header to prevent File Header updates. When the database is open, the file can be copied only when the datafile is read only.
Read only allows you to select the tablespace, but does not allow insert, update, delete operations on the tablespace.
5) copy the file.
$ Cat 270>/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf
6.) to ensure that the file copy is not used after the copy operation, run the following command:
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.) set the tablespace To 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.) The resize operation on the data file is normal.
SQL> alter database datafile '/emea/rdbms/64bit/app/oracle/oradata/EMR102U6/my_test_01.dbf' resize 250 k;
Database altered.
Note: This process can also be used to retrieve the deleted current redo logfile.
What is the maximum file descriptor in linux? How is it calculated?
A file descriptor is a simple integer used to indicate the files and sockets opened by each process. The first open file is 0, the second is 1, and so on. A Unix operating system usually imposes a limit on the number of files that can be opened by each process. What's more, unix usually has a system-level limit.
OS .chinaunix.net/...shtml