ASM Commands

################################################################
# Adding/Removing/Managing 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 Analysis
###################################
–Only Performance Statistics
–N.B Time in Hundred seconds!
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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s