asmcmd Commands - Oracle 11g

Released as an ASM feature in Oracle Database 10g Release 2, asmcmd is a command-line utility to access and manage files associated with the ASM diskgroups.The asmcmd utility has a myriad of enhancements in Oracle Database 11g.asmcmd provides backward compatibility with Oracle Database 10g ASM instances.

You can use the Oracle Database 11g asmcmd utility to manage your Oracle Database 10g ASM environments.Oracle will support copying of the asmcmd executable from the Oracle Database 11g software binary directory to an Oracle Database 10g Release 2 software binary directory.The asmcmd utility will allow various 11.1 functionality to be leveraged against a 10.x Oracle release.

There are numerous improvements and additional options to the existing commands to asmcmd.The key commands set that will be discussed are as follows:

  • ls
  • lsdg
  • lsct
  • lsdsk
  • cp

ls
The ls command now incorporates the-c and the-g options.The-c option displaysinformation from the V$ASM_DISKGROUP view or from the GV$ASM_DISKGROUP view if the-g flag is also provided.The-g option displays information from the GV$ASM_DISKGROUP_STAT or GV$ASM_DISKGROUP view if the -c flag is also provided.The-g flag queries the GV$ASM_DISKGROUP view and reports the instance ID(INST_ID)in the output.Here’s a sample output from the -gc option:

ASMCMD> ls -gc
Inst_ID Name
1 DATA/
1 FRA/

lsdg
The lsdg command lists all disk groups and their attributes from V$ASM_DISKGROUP.The syntax for the lsdg command is as follows:

lsdg [-cgH] [group]

In Oracle Database 11g,two new options are provided—the -g and -c flags to the lsdgcommand. The -g flag queries the GV$ASM_ DISKGROUP view and reports the instance ID(INST_ID) in the output.If used with the -c flag, the GV$ASM_ DISKGROUP_ STAT view will be queried.
lsct
The lsct command lists all clients and their attributes from V$ASM_CLIENT:

ASMCMD [+] > lsct
DB_Name Status Software_ Compatible_ Instance_
Version Version Name
DBATOOLS CONNECTED 11.1.0.4.0 11.1.0.0.0 DBATOOLS
DBATOOLS CONNECTED 11.1.0.4.0 11.1.0.0.0 DBATOOLS

In Oracle Database 11g, the -g option is provided. This option queries the GV$ASM_CLIENT view and includes INST_ID in the report.

lsdsk
The lsdsk command is new to Oracle Database 11g. This command lists ASM-visible disks. Valid options for lsdsk are as follows:

lsdsk [-ksptcgHI] [-d <diskgroup_name>] [pattern]

The pattern keyword restricts the output to only disks that match the pattern.Wildcard characters and slashes (/ or )can be part of the pattern. In connected mode,asmcmd uses the V$ and GV$ tables to retrieve disk information.

In nonconnected mode,asmcmd scans disk headers to retrieve disk information using an ASM disk string to restrict the discovery set. The connected mode is always attempted first.Table lists flags for lsdsk that are worth mentioning.

Important 1sdsk flags

Important 1sdsk flags

Let’s look at some examples of the lsdsk command with the new parameters.The –k option reports the total size and amount of free space information in megabytes at the disk level.It also provides failgroup, disk label,and redundancy information, as shown here:

ASMCMD> lsdsk -k -d DATA
Total_MB Free_MB OS_MB Name Failgroup Library
Label UDID Product Redund Path
1961 1909 1961 VOL1 VOL1 ASM Library - Generic Linux, version
2.0.2 (KABI_V2)
VOL1 UNKNOWN ORCL:VOL1
1961 1909 1961 VOL2 VOL2 ASM Library - Generic Linux, version
2.0.2 (KABI_V2)
VOL2 UNKNOWN ORCL:VOL2

Another parameter worth mentioning is the -s option.The -s option provides information about disk performance metrics including read and write times.This option also reports errors encounteredat each disk level.You can use the -s option to gather performance characteristics of each disk.You can review the following read and write times and confirm IO distribution across all the disks in the diskgroup.

ASMCMD [+] > lsdsk -s -d DATA
Reads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read
Bytes_Written Path
1023 1306 0 0 2.491 1.166 4194304
ORCL:VOL1
1011 1306 0 0 2.809 3.387 4141056
ORCL:VOL2

The-t option provides information about when the disks were created and mounted.It also provides the remaining duration for the disk repair time.You can leverage the -d option to specify just the DATA diskgroup in conjunction with the -t option to show creation and mount times, as displayed here:

ASMCMD> lsdsk -t -d DATA
Create_Date Mount_Date Repair_Timer Path
30-MAY-07 30-MAY-07 0 ORCL:VOL1
30-MAY-07 30-MAY-07 0 ORCL:VOL2

cp
Anybody who has been supporting ASM on a day-to-day basis will admit that the copy command(cp)is the most anticipated ASM enhancement. Now, DBAs can copy ASM-supported files using the standard cp command from the asmcmd utility.The asmcmd cp command can be used to copy files in these situations:

  • From local diskgroup to another local diskgroup
  • From diskgroup to OS
  • From OS to diskgroup
  • From local diskgroup to a remote diskgroup

In addition,the asmcmd cp command can be used to copy all ASM-supported files such as Data Pump dump files,spfiles,block change tracking files, controlfiles, Data Guard Broker configuration files,and so on. The cp command has the following options:

cp [-ifr] <[@connect_identifier:]src> <[@connect_identifier:]tgt>

The three flags,-ifr,are similar to the flags from the Unix cp, rcp, and scp commands (interactive,force,and recursive copy).The interactive option prompts prior to a file overwrite. The force option will remove an existing file and perform a copy.

We’ll now show some examples of using the copy command to copy files in and out of ASM. Let’s start by copying a Data Pump dump file from the OS into the ASM DATA diskgroup:

ASMCMD [+] > cp /home/oracle/encrypted.dmp +data
source /home/oracle/encrypted.dmp SMCMD [+] > cp /home/oracle/encrypted.dmp +data
source /home/oracle/encrypted.dmp
target +data/encrypted.dmp
copying file(s)...
file, +DATA/encrypted.dmp, copy committed.
ASMCMD [+] > cd +data
ASMCMD [+data] > ls -ltr
Type Redund Striped Time Sys Name
Y ASMTESTING/
Y DBA10G/
Y DBA11G/
N encrypted.dmp =>
+DATA/ASMTESTING/DUMPSET/TESTING.296.632600587

Only ASM-supported files are allowed to be copied into ASM.If you attempt to copy in a non-ASM file such as a text file,an error message will be generated.

Now let’s copy an Oracle datafile from one ASM instance to another ASM instance.In Oracle Database 11g,an active database is no longer required to transfer files between one ASM instance diskgroup to another.We will copy one of the docs_d1 datafiles from the ASM instance on rac103 to another ASM instance on rac1. A database named DBA11g1 is running on the remote database server.In this example, we will rename the datafile from +DATA/DBA11g/ DATAFILE/DOCS_D1.289.631914611 to xxx on the process:

ASMCMD [+DATA/DBA11g/DATAFILE] > cp
+DATA/DBA11g/DATAFILE/DOCS_D1.289.631914611
sys@rac1.+ASM:+DATA/DBA11g1/datafile/xxx
Enter password: *********
source +DATA/DBA11g/DATAFILE/DOCS_D1.289.631914611
target +DATA/DBA11g1/datafile/xxx
copying file(s)...
file, +DATA/dba11g1/datafile/xxx, copy committed.

The syntax for the remote ASM diskgroup copy is as follows:

cp [srcfile]

The username can be any username in the ASM instance that has the sysasm privilege. Notice the dot(.) notation between the hostname and the ASM instance.The port assignment is optional if the LISTENER is not listening on port 1521.The last delimiter is a colon(:)followed by the fully qualified directory or file name. Note that the target ASM instance must be registered with the LISTENER for the remote copy between ASM diskgroups to work.

You can verify on the remote ASM instance that the copied file exists:

ASMCMD> pwd
+DATA/DBA11G1/DATAFILE
ASMCMD> ls -l xxx
Type Redund Striped Time Sys Name
N xxx => +DATA/ASMTESTING/DATAFILE/TESTING.278.632611175

You will also notice that the xxx file is created as an alias, and the actual file resides in the +DATA/ASMTESTING/DATAFILE directory. Because we specified the fully qualified file name, OMF will create an alias.

Another important point to note is that the -f option does not work with aliases.In the following example, we attempt to overwrite an existing alias, which results in an ORA-15005 error:

ASMCMD [+DATA/DBA11g/DATAFILE] > cp –f
+DATA/DBA11g/DATAFILE/DOCS_D1.289.631914611
Enter password: *********
error
source +DATA/DBA11g/DATAFILE/DOCS_D1.289.631914611
target +DATA/DBA11g1/datafile/docs_d1.dbf
ASMCMD-08015: can not create file->'+DATA/DBA11g1/datafile/docs_d1.dbf'
ORA-15056: additional error message
ORA-17502: ksfdcre:4 Failed to create file +DATA/dba11g1/datafile/docs_d1.dbf
ORA-15005: name "dba11g1/datafile/docs_d1.dbf" is already used by an existing alias
ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 142
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)
ASMCMD-08016: copy source->'+DATA/DBA11g/DATAFILE/DOCS_D1.289.631914611'
and target->'+DATA/DBA11g1/datafile/docs_d1.dbf' failed

Continuing with the cp examples, this is how to perform a datafile copy from one directory to another directory on the local ASM instance:

ASMCMD>cp +data/DBA11g1/DATAFILE/ALERT_D1.267.631889077
+FRA/DBA11G1/alert_d1.dbf
source +data/DBA11g1/DATAFILE/ALERT_D1.267.631889077
target +FRA/DBA11G1/alert_d1.dbf
copying file(s)...
file, +FRA/dba11g1/alert_d1.dbf, copy committed.

The syntax to copy files between one local diskgroup to another local diskgroup is straight forward.You can copy files between one diskgroup to another diskgroup or even to the same diskgroup.You can also leverage the copy command to copy files from ASM to a local file system.

As the last example, we’ll copy the docs_d4 datafile to the /oradata/DBATOOLS/ directory on the file system:

ASMCMD> cp +DATA/DBA11G1/DATAFILE/DOCS_D4.276.631890065
/oradata/DBATOOLS/docs_d4.dbf
source +DATA/DBA11G1/DATAFILE/DOCS_D4.276.631890065
target /oradata/DBATOOLS/docs_d4.dbf
copying file(s)...
file, /oradata/DBATOOLS/docs_d4.dbf,copy committed.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Oracle 11g Topics