Showing posts with label ASM. Show all posts
Showing posts with label ASM. Show all posts

Wednesday, 21 August 2013

Dropping Disk from ASM Group

Dropping disk in ASM by this method will mark the disk for drop and then start doing rebalance. Once it completes moving data off the ear-marked disks then it will remove that disk from diskgroup.
This is different concept than dropping disks on OS and storage level, as in both disk are unavailable straight away after comman executes.

This also helps to do addition and deletion of disks by doing one rebalance. So if new disks are added and straight after that old disks are dropped in ASM then ASM will only do one rebalance considering both new and removed disks.

Alter diskgroup DATA drop disk '/dev/data_disk1';
Diskgroup altered.



 

Friday, 1 July 2011

SOME ASM COMMANDS


ASM packages installed a service called oracleasm which can be called by running these commands

# /etc/init.d/oracleasm
# service oracleasm



/etc/init.d/oracleasm script takes the following options:
configure: Configure ASM.
start: Start the ASM service.
stop: Stop the ASM service.
status: Print the status of ASM service.
createdisk: Create an ASM disk.
scandisks: Search for ASM disks.
listdisks: List ASM disks.
querydisk: Query the current status of an ASM disk.
deletedisk: Delete an ASM disk.
restart: Restart the ASM service.
link: Load the oracleasm module.
enable: Enable the ASM service.
disable: Disable the ASM service.



Starting ASM service

# /etc/init.d/oracleasm start

To stop ASM service

# /etc/init.d/oracleasm stop

To check status of ASM service
# /etc/init.d/oracleasm status

CREATEDISK
# /etc/init.d/oracleasm createdisk VOL1 /dev/sdb1
Marking disk "/dev/sdb1" as an ASM disk [ OK ]
 # /etc/init.d/oracleasm createdisk VOL2 /dev/sdc1
Marking disk "/dev/sdc1" as an ASM disk [ OK ]
 # /etc/init.d/oracleasm createdisk VOL3 /dev/sdd1
Marking disk "/dev/sdd1" as an ASM disk [ OK ]


SCANDISK
# /etc/init.d/oracleasm scandisks


LISTDISK to verify the disks are available
# /etc/init.d/oracleasm listdisks

To query the status of existing disk
# /etc/init.d/oracleasm querydisk VOL1

DELETEDISK
# /etc/init.d/oracleasm deletedisk VOL1


Deleting an ASM Instance Manually
delete the ASM instance from the OCR:

 $ srvctl remove asm -n DB1 -i +ASM1
 $ srvctl remove asm -n DB2 -i +ASM2


On each node, delete the ASM instance from /etc/oratab. Then, on each node, delete the
parameter file, as in the following example:
[oracle@london1 oracle] $ rm $ORACLE_HOME/dbs/init+ASM.ora

Finally, on each node, delete the password file:
[oracle@london1 oracle] $ rm $ORACLE_HOME/dbs/orapw+ASM1


Col name form a30
Col failgroup form a30
Select name,failgroup from v$asm_disk
Where group_number=(
Select group_number from v$asm_diskgroup
Where name=’G3_RECOVERY_AREA’)
/

Checking the operation of rebalancing
Select * from gv$asm_operation;



################################################################
# 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;







SET LINESIZE  200
SET PAGESIZE  9999
SET TRIMSPOOL on
SET VERIFY    off

COLUMN disk_group_name        FORMAT a10           HEAD 'Disk Group Name'
COLUMN disk_file_path         FORMAT a30           HEAD 'Path'
COLUMN disk_file_name         FORMAT a10           HEAD 'File Name'
COLUMN disk_file_fail_group   FORMAT a10           HEAD 'Fail Group'
COLUMN total_mb               FORMAT 999,999,999   HEAD 'File Size (MB)'
COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'
COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'

break on report on disk_group_name skip 1
compute sum label ""              of total_mb used_mb on disk_group_name
compute sum label "Total: "       of total_mb used_mb on report

SELECT
  a.group_number,
  a.name,
  a.state
FROM
    v$asm_diskgroup a
ORDER BY
    a.group_number
;

SELECT
  b.group_number                                   disk_group_number,
  b.path                                           disk_file_path,
  b.name                                           disk_file_name,
  b.failgroup                                      disk_file_fail_group,
  b.total_mb                                       total_mb,
  (b.total_mb - b.free_mb)                         used_mb,
  decode(b.total_mb,0,0,(ROUND((1- (b.free_mb / b.total_mb))*100, 2)))      pct_used
FROM
    v$asm_disk b
WHERE b.header_status = 'MEMBER'
ORDER BY
  b.group_number
;