Professional Documents
Culture Documents
Contents
1. Overview
2. ASM Script Repository
Overview
This article provides links to several SQL scripts that can be used to monitor and manage an ASM
instance. All of the scripts are meant to be run against the ASM instance logged in with SYSDBA
privileges.
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_disks.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all disks contained within all disk |
-- | groups. This script is also responsible for queriing all |
-- | candidate disks - those that are not assigned to any disk |
-- | group. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
NVL(a.name, '[CANDIDATE]') disk_group_name
, 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
, ROUND((1- (b.free_mb / b.total_mb))*100, 2) pct_used
FROM
v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
ORDER BY
a.name
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_files2.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all files (and file metadata) |
-- | information for all ASM disk groups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
g.name disk_group_name
, a.name file_name
, f.bytes bytes
, f.space space
, f.type type
, TO_CHAR(f.creation_date, 'DD-MON-YYYY HH24:MI:SS') creation_date
FROM
v$asm_file f JOIN v$asm_alias a USING (group_number, file_number)
JOIN v$asm_diskgroup g USING (group_number)
WHERE
system_created = 'Y'
ORDER BY
g.name
, file_number
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_templates.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all template information for all |
-- | ASM disk groups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
b.name disk_group_name
, a.entry_number entry_number
, a.redundancy redundancy
, a.stripe stripe
, a.system system
, a.name template_name
FROM
v$asm_template a JOIN v$asm_diskgroup b USING (group_number)
ORDER BY
b.name
, a.entry_number
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_files.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all files (and file metadata) |
-- | information for all ASM disk groups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_clients.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all clients making use of this ASM |
-- | instance. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
a.name disk_group_name
, c.instance_name instance_name
, c.db_name db_name
, c.status status
FROM
v$asm_diskgroup a JOIN v$asm_client c USING (group_number)
ORDER BY
a.name
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_alias.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all alias definitions contained |
-- | within all ASM disk groups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
g.name disk_group_name
, a.name alias_name
, a.file_number file_number
, a.file_incarnation file_incarnation
, a.alias_index alias_index
, a.alias_incarnation alias_incarnation
, a.parent_index parent_index
, a.reference_index reference_index
, a.alias_directory alias_directory
, a.system_created system_created
FROM
v$asm_alias a JOIN v$asm_diskgroup g USING (group_number)
ORDER BY
g.name
, a.file_number
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_disks_perf.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all disks contained within all ASM |
-- | disk groups along with their performance metrics. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
a.name disk_group_name
, b.path disk_path
, b.reads reads
, b.writes writes
, b.read_errs read_errs
, b.write_errs write_errs
, b.read_time read_time
, b.write_time write_time
, b.bytes_read bytes_read
, b.bytes_written bytes_written
FROM
v$asm_diskgroup a JOIN v$asm_disk b USING (group_number)
ORDER BY
a.name
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_diskgroups.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Provide a summary report of all disk groups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SELECT
name group_name
, sector_size sector_size
, block_size block_size
, allocation_unit_size allocation_unit_size
, state state
, type type
, total_mb total_mb
, (total_mb - free_mb) used_mb
, ROUND((1- (free_mb / total_mb))*100, 2) pct_used
FROM
v$asm_diskgroup
ORDER BY
name
/
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : asm_drop_files.sql |
-- | CLASS : Automatic Storage Management |
-- | PURPOSE : Used to create a SQL script that removes all ASM files |
-- | contained within all diskgroups. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SET LINESIZE 255
SET PAGESIZE 9999
SET VERIFY off
SET FEEDBACK off
SET HEAD off
SELECT
'ALTER DISKGROUP ' ||
disk_group_name ||
' DROP FILE ''' || CONCAT('+' || disk_group_name,
SYS_CONNECT_BY_PATH(alias_name, '/')) || ''';' full_alias_path
FROM
( SELECT
g.name disk_group_name
, a.parent_index pindex
, a.name alias_name
, a.reference_index rindex
, f.type type
FROM
v$asm_file f RIGHT OUTER JOIN v$asm_alias a USING (group_number,
file_number)
JOIN v$asm_diskgroup g USING (group_number)
)
WHERE type IS NOT NULL
START WITH (MOD(pindex, POWER(2, 24))) = 0
CONNECT BY PRIOR rindex = pindex
/