Saturday, July 16, 2011

ASMCMD Command Line Tool in Oracle 1og

The ASMCMD tool is a command line utility that allows us to manage ASM instances and the disk structures and files within those instances. With ASMCMD we  can:
List contents of ASM disk groups
Perform searches (like directory listings)
Add or remove directories
Display space availability and utilization

Many of the commands in ASMCMD are UNIX like (i.e. ls, cd) and therefore the ASMCMD is fairly easy to learn how to use.

Starting ASMCMD
To start ASMCMD, set the ORACLE_SID to +ASM(in case of single instance) and then type ASMCMD from the command line as below :

C:\>Set ORACLE_SID=+ASM
C:\>ASMCMD


Or from UNIX:
/opt/oracle>export ORACLE_SID=+ASM
/opt/oracle>ASMCMD


When ASMCMD starts, we  will see the ASMCMD prompt as seen here:
1.ASMCMD>


we  can start ASMCMD with the –p option and it will display the directory level as shown below  :
C:\>ASMCMD -p
ASMCMD [+] >


ASMCMD Commands :    ASMCMD has a basic set of 12 commands in oracle 10.2g .We can see these commands from the ASMCMD prompt if we type  "help"  on the ASMCMD prompt .The logs are as below 
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


Now we will check each command on ASMCMD prompt. In my case , i have two diskgroup 'RATCAT' and 'SATMAT'.


1.) cd  –  Change directory : The cd command will move us in and out of ASM directory structures. This command works just like it's UNIX equivelent, and the special designators for previous directory ".." are available for use and use "+" to indicate the root (instead of a forward or backwards slash ( / or \)). Here are some examples:


C:\>asmcmd -p
ASMCMD [+] > cd +RATCAT        
ASMCMD [+RATCAT] > cd test1
ASMCMD [+RATCAT/test1] > cd test22
ASMCMD [+RATCAT/test1/test22] > cd ..
ASMCMD [+RATCAT/test1] > cd ..
ASMCMD [+RATCAT] > cd ..
ASMCMD [+] >


2.) du  –  Disk Used :   Display total space used for files located recursively under [dir],similar to "du -s" under UNIX; default is the current directory.  Two  values are returned, both in units of megabytes.  The first value does not take into account mirroring of the diskgroup while the second does. For instance, if a file occupies 100 MB of space, then it actually  takes up 200 MB of space on a normal redundancy diskgroup and 300 MB of space on a high redundancy diskgroup.


ASMCMD [+] > du
Used_MB        Mirror_used_MB
   2661                2661

3.)  find  –  Find a directory or file:    This command searches the specified directory and all subdirectories below it in the directory tree for the supplied name. name can be a directory name or a filename, and can include wildcard characters. dir may also include wildcards. In the output of the command, directory names are suffixed with the slash character (/) to distinguish them from filenames.


We use the -t flag to find all the files of a particular type (specified as type). For example, we can search for control files by specifying type as CONTROLFILE. Valid values for type are the following:

CONTROLFILE
DATAFILE
ONLINELOG
ARCHIVELOG
TEMPFILE
BACKUPSET
PARAMETERFILE
DATAGUARDCONFIG
FLASHBACK
CHANGETRACKING
DUMPSET
AUTOBACKUP
XTRANSPORT


ASMCMD [+ratcat] > find  +  datafile*
+RATCAT/NOIDA/DATAFILE/


ASMCMD [+ratcat] > find  +  system*
+RATCAT/NOIDA/DATAFILE/SYSTEM.256.755871363
+RATCAT/NOIDA/DATAFILE/SYSTEM.263.756485911


ASMCMD [+] > find  /  system*
+RATCAT/NOIDA/DATAFILE/SYSTEM.256.755871363
+RATCAT/NOIDA/DATAFILE/SYSTEM.263.756485911

4.)  help :  The help command provides the  help for all the ASMCMD commands. we can enter help, followed by the command name, for more detailed information on the command we are interested in.
  
ASMCMD [+] > help du


5.)  ls  :  The ls command is the list file command. This will list the directories and/or files contained within the ASM disk structure. Here are some examples of using the ls command:


ASMCMD [+] > ls
RATCAT/
SATMAT/


ASMCMD [+] > ls -l
State    Type    Rebal  Unbal  Name
MOUNTED  EXTERN  N      N      RATCAT/
MOUNTED  EXTERN  N      N      SATMAT/

6.)  lsct :  The lsct command lists all clients that are using ASM. we can specify a disk group to restrict the output or we can just allow the command to display all the clients. The output of the command displays the databases connected to the ASM instance, the version of the database connected. Also included is the compatible version of the database (set via the COMPATIBLE parameter setting) and the instance name of the instance connected to the ASM instance. Here is an example of the output from the lsct command:

