Saturday, June 21, 2014

Oracle RAC - ASM file operations

Disadvantages of ASM Disks
At operating system level, files in ASM reside on raw disks and OS is unaware of what is stored on those devices. We are unable to look inside these disks using an OS tool or shell commands.
What is ASMCMD
ASMCMD is Oracle's command-line tool for managing ASM instances, files, disk groups etc. For managing ASM instances, I use the sql commands because I'm more used to SQL syntax. However, for managing ASM files I use ASMCMD. Its commands are like bash commands. It allows you to perform various tasks like copying, moving, deleting files...
Starting ASMCMD
Before running ASMCMD:
1. Set ORACLE_HOME environment variable to Grid Infrastructure (GI) home.
1
$ export ORACLE_HOME=/u01/app/grid/11.2.0.3
2. Set ORACLE_SID environment variable to the name of ASM instance. This will be "+ASM" for single instance configuration and "+ASM" for RAC (Real Application Clusters) configuration.
1
$ export ORACLE_SID='+ASM'
3. Include the $ORACLE_HOME/bin folder in PATH environment variable.
1
$ export PATH=$PATH:$ORACLE_HOME/bin;
4. As oracle user, start ASMCMD command with "-p" parameter. The "-p" parameter is optional. When set, the current directory is listed in the prompt, which is useful for administrators.
1
$ asmcmd -p
File Management Commands
ls : Lists the directories, files and attributes of them.
cd : Change directory.
1
2
3
4
5
6
$ asmcmd -p
 
ASMCMD [+] > ls
 
FRA/
ORADATA/
I'm in the top directory of ASM. Paths in ASM always start with a (+) sign followed by disk group name. (More information on ASM concepts.)
Now I am going to move to subfolders and list the files there.
1
2
3
4
5
6
7
8
9
10
11
ASMCMD [+] > cd +ORADATA/TESTDB/DATAFILE
 
ASMCMD [+ORADATA/TESTDB/DATAFILE] > ls -l
 
Type      Redund  Striped  Time             Sys  Name
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    AUDIT_TRAIL.1910.772801593
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    EXAMPLE.439.772800417
 DATAFILE  UNPROT  COARSE   JAN 29 17:00:00  Y    SYSAUX.2425.772800299
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    SYSTEM.2380.772803055
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    UNDOTBS1.435.772800299
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    USERS.437.772800299
When used with "-l" parameter, the "ls" command lists files and folders with extended information.
You can also use wildcards with ls command.
1
2
3
4
5
ASMCMD [+ORADATA/TESTDB/DATAFILE] > ls -l SYS*
 
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   JAN 29 17:00:00  Y    SYSAUX.2425.772800299
DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    SYSTEM.2380.772803055
The files starting with "SYS" are listed.
The "-s" parameter shows space information for relevant files.
1
2
3
4
5
ASMCMD [+ORADATA/TESTDB/DATAFILE] > ls -s SYS*
 
Block_Size  Blocks      Bytes      Space  Name
       8192   97281  796925952  799014912  SYSAUX.2425.772800299
       8192   93441  765468672  767557632  SYSTEM.2380.772803055
By default, files are sorted by name. If you set the "-t" parameter, files are sorted by timestamp.
1
2
3
4
5
ASMCMD [+ORADATA/TESTDB/DATAFILE] > ls -lt SYS*
 
 Type      Redund  Striped  Time             Sys  Name
 DATAFILE  UNPROT  COARSE   JAN 29 17:00:00  Y    SYSAUX.2425.772800299
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    SYSTEM.2380.772803055
If you set "--reverse" flag, the sort order is reversed.
1
2
3
4
5
ASMCMD [+ORADATA/TESTDB/DATAFILE] > ls -lt SYS* --reverse
 
Type      Redund  Striped  Time             Sys  Name
 DATAFILE  UNPROT  COARSE   JAN 27 22:00:00  Y    SYSTEM.2380.772803055
 DATAFILE  UNPROT  COARSE   JAN 29 17:00:00  Y    SYSAUX.2425.772800299
