Professional Documents
Culture Documents
1) To Bottom
In this Document
Purpose
Scope
Details
References
APPLIES TO:
Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.1 [Release 10.1 to 11.2]
Information in this document applies to any platform.
***Checked for relevance on 30-Apr-2010***
PURPOSE
Oracle database 10gR2 provides two new options to access and manage Automatic Storage
Management (ASM) files and related information via command line interface - asmcmd and
ASM ftp. This article will talk about asmcmd and provide sample Linux shell script to
demonstrate the asmcmd in action.
SCOPE
asmcmd can be used by Oracle database administrators to query and manage their ASM systems.
Oracle Support Services engineers can use asmcmd to easily retrieve ASM related info for
diagnosing and debugging purposes.
asmcmd can be used against ASM versions 10gR1 (10.1.0.n) and 10gR2 (10.2.0.n). In ASM
version 10.2 asmcmd is provided by default ASM installation.
To use asmcmd in ASM version 10.1 environment we can just copy relevant files from 10.2
installation into the 10.1 environment as follows.
Linux/UNIX:
Copy/ftp asmcmd and asmcmdcore from 10.2 install into 10.1 $ORACLE_HOME/bin , where
$ORACLE_HOME is the oracle home where ASM is installed. These two files should be owned
by the oracle user and the dba group, and have the following permissions:
asmcmd: 550
asmcmdcore: 440
Windows:
Copy/ftp asmcmd.bat and asmcmdcore from 10.2 install into %ORACLE_HOME%\bin, where
%ORACLE_HOME% is the oracle home where ASM is installed.
DETAILS
find Lists the paths of all occurrences of the specified name (with
wildcards) under the specified directory.
rmalias Deletes the specified alias, retaining the file that the alias
points to.
#
# Parse command line arguments
#
while [ $# -gt 0 ]
do
case $1 in
-db) shift; DBNAME=$1;; # Database name
-space) SPACE=TRUE;; # User wants the space usage report
-files) FILES=TRUE;; # User wants the report on all files in db DBNAME
-help) echo "Usage: asm.sh [-db DBNAME] [-space] [-files]";exit 1;;
esac;
shift
done
echo ""
#
# Get all ASM disk groups using the 'asmcmd ls' command
#
if [ -s /tmp/groups$$ ]
then
echo "ASM instance $ORACLE_SID manages the following disk group(s):"
echo "=================================="
cat /tmp/groups$$
echo ""
else
echo "There are no disk groups in the ASM instance $ORACLE_SID"
echo ""
exit 2
fi
#
# If -files was specified, report on all files for database DBNAME
#
if [ $FILES ]
then
if [ $DBNAME ]
then
for GRP in `cat /tmp/groups$$`
do
asmcmd find $GRP/$DBNAME % >>/tmp/files$$ 2>/dev/null
done
if [ -s /tmp/files$$ ]
then
echo "$ORACLE_SID files for database $DBNAME:"
echo "=================================="
cat /tmp/files$$
else
echo "Database $DBNAME does not have any files in disk group $GRP."
fi
echo ""
else
echo "The list of all files managed by ASM instance $ORACLE_SID:"
echo "=================================="
for GRP in `cat /tmp/groups$$`
do
asmcmd find $GRP % 2>/dev/null
done
fi
fi
#
# If -space was specified, report on the space usage per ASM group
#
if [ $SPACE ]
then
if [ $DBNAME ]
then
for GRP in `cat /tmp/groups$$`
do
asmcmd du $GRP/$DBNAME > /tmp/grp$$ 2>/dev/null
if [ -s /tmp/grp$$ ]
then
echo "Space usage by database $DBNAME in disk group $GRP:"
echo "=================================="
cat /tmp/grp$$
echo ""
rm -f /tmp/grp$$
else
echo "Database $DBNAME does not use disk group $GRP."
fi
done
else
for GRP in `cat /tmp/groups$$`
do
asmcmd du $GRP > /tmp/grp$$ 2>/dev/null
if [ -s /tmp/grp$$ ]
then
echo "Total Space usage by all databases in disk group $GRP:"
echo "=================================="
cat /tmp/grp$$
echo ""
rm -f /tmp/grp$$
fi
done
fi
fi
#
# Clean up
#
rm -f /tmp/groups$$
rm -f /tmp/files$$
rm -f /tmp/grp$$
#
# All work done
#
exit 0
1. Default output
$ ./asm.sh
Some minor issues and usage warnings for asmcmd version 10.2.0.1.
1. When using asmcmd non interactively (e.g. in a shell scripts) it may be easier to use % (not *)
for wildcard matching, to avoid shell substitution issues.
2. asmcmd does not support wildcard substitution in CD command. This will be addressed in
later versions of asmcmd.
3. 'asmcmd du' always reports "Mirror_used_MB" space for all ASM disk groups. If the disk
group is not mirrored, "Used_MB" and "Mirror_used_MB" values would be the same
(represening the taken disk space in megabytes). In a normal redundancy disk group (i.e. with
one mirror) the space reported under "Mirror_used_MB" would be double the ammout reported
under "Used_MB". Similarly, for the triple mirrored disk group we would expect the three times
the space reported under "Mirror_used_MB".