ASMCMD [+] > lsct
DB_Name   Status        Software_Version  Compatible_version  Instance_Name
noida     CONNECTED           10.2.0.1.0          10.2.0.1.0           noida
noida     CONNECTED           10.2.0.1.0          10.2.0.1.0           noida


7.) lsdg : The lsdg command provides information on the disk groups that have been created in an ASM instance. This command returns a great deal of information about the disk group. Of particular interest is the free_MB column, which indicates how much space is available on the disk group. Here is an example of the output of the lsdg command:


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      9088     7043                0            7043              0  RATCAT/
MOUNTED  EXTERN  N      N         512   4096  1048576      9088     8362                0            8362              0  SATMAT/


8.) mkalias : Use the mkalias command to create ASM aliases for a given ASM file name. This command is equivalent to the alter diskgroup add alias command from the SQL prompt when connected to an ASM instance. Here is an example of using the mkalias to create an alias for an ASM file:


ASMCMD [+RATCAT/NOIDA/DATAFILE] > mkalias EXAMPLE.270.756485973 exam
ASMCMD [+RATCAT/NOIDA/DATAFILE] > ls
EXAMPLE.265.755871581
EXAMPLE.270.756485973
SYSAUX.257.755871363
SYSAUX.269.756485947
SYSTEM.256.755871363
SYSTEM.263.756485911
UNDOTBS1.258.755871365
UNDOTBS1.271.756485979
USERS.259.755871365
USERS.272.756485983
exam         ---------  alias
                                         Hence we find the aliases name as "exam" 


9.) mkdir :   Mkdir allows you to create ASM directories. we can not create a directory in the root directory (+), and we can create multiple directories at one time by simply listing them one at a time on the mkdir command line separated by spaces. This command is roughly equivalent to the alter diskgroup add directory command. Here are a couple of examples of using the mkdir command:


ASMCMD [+] > mkdir +RATCAT/asm


Here we can crosscheck it by using  "ls"  command


ASMCMD [+] > ls +RATCAT
NOIDA/
aa/
asm/           ----- new directory created
spfileTEST.ora
sysaux.f
test/
test1/


ASMCMD [+] > mkdir +RATCAT/asm1 +RATCAT/asm2 +RATCAT/asm3


Again we can crosscheck it by using "ls" command


ASMCMD [+] > ls +RATCAT/
NOIDA/
aa/
asm/
asm1/            ----->new directory created
asm2/            ----->
asm3/            ----->
spfileTEST.ora
sysaux.f
test/
test1/


10.)  pwd :   Use the pwd command to determine where in the ASM directory tree we  are. Here is an example:


ASMCMD [+RATCAT/NOIDA/DATAFILE] > pwd
+RATCAT/NOIDA/DATAFILE


In case of non-interactive mode, this is more helpful


ASMCMD> pwd
+RATCAT/NOIDA/DATAFILE


11.)  rm  :   The rm command is used to remove ASM directories or files. The rm command will only remove a directory if that directory is empty. This is equivalent to the alter diskgroup drop directory command. Here is an example of removing a directory with the rm command:


ASMCMD> ls
NOIDA/
aa/
asm/
asm1/
asm2/
asm3/
spfileTEST.ora
sysaux.f
test/
test1/


ASMCMD> rm asm


ASMCMD> ls
NOIDA/
aa/
asm1/
asm2/
asm3/
spfileTEST.ora
sysaux.f
test/
test1/


The rm command is also used to remove ASM files and associated aliases. This is equivalent to the alter diskgroup drop file command. 


we can use the "*" wildcard character with the rm command too. If we use the wildcard character, Oracle will warn us to make sure that we truly want to remove the file. Here is an example


ASMCMD> rm asm*
You may delete multiple files and/or directories.
Are you sure? (y/n) y


ASMCMD> ls
NOIDA/
aa/
spfileTEST.ora
sysaux.f
test/
test1/

12.) rmalias  :  The rmalias command is used to remove ASM aliases .


ASMCMD [+RATCAT/NOIDA/DATAFILE] > ls
EXAMPLE.265.755871581
EXAMPLE.270.756485973
SYSAUX.257.755871363
SYSAUX.269.756485947
SYSTEM.256.755871363
SYSTEM.263.756485911
UNDOTBS1.258.755871365
UNDOTBS1.271.756485979
USERS.259.755871365
USERS.272.756485983
exam


ASMCMD [+RATCAT/NOIDA/DATAFILE] > rmalias exam
ASMCMD [+RATCAT/NOIDA/DATAFILE] > ls
EXAMPLE.265.755871581
EXAMPLE.270.756485973
SYSAUX.257.755871363
SYSAUX.269.756485947
SYSTEM.256.755871363
SYSTEM.263.756485911
UNDOTBS1.258.755871365
UNDOTBS1.271.756485979
USERS.259.755871365
USERS.272.756485983


There are further more new features and commands are added in ASM oracle 11g.I will cover it later on.


Enjoy   :-) 

No comments: