Monday, May 19, 2008

ASM Command-Line Utility (ASMCMD)

ASM Command-Line Utility (ASMCMD)
ASMCMD is a comman-line utility that helps us to view,manage,manipulate,perform search,display space utilization of files and directories within ASM disk groups.

Can ASMCMD be used to manipulate the disks in a disk group?

No. We can't use ASMCMD to manipulate disks in a disk group. Manipulation includes operations such as addition and deletion of disks in a disk group/creating and dropping of disk groups. We can use SQL commands for that purpose.

What is a system-generated filename?

A system-generated file name is also called as fully qualified filename.

Every file created in ASM gets this system-generated name.

This is same as the complete path name in normal file system.(say $ORACLE_HOME=/u01/app/product/oracle/...)

Does fully qualified filename/system generated filename follow any standard?

Yes.Fully qualified filename follows the following standard:

+diskGroupName/databaseName/fileType/fileTypeTag.fileNumber.incarnation

Example:

+dgroup6/sample/CONTROLFILE/Current.256.541952343

In this example,
dgroup6 - diskgroup
sample - database
CONTROLFILE - type of file
current - file type tag
256 - file number
541952343 - incarnation

ASMCMD supports only forward slash(\).

Filenames are not case sensitive.

What is an ASM directory?

An ASM directory is a container of files.It is same as directories in file system.An ASM directory is autogenerated.A plus sign(+) represents a root directory.A fully qualifiedname or a system-generated name represents a hierarchy of directories.

An ASM automatically generates directories for files in fully qualified name and these directories are called as system-generated directories.

Following ASM commands can be used to manage these directories:
cd - move up and down between these directories
pwd - prints the name of the current directory
ls - lists the contents of the current directory
mkdir - We can create our own directories as sub-directories of system-generated directories(Note:ALTER DISKGROUP command can be used for the same purpose)
mkalias - create file alias

An ASM directory can be a part of the tree structure of other directories.

What is the use of -p option of ASMCMD?

We can start ASMCMD with -p option(ASMCMD -p) to include current directory as a part of ASMCMD prompt.

What is an alias?

Aliases are filenames that are pointers or references to system-generated filenames.They are user-friendly and are same as symbolic names in UNIX/Linux.They are used to simplify filename administration.Following commands can be used to create aliases:

mkalias,ALTER DISKGROUP with ADD ALIAS clause :

Syntax:

ALTER DISKGROUP dgroup1 ADD ALIAS '(aliasname)'
FOR '(system-generated filename of file)';

We can create alias:

1) At system-generated subdirectory
2) At user-generated subdirectory
3) At disk group level

An alias name has at minimum diskgroup as a part of its filename.

To get the system-generated file name and its alias use the following ASMCMD command:

ls -l

What is the difference between absolute path and relative path?

An absolute path is the system-generated filename that starts from the name of a diskgroup(+).A relative pathname specifies path relative to present working directory.Say a user is in diskgroup(+dgroup1),the relative path can be sample/CTLFILE/CURRENT.123.2345678.

What is a pseudo-directory?

A pseudo-directory is a name that can be specified along with the cd command. They are:
. - current working directory (single-dot)
.. - parent directory of the current directory(two dots without space)

What is a wildcard character?

The characters '*' and '%' are referred to as wildcard characters that match zero or more characters within an absolute or relative path ,which saves typing of full directory or filename.Both these characters behave identically.ASMCMD commands that accept wildcard characters are cd, du, find, ls, lsdsk, and rm.
Running ASMCMD Utility
ASMCMD utility can be run in interactive and non-interactive mode. We need certain preparations before running ASMCMD utility.

Preparation before running ASMCMD utility :

Check the following before running the ASMCMD utility.

1) Check that ASM instance is started and disk groups are mounted.
2) Loginto host in which ASM instance is running.We must login as an user with SYSASM or SYSDBA system privileges through Operating system(OS) authentication.SYSASM is the preferred connection privilege.
3) Set the ORACLE_HOME and ORACLE_SID variables to refer to the ASM instance.
4) Set the operating system variables correctly to connect to the ASM instance.
5) The default value of ASM SID in a single instance database is +ASM.In case of a oracle RAC environment the value of ASM SID is +ASMnode#
6) Ensure that PATH variable is set properly.Issue echo $PATH command to check if bin directory of the ORACLE_HOME is in $PATH.

Running ASMCMD in Interactive-mode :

The interactive mode of the ASMCMD utility provides a shell-like environment where we are prompted to enter ASMCMD commands.

1. Enter the following at the operating system command prompt:
asmcmd
Oracle displays an ASMCMD command prompt as follows:
ASMCMD>
2. Enter an ASMCMD command and press Enter. The command runs and displays its output, if any, and then ASMCMD prompts for the next command.
3. Continue entering ASMCMD commands. Enter the command exit to exit ASMCMD.

We can specify the -v option when starting asmcmd to displays the asmcmd version number. After displaying the version number, asmcmd immediately exits.

$ asmcmd -v
asmcmd version 11.1.0.3.0

We can specify the -a option to choose the type of connection, either SYSASM or SYSDBA. The default value is SYSASM.

$ asmcmd -a sysasm

Running ASMCMD in Non-interactive Mode:

This mode is useful is automating the process using scripts. The format is asmcmd (command) (option),where command is the ASMCMD command to be run and option is the option with which the command has to be run.

For example asmcmd ls -l invokes asmcmd in non-interactive mode and lists the files in current directory along with its alias.

No comments: