ASM Cheatsheet
# Adding/Removing/Managing configuration about existing ASM instances
--Use the following syntax to add configuration information about an existing ASM instance:
Srvctl add asm -n node_name -i +asm_instance_name -o oracle_home
--Use the following syntax to remove an ASM instance:
Srvctl remove asm -n node_name [-i +asm_instance_name]
--Use the following syntax to enable an ASM instance:
Srvctl enable asm -n node_name [-i ] +asm_instance_name
--Use the following syntax to disable an ASM instance:
Srvctl disable asm -n node_name [-i +asm_instance_name]
--Use the following syntax to start an ASM instance:
Srvctl start asm -n node_name [-i +asm_instance_name] [-o start_options]
--Use the following syntax to stop an ASM instance:
Srvctl stop asm -n node_name [-i +asm_instance_name] [-o stop_options]
--Use the following syntax to show the configuration of an ASM instance:
Srvctl config asm -n node_name
--Use the following syntax to obtain the status of an ASM instance:
Srvctl status asm -n node_name
--P.S.:
--For all of the SRVCTL commands in this section for which the
--option is not required, if you do not specify an instance name, then -i
--the command applies to all of the ASM instances on the node.
# Managing DiskGroup inside ASM:
--Note that adding or dropping disks will initiate a rebalance of the data on the disks.
--The status of these processes can be shown by selecting from v$asm_operation.
--Quering ASM Disk Groups
Col name format a25
Col DATABASE_COMPATIBILITY format a10
Col COMPATIBILITY format a10
Select * from v$asm_diskgroup;
--or
Select name, state, type, total_mb, free_mb from v$asm_diskgroup;
--Quering ASM Disks
Col PATH format a55
Col name format a25
Select name, path, group_number, TOTAL_MB, FREE_MB, READS, WRITES, READ_TIME,
WRITE_TIME from v$asm_disk order by 3,1;
--or
Col PATH format a50
Col HEADER_STATUS format a12
Col name format a25
--select INCARNATION,
Select name, path, MOUNT_STATUS,HEADER_STATUS, MODE_STATUS, STATE, group_number,
OS_MB, TOTAL_MB, FREE_MB, READS, WRITES, READ_TIME, WRITE_TIME, BYTES_READ,
BYTES_WRITTEN, REPAIR_TIMER, MOUNT_DATE, CREATE_DATE from v$asm_disk;
#TUNING and Analisys
--Only Performance Statistics
--N.B Time in Hundredseconds!
Col READ_TIME format 9999999999.99
Col WRITE_TIME format 9999999999.99
Col BYTES_READ format 99999999999999.99
Col BYTES_WRITTEN format 99999999999999.99
Select name, STATE, group_number, TOTAL_MB, FREE_MB,READS, WRITES, READ_TIME,
WRITE_TIME, BYTES_READ, BYTES_WRITTEN, REPAIR_TIMER,MOUNT_DATE
From v$asm_disk order by group_number, name;
--Check the Num of Extents in use per Disk inside one Disk Group.
Select max(substr(name,1,30)) group_name, count(PXN_KFFXP) extents_per_disk,
DISK_KFFXP, GROUP_KFFXP from x$kffxp, v$ASM_DISKGROUP gr
Where GROUP_KFFXP=&group_nr and GROUP_KFFXP=GROUP_NUMBER
Group by GROUP_KFFXP, DISK_KFFXP order by GROUP_KFFXP, DISK_KFFXP;
--Find The File distribution Between Disks
SELECT * FROM v$asm_alias WHERE name=’PWX_DATA.272.669293645’;
SELECT GROUP_KFFXP Group#,DISK_KFFXP Disk#,AU_KFFXP AU#,XNUM_KFFXP Extent#
FROM X$KFFXP WHERE number_kffxp=(SELECT file_number FROM v$asm_alias
WHERE name=’PWX_DATA.272.669293645’);
--or
SELECT GROUP_KFFXP Group#,DISK_KFFXP Disk#,AU_KFFXP AU#,XNUM_KFFXP Extent#
FROM X$KFFXP WHERE number_kffxp=&DataFile_Number;
--or
Select d.name, XV.GROUP_KFFXP Group#, XV.DISK_KFFXP Disk#,
XV.NUMBER_KFFXP File_Number, XV.AU_KFFXP AU#, XV.XNUM_KFFXP Extent#,
XV.ADDR, XV.INDX, XV.INST_ID, XV.COMPOUND_KFFXP, XV.INCARN_KFFXP,
XV.PXN_KFFXP, XV.XNUM_KFFXP,XV.LXN_KFFXP, XV.FLAGS_KFFXP,
XV.CHK_KFFXP, XV.SIZE_KFFXP from v$asm_disk d, X$KFFXP XV
Where d.GROUP_NUMBER=XV.GROUP_KFFXP and d.DISK_NUMBER=XV.DISK_KFFXP
And number_kffxp=&File_NUM order by 2,3,4;
--List the hierarchical tree of files stored in the diskgroup
SELECT concat(‘+’||gname, sys_connect_by_path(aname, ‘/’)) full_alias_path FROM
(SELECT g.name gname, a.parent_index pindex, a.name aname,
a.reference_index rindex FROM v$asm_alias a, v$asm_diskgroup g
WHERE a.group_number = g.group_number)
START WITH (mod(pindex, power(2, 24))) = 0
CONNECT BY PRIOR rindex = pindex;
#Create and Modify Disk Group
Create diskgroup FRA1 external redundancy disk ‘/dev/vx/rdsk/oraASMdg/fra1’
ATTRIBUTE ‘compatible.rdbms’ = ’11.1’, ‘compatible.asm’ = ’11.1’;
Alter diskgroup FRA1 check all;
--on +ASM2 :
Alter diskgroup FRA1 mount;
--Add a second disk:
Alter diskgroup FRA1 add disk ‘/dev/vx/rdsk/oraASMdg/fra2’;
--Add several disks with a wildcard:
Alter diskgroup FRA1 add disk ‘/dev/vx/rdsk/oraASMdg/fra*’;
--Remove a disk from a diskgroup:
Alter diskgroup FRA1 drop disk ‘FRA1_0002’;
--Drop the entire DiskGroup
Drop diskgroup DATA1 including contents;
--How to DROP the entire DiskGroup when it is in NOMOUNT Status
--Generate the dd command which will reset the header of all the
--disks belong the GROUP_NUMBER=0!!!!
Select ‘dd if=/dev/zero of=’’’ ||PATH||’’’ bs=8192 count=100’ from v$asm_disk
Where GROUP_NUMBER=0;
Select * from v$asm_operation;
Alter diskgroup FRA1 drop disk ‘FRA1_0002’;
Alter diskgroup FRA1 add disk ‘/dev/vx/rdsk/fra1dg/fra3’;
Alter diskgroup FRA1 drop disk ‘FRA1_0003’;
Alter diskgroup FRA1 add disk ‘/dev/vx/rdsk/fra1dg/fra4’;
--When a new diskgroup is created, it is only mounted on the local instance,
--and only the instance-specific entry for the asm_diskgroups parameter is updated.
--By manually mounting the diskgroup on other instances, the asm_diskgroups parameter
--on those instances are updated.
--on +ASM1 :
Create diskgroup FRA1 external redundancy disk ‘/dev/vx/rdsk/fradg/fra1’
ATTRIBUTE ‘compatible.rdbms’ = ’11.1’, ‘compatible.asm’ = ’11.1’;
--on +ASM2 :
Alter diskgroup FRA1 mount;
--It works even for on going balances!!!
Alter diskgroup DATA1 rebalance power 10;
# New ASM Command Line Utility (ASMCMD) Commands and Options
ASMCMD Command Reference:
Command Description
- cd Command Changes the current directory to the specified directory.
- cp Command Enables you to copy files between ASM disk groups on a local instance and remote
instances.
- du Command Displays the total disk space occupied by ASM files in the specified
- ASM directory and all of its subdirectories, recursively.
- exit Command Exits ASMCMD.
- find Command Lists the paths of all occurrences of the specified name (with wildcards) under the
specified directory.
- help Command Displays the syntax and description of ASMCMD commands.
- ls Command Lists the contents of an ASM directory, the attributes of the specified
- file, or the names and attributes of all disk groups.
- lsct Command Lists information about current ASM clients.
- lsdg Command Lists all disk groups and their attributes.
- lsdsk Command Lists disks visible to ASM.
- md_backup Command Creates a backup of all of the mounted disk groups.
- md_restore Command Restores disk groups from a backup.
- mkalias Command Creates an alias for system-generated filenames.
- mkdir Command Creates ASM directories.
- pwd Command Displays the path of the current ASM directory.
- remap Command Repairs a range of physical blocks on a disk.
- rm Command Deletes the specified ASM files or directories.
- rmalias Command Deletes the specified alias, retaining the file that the alias points to.
Kfed tool From Unix Prompt for reading ASM disk header.
Kfed read /dev/vx/rdsk/fra1dg/fra1
# CREATE and Manage Tablespaces and Datafiles on ASM
CREATE TABLESPACE my_ts DATAFILE ‘+disk_group_1’ SIZE 100M AUTOEXTEND ON;
ALTER TABLESPACE sysaux ADD DATAFILE ‘+disk_group_1’ SIZE 100M;
ALTER DATABASE DATAFILE ‘+DATA1/dbname/datafile/audit.259.668957419’ RESIZE 150M;
Create diskgroup DATA1 external redundancy disk ‘/dev/vx/rdsk/oraASMdg/fra1’
ATTRIBUTE ‘compatible.rdbms’ = ’11.1’, ‘compatible.asm’ = ’11.1’;
Select ‘alter diskgroup DATA1 add disk ‘’’ || PATH || ‘’’;’ from v$asm_disk
Where GROUP_NUMBER=0 and rownum<=&Num_Disks_to_add;
Select ‘alter diskgroup FRA1 add disk ‘’’ || PATH || ‘’’;’ from v$asm_disk
Where GROUP_NUMBER=0 and rownum<=&Num_Disks_to_add;
--Remove ASM header
Select ‘dd if=/dev/zero of=’’’ ||PATH||’’’ bs=8192 count=100’ from v$asm_disk
Where GROUP_NUMBER=0;
Sql to find candidate disks
SELECT
NVL(a.name, ‘[CANDIDATE]’) disk_group_name
, b.path disk_file_path
, b.name disk_file_name
, b.failgroup disk_file_fail_group
FROM
V$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
ORDER BY
a.name;