Thursday 6 October 2016

Linux: I've deleted my file , but it is still in use?? lsof to the rescue

Example:

[steaua@MYDB]/u01/app/oracle/users/Florin >lsof |grep oradata |grep deleted
oracle     4028    oracle  300u      REG             253,69     2105344     49160 /oradata/ora_data05/refusg_MYDB_02.dbf (deleted)

How to find the objects/extents residing on a specific datafile?

This can be useful, for example, if we want to drop a datafile, and it has to be empty in order to do this.

How can we check what objects are there in a datafile?

select distinct a.owner,a.segment_name
from dba_extents a,dba_data_files b
where a.file_id=b.file_id and b.file_name=<your datafile name with path>;

Note: the query above is usually very slow, since it has to full scan a few big fixed tables.