Vous êtes sur la page 1sur 9

ASM SQL Scripts

by Jeff Hunter, Sr. Database Administrator

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.

ASM Script Repository

OutputScript Name Last Update Date


asm_disks.sql
asm_files2.sql
asm_templates.sql
asm_files.sql
asm_clients.sql
asm_alias.sql
asm_disks_perf.sql
asm_diskgroups.sql
asm_drop_files.sql
-- +----------------------------------------------------------------------------+

-- | 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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN disk_file_path FORMAT a17 HEAD 'Path'
COLUMN disk_file_name FORMAT a20 HEAD 'File Name'
COLUMN disk_file_fail_group FORMAT a20 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 "Grand Total: " of total_mb used_mb on report

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN file_name FORMAT a30 HEAD 'File Name'
COLUMN bytes FORMAT 9,999,999,999,999 HEAD 'Bytes'
COLUMN space FORMAT 9,999,999,999,999 HEAD 'Space'
COLUMN type FORMAT a18 HEAD 'File Type'
COLUMN redundancy FORMAT a12 HEAD 'Redundancy'
COLUMN striped FORMAT a8 HEAD 'Striped'
COLUMN creation_date FORMAT a20 HEAD 'Creation Date'

break on report on disk_group_name skip 1


compute sum label "" of bytes space on disk_group_name
compute sum label "Grand Total: " of bytes space on report

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN entry_number FORMAT 999 HEAD 'Entry Number'
COLUMN redundancy FORMAT a12 HEAD 'Redundancy'
COLUMN stripe FORMAT a8 HEAD 'Stripe'
COLUMN system FORMAT a6 HEAD 'System'
COLUMN template_name FORMAT a30 HEAD 'Template Name'

break on report on disk_group_name skip 1

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 150


SET PAGESIZE 9999
SET VERIFY off

COLUMN full_alias_path FORMAT a63 HEAD 'File Name'


COLUMN system_created FORMAT a8 HEAD 'System|Created?'
COLUMN bytes FORMAT 9,999,999,999,999 HEAD 'Bytes'
COLUMN space FORMAT 9,999,999,999,999 HEAD 'Space'
COLUMN type FORMAT a18 HEAD 'File Type'
COLUMN redundancy FORMAT a12 HEAD 'Redundancy'
COLUMN striped FORMAT a8 HEAD 'Striped'
COLUMN creation_date FORMAT a20 HEAD 'Creation Date'
COLUMN disk_group_name noprint

BREAK ON report ON disk_group_name SKIP 1

compute sum label "" of bytes space on disk_group_name


compute sum label "Grand Total: " of bytes space on report
SELECT
CONCAT('+' || disk_group_name, SYS_CONNECT_BY_PATH(alias_name, '/'))
full_alias_path
, bytes
, space
, NVL(LPAD(type, 18), '<DIRECTORY>') type
, creation_date
, disk_group_name
, LPAD(system_created, 4) system_created
FROM
( SELECT
g.name disk_group_name
, a.parent_index pindex
, a.name alias_name
, a.reference_index rindex
, a.system_created system_created
, 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 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
/

-- +----------------------------------------------------------------------------+
-- | 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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN instance_name FORMAT a20 HEAD 'Instance Name'
COLUMN db_name FORMAT a9 HEAD 'Database Name'
COLUMN status FORMAT a12 HEAD 'Status'

break on report on disk_group_name skip 1

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN alias_name FORMAT a30 HEAD 'Alias Name'
COLUMN file_number HEAD 'File|Number'
COLUMN file_incarnation HEAD 'File|Incarnation'
COLUMN alias_index HEAD 'Alias|Index'
COLUMN alias_incarnation HEAD 'Alias|Incarnation'
COLUMN parent_index HEAD 'Parent|Index'
COLUMN reference_index HEAD 'Reference|Index'
COLUMN alias_directory FORMAT a10 HEAD 'Alias|Directory?'
COLUMN system_created FORMAT a8 HEAD 'System|Created?'

break on report on disk_group_name skip 1

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name'


COLUMN disk_path FORMAT a20 HEAD 'Disk Path'
COLUMN reads FORMAT 999,999,999 HEAD 'Reads'
COLUMN writes FORMAT 999,999,999 HEAD 'Writes'
COLUMN read_errs FORMAT 999,999 HEAD 'Read|Errors'
COLUMN write_errs FORMAT 999,999 HEAD 'Write|Errors'
COLUMN read_time FORMAT 999,999,999 HEAD 'Read|Time'
COLUMN write_time FORMAT 999,999,999 HEAD 'Write|Time'
COLUMN bytes_read FORMAT 999,999,999,999 HEAD 'Bytes|Read'
COLUMN bytes_written FORMAT 999,999,999,999 HEAD 'Bytes|Written'

break on report on disk_group_name skip 2

compute sum label "" of reads writes read_errs write_errs read_time


write_time bytes_read bytes_written on disk_group_name
compute sum label "Grand Total: " of reads writes read_errs write_errs read_time
write_time bytes_read bytes_written on report

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. |
-- +----------------------------------------------------------------------------+

SET LINESIZE 145


SET PAGESIZE 9999
SET VERIFY off

COLUMN group_name FORMAT a20 HEAD 'Disk Group|Name'


COLUMN sector_size FORMAT 99,999 HEAD 'Sector|Size'
COLUMN block_size FORMAT 99,999 HEAD 'Block|Size'
COLUMN allocation_unit_size FORMAT 999,999,999 HEAD 'Allocation|Unit Size'
COLUMN state FORMAT a11 HEAD 'State'
COLUMN type FORMAT a6 HEAD 'Type'
COLUMN total_mb FORMAT 999,999,999 HEAD 'Total 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 "Grand Total: " of total_mb used_mb on report

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

COLUMN full_alias_path FORMAT a255 HEAD 'File Name'


COLUMN disk_group_name noprint

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
/

Vous aimerez peut-être aussi