Systems Engineering and RDBMS

ASMCMD

Posted by decipherinfosys on March 9, 2009

Oracle introduced ASM (Automatic storage management) in Oracle release 10g.  Since its introduction in 10g, it remains Oracle’s recommended approach for file creation, storage and maintenance. It also serves as a volume manager. The idea behind the ASM is simplicity in managing database files, reduction in administration tasks and ease of operations.

ASM has its own instance similar to regular database instance except it has a smaller footprint. Basic difference is that the ASM instance mounts the disk groups. It cannot mount the databases. Disk groups are nothing but a collection of disks which Oracle uses as a single unit. It uses these disk groups to store data files. It can contain multiple files and files from the different databases but a single file can only belong to single disk group.

In its debut release 1 (10.1), it didn’t have any command line interface to manage the disk groups, files etc. It can be managed though through SQL*Plus and/or enterprise manager. In release 2 (10.2), Oracle introduced asmcmd (command line tool to perform day to day routine tasks to manage disk groups, ASM files etc.) With this little introduction, let us see how we can use asmcmd.

In order to use asmcmd, we have to set two environment variables. ORACLE_HOME and ORACLE_SID. If ORACLE_HOME is not set, Oracle complains about ORACLE_HOME not being set. If ORACLE_SID is not set then it gives following error.

ASMCMD-08103: failed to connect to ASM; ASMCMD running in non-connected mode

Let us start with setting up above two environment variables.

C:\>set ORACLE_SID=+ASM
C:\>set ORACLE_HOME=C:\oracle\product\11.1.0

We can invoke asm command line tool in two ways.

C:\>asmcmd
ASMCMD>

Or with –p flag which will display present directory inside of prompt it self.

C:\>asmcmd -p
ASMCMD [+] >

One thing to remember is that user making connection should be part of sysdba group. Once you are in the utility, supported command are pretty much same as Unix commands.

ls –l command lists the disk group directories when issued just after making connection. Once you navigate through directories, it will display other files and directories.

ASMCMD [+] > ls -l
State    Type    Rebal  Name
MOUNTED  NORMAL  N      DB9_DATA01/
MOUNTED  EXTERN  N      DB9_STR01/
MOUNTED  EXTERN  N      DB9_TRANSIENT01/

Once we drill down to specific directory, this is what we will see.

ASMCMD [+] > cd db9_data01/orcl
ASMCMD [+db9_data01/orcl] > ls -l
Type  Redund  Striped  Time  Sys  Name
Y    CONTROLFILE/
Y    DATAFILE/
Y    ONLINELOG/
Y    PARAMETERFILE/
Y    TEMPFILE/
N    spfileorcl.ora => +DB9_DAT
A01/ORCL/PARAMETERFILE/spfile.266.680772343

Moving it one folder down, we can see actual files.

ASMCMD [+db9_data01/orcl/datafile] > ls -l
Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAR 06 09:00:00  Y    EXAMPLE.265.680771705
DATAFILE  MIRROR  COARSE   MAR 06 09:00:00  Y    SYSAUX.257.680771171
DATAFILE  MIRROR  COARSE   MAR 06 09:00:00  Y    SYSTEM.256.680771169
DATAFILE  MIRROR  COARSE   MAR 06 09:00:00  Y    UNDOTBS1.258.680771225
DATAFILE  MIRROR  COARSE   MAR 06 09:00:00  Y    USERS.259.680771255

To display all the disk groups, we can use lsdg command.

ASMCMD [+] > lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_
MB  Usable_file_MB  Offline_disks  Name
MOUNTED  NORMAL  N         512   4096  1048576      4096      630             10
24            -197              0  DB9_DATA01/
MOUNTED  EXTERN  N         512   4096  1048576      1024      789
0             789              0  DB9_STR01/
MOUNTED  EXTERN  N         512   4096  1048576      1024      974
0             974              0  DB9_TRANSIENT01/

For listing OS level directory structure path use lsdsk command. This is new in 11g.

ASMCMD [+] > lsdsk
Path
C:\ORACLEASM\DB9DATA01
C:\ORACLEASM\DB9DATA01M
C:\ORACLEASM\DB9DATA02
C:\ORACLEASM\DB9DATA02M
C:\ORACLEASM\DB9STR01
C:\ORACLEASM\DB9TRANS01

Another command is mkdir (to make new directory) and rm (common for both removing directory and file). This works when we are already navigated to disk group directory as shown below.

ASMCMD [+] > cd db9_data01
ASMCMD [+db9_data01] > mkdir testgrp
ASMCMD [+db9_data01] > cd testgrp
ASMCMD [+db9_data01/testgrp] > ls -l
ASMCMD [+db9_data01/testgrp] > cd ..
ASMCMD [+db9_data01] > rm testgrp

If we try to issue mkdir command from root ‘ASMCMD [+]’ it will give following error.

ASMCMD [+] > mkdir testgrp
ORA-15032: not all alterations performed
ORA-15001: diskgroup “+” does not exist or is not mounted (DBD ERROR: OCIStmtExe
cute)

Some other supported commands are

help
cp – new in 11g
find
mkalias
pwd
rmalias
md_backup – new in 11g
md_restore – new in 11g
remap – new in 11g.

For complete explanation of all these commands, refer to Oracle storage administrator guide. You can follow the link given in resource section below.

Resources:

  • Otn article – here.
  • Tech Repbulic article – here.
  • Oracle Storage Administrator guide – here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: