Asmcmd

From Oracle FAQ
⧼orafaq-jumptonavigation⧽⧼orafaq-jumptosearch⧽

ASMCMD is a utility that can be used to manage ASM (Automatic Storage Management) diskgroups. This utility uses familiar Unix-style filesystem commands to view and manage ASM files and directories.

In Oracle 10g Release 1, ASM could only be administered through SQL commands or the Enterprise Manager (EM) GUI. For example, to list the diskgroups one would typically open EM or connect to sqlplus and issue a SELECT against some V$ASM_* views (like V$ASM_DISKGROUP and V$ASM_DISK). This utility allows people that is not familiar with SQL to view and manage ASM without opening any GUI tools.

History

ASM was first released with Oracle 10g Release 2.

Under the covers

Asmcmd is implemented as a shell script that starts a Perl program called asmcmdcore. If you are a Perl programmer, you can easily extend this script to add additional commands and security checks.

Start asmcmd

The ASM Command Line Utility can be started by executing the asmcmd command. Here is a Linux/Unix example:

$ export ORACLE_SID=+ASM
$ cd $ORACLE_HOME/bin
$ asmcmd
ASMCMD> exit
$

The asmcmd utility also provides a useful "-p" option that will display the current path in the prompt. Here is an example:

$ asmcmd -p
ASMCMD [+] > cd FLASH
ASMCMD [+FLASH] >

Asmcmd commands

Some of the more interesting commands are described below -

Getting some help:

ASMCMD> help

Help for a spesific command:

ASMCMD> help ls

Navigating through the structure using "cd", "ls" and "pwd" commands:

ASMCMD> ls -l
State    Type    Rebal  Unbal  Name
MOUNTED  EXTERN  N      N      DISKGROUP1/
MOUNTED  EXTERN  N      N      FLASH/
ASMCMD> cd DISKGROUP1
ASMCMD> ls -l
Type  Redund  Striped  Time             Sys  Name
                                        Y    SALES/
ASMCMD> cd SALES
ASMCMD> ls -l
Type           Redund  Striped  Time  Sys  Name
                                      Y    CONTROLFILE/
                                      Y    DATAFILE/
                                      Y    ONLINELOG/
                                      Y    PARAMETERFILE/
                                      Y    TEMPFILE/
                                      N    spfilesales.ora =>  +DISKGROUP1/SALES/PARAMETERFILE/spfile.268.569267897
ASMCMD> cd DATAFILE
ASMCMD> pwd
+DISKGROUP1/SALES/DATAFILE

Find files:

ASMCMD> find / spfile*
+DISKGROUP1/SALES/PARAMETERFILE/spfile.268.569267897
+DISKGROUP1/SALES/spfilesales.ora

List all connected instances:

ASMCMD> lsct
DB_Name   Status        Software_Version  Compatible_version  Instance_Name
sales     CONNECTED           10.2.0.1.0          10.2.0.1.0  sales1
sales     CONNECTED           10.2.0.1.0          10.2.0.1.0  sales2

List all diskgroups:

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     11264     9885                0            9885              0  DISKGROUP1/
MOUNTED  EXTERN  N      N         512   4096  1048576     10240     9906                0            9906              0  FLASH/

Check used space:

ASMCMD> du
Used_MB      Mirror_used_MB
   1523                1523

Delete files (be careful!!!):

ASMCMD> rm *
Are you sure? (y/n) y

Metadata (ASM superblocks) backup and recovery (Oracle 11g and above):

ASMCMD> md_backup –b /tmp/dg.backup –g DATA –g RECOVER
ASMCMD> md_restore –t full –g RECOVER /tmp/dg.backup

Also see

  • ASM - Automatic Storage Management
  • ASM FAQ - See FAQ about asmcmd being slow.