One of the features of ASM is databases consolidation. A single diskgroup will be the repository for multiple databases. The result, having a large number of datafiles. If the files were created using OMF (Oracle Managed Files) format, when the datafile is deleted on the database side, it is also deleted on the ASM side. There may be situations when the datafiles are not deleted on the ASM side, particularly when not using OMF format.
With large diskgroups holding large number of datafiles it is necessary to make good usage of the storage and reclaim space allocated for files not used by the databases.
The following script will provide the list of files stored in ASM and CURRENTLY NOT OPENED by any database client of the diskgroups. It is very important to validate the results of the query, particularly for files that could have been marked temporary offline. It does not apply to READ ONLY tablespaces, because once the file is opened by the database, it will be returned by the query.
Note: The parameter file (spfile) will be reported always as not opened. Always double check the file before deleting it.
- The query has to be executed on the ASM instance.
- Diskgroups need to be mounted.
None. Download the script and execute on the ASM instance
$ sqlplus '/ as sysdba'
sql>@files_not_opened
This script is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this script before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this script may not be in an executable state when you first receive it. Check over the script to ensure that errors of this type are corrected.
The following code can be downloaded here
setpagesize0
setlinesize200
colfull_alias_pathformata80
/*+----------------------------------------------------------------
QuerywillreturnallthefilesstoredonASMbutnotcurrently
openedbyanydatabaseclientofthediskgroups
orderedbygroupnumber,filetype
---------------------------------------------------------------*/
select*from(
/*+-----------------------------------------------------------------
1stbranchreturnsallthefilesstoredonASM
-----------------------------------------------------------------*/
selectx.gnum,x.filnum,x.full_alias_path,f.ftypefrom(
SELECTgnum,filnum,concat('+'||gname,sys_connect_by_path(aname,'/'))full_alias_path
FROM(SELECTg.namegname,a.parent_indexpindex,a.nameaname,
a.reference_indexrindex,a.group_numbergnum,a.file_numberfilnum
FROMv$asm_aliasa,v$asm_diskgroupg
WHEREa.group_number=g.group_number)
STARTWITH(mod(pindex,power(2,24)))=0CONNECTBYPRIORrindex=pindex)x,
(selectgroup_numbergnum,file_numberfilnum,typeftypefromv$asm_fileorderbygroup_number,file_number)f
wherex.filnum!=4294967295
andx.gnum=f.gnumandx.filnum=f.filnum
MINUS
/*+--------------------------------------------------------------
2ndbranchreturnsallthefilesstoredonASM
andcurrentlyopenedbyanydatabaseclientofthediskgroups
-----------------------------------------------------------------*/
selectx.gnum,x.filnum,x.full_alias_path,f.ftype
from(selectid1gnum,id2filnumfromv$lockwheretype='FA'and (lmode=4 or lmode=2))l,
(
SELECTgnum,filnum,concat('+'||gname,sys_connect_by_path(aname,'/'))full_alias_path
FROM(SELECTg.namegname,a.parent_indexpindex,a.nameaname,
a.reference_indexrindex,a.group_numbergnum,a.file_numberfilnum
FROMv$asm_aliasa,v$asm_diskgroupg
WHEREa.group_number=g.group_number)
STARTWITH(mod(pindex,power(2,24)))=0CONNECTBYPRIORrindex=pindex
)x,
(selectgroup_numbergnum,file_numberfilnum,typeftypefromv$asm_fileorderbygroup_number,file_number)f
wherex.filnum!=4294967295and
x.gnum=l.gnum andx.filnum=l.filnum andx.gnum=f.gnumandx.filnum=f.filnum)q
orderbyq.gnum,q.ftype;
The key of this sql is the reference to v$lock view. For any file stored on ASM and opened by a database instance, there will be an entry on v$lock:
Column |
Description |
type |
The enqueue name is FA (File Access) |
ID1 |
For this enqueue, represents the diskgroup number |
ID2 |
For this enqueue, represents the ASM file number |
mode |
If the file is opened, mode will be 4 (Shared) for 10g, and 2 (row S) for 11g |
The first branch of the main query will return ALL the ASM files stored on the diskgroup
The second branch of the main query will return all the ASM files currently opened by any database.
The query finally will return the files stored on ASM but not present on the second query (MINUS), which basically will be the files not currently opened.
This is the first example of the results of the execution of the script. Note it includes all type of files like ARCHIVELOGS, FLASHBACK LOGS, REDOLOGS. Once it has been confirmed the files are not required any more, then they can be deleted using ASMCMD or SQL running the command ALTER DISKGROUP ... DROP FILE '<path>';
GNUMFILNUMFULL_ALIAS_PATH
------------------------------------------------------------------------------------------
1270+DATA1/G102/ONLINELOG/group_2.270.645209903
13247+DATA1/G102/ARCHIVELOG/2008_01_30/thread_2_seq_54.3247.645369463
13249+DATA1/G102/ARCHIVELOG/2008_01_30/thread_1_seq_59.3249.645367259
13250+DATA1/G102/FLASHBACK/log_104.3250.645367249
13251+DATA1/G102/FLASHBACK/log_103.3251.645369221
13252+DATA1/G102/ARCHIVELOG/2008_01_30/thread_1_seq_58.3252.645367197
13254+DATA1/G102/ARCHIVELOG/2008_01_30/thread_2_seq_53.3254.645369095
13255+DATA1/G102/ARCHIVELOG/2008_01_30/thread_1_seq_57.3255.645366969
13256+DATA1/G102/ARCHIVELOG/2008_01_30/thread_2_seq_52.3256.645368439
13257+DATA1/G102/ARCHIVELOG/2008_02_04/thread_2_seq_59.3257.645786351
13258+DATA1/G102/FLASHBACK/log_13.3258.645786863
As mentioned before, it is extremely important to review the results of the script. In this following example, these datafiles are not currently opened but they belong to a database currently closed.
GNUMFILNUMFULL_ALIAS_PATH
------------------------------------------------------------------------------------------
2256+DG_NETAPPS/V102/DATAFILE/UNDOTBS2.256.643467013
2257+DG_NETAPPS/NETAPP/DATAFILE/SYSTEM.257.643477635
2258+DG_NETAPPS/NETAPP/DATAFILE/SYSAUX.258.643477637
2259+DG_NETAPPS/NETAPP/DATAFILE/UNDOTBS1.259.643477641
2260+DG_NETAPPS/NETAPP/DATAFILE/USERS.260.643477643
2261+DG_NETAPPS/NETAPP/CONTROLFILE/Current.261.643478451
2262+DG_NETAPPS/NETAPP/ONLINELOG/group_1.262.643478461
2263+DG_NETAPPS/NETAPP/ONLINELOG/group_2.263.643478517
2264+DG_NETAPPS/NETAPP/ONLINELOG/group_3.264.643478569
2265+DG_NETAPPS/NETAPP/TEMPFILE/TEMP.265.643478655
2266+DG_NETAPPS/NETAPP/PARAMETERFILE/spfile.266.643478737
2266+DG_NETAPPS/NETAPP/spfilenetapp.ora
2267+DG_NETAPPS/NETTEST/DATAFILE/UNDOTBS1.267.643723749
From Oracle
-------------------------------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
Email: [email protected]
DBA1 群:62697716(满); DBA2 群:62697977(满) DBA3 群:62697850(满)
DBA 超级群:63306533(满); DBA4 群: 83829929 DBA5群: 142216823
聊天 群:40132017 聊天2群:69087192
--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请