Notice that the files are sorted in reverse order by timestamp.
Copying Files in ASM
cp: Copy files to destination.
syntax: cp [src_file] [dest_file]
The copy operatin can be:
a. From disk group to operating system,
b. from operating system to disk group,
c. between 2 disk groups. These disk groups can even be on different ASM instances.
When ASM was first introduced in version 10g, asmcmd didn't have a copy feature. You had to use RMAN commands (backup-restore) to copy files. This new copy feature in ASMCMD makes the process much shorter and easier.
1
2
3
4
5
6
7
ASMCMD [+ORADATA/testdb/DATAFILE] > cp SYSTEM.2380.772803055 /home/oracle/system_backup
 
copying +ORADATA/testdb/DATAFILE/SYSTEM.2380.772803055 -> /home/oracle/system_backup
 
$ file /home/oracle/system_backup
 
/home/oracle/system_backup: data
As seen in the example, asmcmd copied the file "+ORADATA/testdb/DATAFILE/SYSTEM.2380.772803055" bit-to-bit to /home/oracle/system_backup
If you are copying a file from OS to ASM, the type of the file must be a type that ASM supports. ASM cannot store all kind of files.
1
2
3
4
5
6
7
8
9
10
$ touch test.txt
 
ASMCMD [+ORADATA/testdb/DATAFILE] > cp /home/oracle/test.txt .
 
ASMCMD-8012: can not determine file type for file
 ORA-27091: unable to queue I/O
 ORA-27067: size of I/O buffer is invalid
 Additional information: 2
 ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 320
 ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)
First I created a regular text file in OS using BASH's "touch" command. Then I tried to copy it to ASM disk group. The operation failed as expected.
The "." and ".." are special characters in ASMCMD. "." points to current directory and ".." points to parent directory.
1
2
3
4
5
6
7
8
ASMCMD [+ORADATA/testdb/DATAFILE] > cp /home/oracle/system_backup +ORADATA/testdb/DATAFILE/from_OS_to_ASM
 
 copying /home/oracle/system_backup -> +ORADATA/testdb/DATAFILE/from_OS_to_ASM
 
ASMCMD [+ORADATA/testdb/DATAFILE] > ls -l from*
 
Type      Redund  Striped  Time             Sys  Name
                                             N    from_OS_to_ASM => +ORADATA/ASM/DATAFILE/from_OS_to_ASM.1911.774035377
Oracle implicitly named the file according to ASM file format.
Deleting Files In ASM
rm : Like in bash, the rm (remove) command is used to delete files and folders.
rm -r : Recursive delete. This deletes the folder and its subfolders along with files.
1
2
3
4
5
6
7
8
9
10
11
12
ASMCMD [+] > cd FRA/TESTDB/ARCHIVELOG
 
ASMCMD [+FRA/TESTDB/ARCHIVELOG] > ls -d 2012_01_17/
 
2012_01_17/
 
ASMCMD [+FRA/TESTDB/ARCHIVELOG] > rm -r 2012_01_17/
 
You may delete multiple files and/or directories.
Are you sure? (y/n) y
 
ASMCMD [+FRA/TESTDB/ARCHIVELOG] >
When deleting a folder which is not empty, if you set the "-f" (force) parameter, Oracle won't ask you to confirm the delete operation.
1
2
ASMCMD [+FRA/TESTDB/ARCHIVELOG] > rm -rf 2012_01_18/
ASMCMD [+FRA/TESTDB/ARCHIVELOG] >

1 comment:

Unknown said...

Hallo,


Such vivid info on the oracle! Flabbergasted! Thank you for making the read a smooth sail!


I want to learn Linux.
I have an idea for an application that I want to be open source.
I fairly technical (Cisco CCNP) and I'm good with tshooting but I don't want to waste hours of my time narrowing down the root cause of some insignificant thing. I would rather pay someone else to give me the answer (I understand Red Hat has technical support I can pay for).
Please keep providing such valuable information.


Shukran,

Hallo,


Such vivid info on the! Flabbergasted! Thank you for making the read a smooth sail!


I want to learn Linux.
I have an idea for an application that I want to be open source.
I fairly technical (Cisco CCNP) and I'm good with tshooting but I don't want to waste hours of my time narrowing down the root cause of some insignificant thing. I would rather pay someone else to give me the answer (I understand Red Hat has technical support I can pay for).
Please keep providing such valuable information.


Shukran,