Oracle Database 10g Release 2
offers an ASM command-line interface (ASMCMD) utility to access and manage
files from a command prompt. Earlier versions have to use SQL*Plus or OEM to
manage ASM.
Some examples
of this command line Interface.
$ asmcmd
asmcmd: command disallowed by current instance type
# ORACLE_SID is wrong
$ echo $ORACLE_SID
ORCL
$ export ORACLE_SID=+ASM1
$ asmcmd
ASMCMD>
Identifying
Diskgroups using ASMCMD:
ASMCMD> lsdg
State Type Rebal Unbal Sector Block
AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Name
MOUNTED EXTERN
N N 512 4096 1048576 122876 46775 0 46775 0 DATABASE_DG/
ASMCMD> lsct
DB_Name Status Software_Version Compatible_version Instance_Name
ORCL CONNECTED 10.2.0.1.0 10.2.0.1.0 ORCL1
Identifying
data files using ASMCMD:
ASMCMD> cd +DATABASE_DG/qprv
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
devices_01.dbf
operations_01.dbf
users01.dbf
Finding
out where controlfile is located on ASM:
ASMCMD> cd CONTROLFILE/
ASMCMD> ls
Current.260.563388683
Current.261.563388685
Current.262.563388685
Reclaiming
Disk space using ASMCMD :
Let us
assume you have three node RAC instances. Assume your database archive logs and
backup sets are located on ASM storage. When you find that obsolete database
archive logs and backups are taking up the ASM space and want delete them to reclaim
space in ASM, do the following.
ASMCMD > CD +BACKUPDEST # change to the disk group
ASMCMD > PWD # current directory
ASMCMD > find . -t BACKUPSET.* # to find out backupset files in the diskgroup
Once
the files have been listed, you can use the operating system rm command to
delete them and use RMAN to crosscheck the backups that you have deleted.
Please
note that -- the -t flag can have values like DATAFILE, ARCHIVELOG,
CONTROLFILE, ONLINELOG
ASMCMD> help
asmcmd [-p] [command]
The environment variables ORACLE_HOME and ORACLE_SID determine
the instance to which the program connects, and ASMCMD establishes
a bequeath connection to it, in the same manner as a SQLPLUS / AS SYSDBA.
The user must be a member of the SYSDBA group.
Specifying the -p option allows the current directory to be displayed
in the command prompt, like so:
ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >
[command] specifies one of the following commands, along with its parameters.
Type "help [command]" to get help on a specific ASMCMD command.
Commands:
--------
cd
du
find
help
ls
lsct
lsdg
mkalias
mkdir
pwd
rm
rmalias
10g R2 offers more flexibility moving
Files between and within databases: The preferred way of doing the file
movement among ASM DISKGROUPS is using RMAN. RMAN is critical to Automatic
Storage Management and is responsible for tracking the ASM filenames and for
deleting obsolete ASM files. Since ASM files cannot be accessed through normal
operating system interfaces, RMAN is the preferred means of copying ASM file.
However, in some cases, you may want to move files from a remote database server
that does not use RMAN or to setup datagaurd; in these cases, we have the DBMS
package called DBMS_FILE_TRANSFER. 10g R2 supports ASM to OS file AND OS File
to ASM using this package. Earlier versions of 10G already support between ASM
to ASM and OS to OS transfer of files.
Using this feature, a DBA can move data files from
within Oracle without 'physically' logging into the operating system
itself. This feature provides one more option when doing common
database administrative tasks such as simple storage management, where we need
to free up space on a disk. Let us see in the below example how we
can move an ASM file to OS directory.
SQL> select tablespace_name,file_name from dba_Data_files;
TABLESPACE_NAME
------------------------------
FILE_NAME
------------------------------------------------------------------------------------------------------------------------
USERS
+DATABASE_DG/qprv/users01.dbf
SYSAUX
+DATABASE_DG/qprv/sysaux01.dbf
UNDOTBS1
+DATABASE_DG/qprv/undotbs01.dbf
SYSTEM
+DATABASE_DG/qprv/system01.dbf
UNDOTBS2
+DATABASE_DG/qprv/undotbs02.dbf
DEVICES
+DATABASE_DG/qprv/devices_01.dbf
SERVICES
+DATABASE_DG/qprv/services_01.dbf
OPERATIONS
+DATABASE_DG/qprv/operations_01.dbf
BBIDS_TBS
+DATABASE_DG/qprv/bbids_tbs_01.dbf
USERS
+DATABASE_DG/qprv/users02.dbf
TEST
+DATABASE_DG/qprv/test.dbf
11 rows selected.
SQL> create or replace directory oracle_10g as '+DATABASE_DG/qprv/';
Directory created.
SQL> grant read,write on directory oracle_10g to ram;
Grant succeeded.
SQL> create or replace directory oracle_dest as '+db04/oradata/qprv/';
Directory created.
SQL> grant read,write on directory oracle_dest to ram;
Grant succeeded
SQL> ALTER DATABASE DATAFILE '+DATABASE_DG/qprv/test.dbf'
offline;
Database altered.
Now
copy the file from the source ASM diskgroup to a normal OS filesystem directory.
BEGIN
DBMS_FILE_TRANSFER.COPY_FILE(
source_directory_object => 'ORACLE_10G',
source_file_name => test.dbf,
destination_directory_object => 'ORACLE_DEST',
destination_file_name => 'TEST.DBF);
END;
Database altered