Sunday, 24 January 2016

Understanding and How To Gather & Backup ASM/ACFS Metadata

1. ASM metadata

An ASM instance manages metadata needed to make ASM files available to Oracle databases and other ASM clients. ASM metadata is stored in the disk groups – in the metadata blocks.

Some ASM metadata is at the fixed position in every ASM disk, and is referred to as physically addressed metadata. Other ASM metadata is organised in files (directories) and is referred to as virtually addressed metadata. The virtually addressed metadata files are managed like any other ASM files – they get mirrored as per the file type redundancy policy, are subject to rebalance and can grow as needed.

Each ASM disk has the metadata that may be relevant to that disk only or to the whole disk group. For example, the ASM disk header is relevant to that disk only, while  the Partnership and Status Table (PST) is relevant to the whole disk group.

2. Physically addressed metadata

The physical ASM metadata are the following structures:

  • Disk header
  • Free Space Table (FST)
  • Allocation Table (AT)
  • Partnership and Status Table (PST)

The disk header, allocation table and free space table are called physically addressed ASM metadata, because ASM instance refers to this data via a disk number and the block number within a disk. The partnership and status table is a special case, as ASM refers to it via allocation unit number, not via disk/block number.

Allocation units 0 on every ASM disk will always have the disk header (block 0), the Free Space Table (block 1) and the Allocation Table - in the rest of the allocation unit 0 blocks.

The ASM disk header contains the disk number, disk group redundancy, disk name, disk group name, disk size, etc.

The Free Space Table (FST) indicates which allocation table blocks may have free space in them. It contains an array of bit patterns indexed by allocation table block number. Location of the first block of the free space table is in the disk header field kfdhdb.fstlocn.

The ASM allocation table (AT) has one entry for every allocation unit (AU) on the disk. Location of the first block of the allocation table is in the disk header – field kfdhdb.altlocn.

The Partnership and Status Table (PST) contains the information about all ASM disks in the disk group – disk numbers, their status, their partner disks, heartbeat info, the failure group info, etc. Each ASM disk contains an allocation unit reserved for storing the PST - typically that is allocation unit number 1. Only few disks have the actual PST data – in external redundancy group we only have one PST table, in a normal redundancy disk group we have up to 3 copies of the PST, and in a high redundancy disk group we have up to 5 copies of the PST.

3. Virtually addressed metadata

The rest of the disk group metadata is organized in ASM metadata files (directories). That is how ASM keeps track of the database files, ASM disks, ASM instance recovery data, etc. An ASM metadata file is maintained like any other file stored in ASM, which means that its extents are allocated across all available disks, that they are mirrored (in a normal and high redundancy disk group) and that its extents can be moved around when the disk group is rebalanced. ASM file numbers between 1 and 255 are reserved for ASM metadata files.
The virtually addressed metadata are the following structures:
  • File Directory
  • Disk Directory
  • Active Change Directory (ACD)
  • Continuing Operations Directory (COD)
  • Template Directory
  • Alias Directory
  • ADVM Volume Directory
  • Disk Used Space Directory
  • Attributes Directory
  • ASM User Directory and User Group Directory
  • Staleness Directory and Staleness Registry
  • Password directory
ASM metadata file names and their locations are not externalized and cannot be queried directly, but we can peek at them via X$KFFXP fixed table. The following query shows the ASM metadata file numbers, their names and allocation unit count for each file in a disk group (in this case in the disk group number 2):
SQL> select
  NUMBER_KFFXP "ASM file number",
  DECODE (NUMBER_KFFXP, 1, 'File directory',
    2, 'Disk directory',
    3, 'Active change directory',
    4, 'Continuing operations directory',
    5, 'Template directory',
    6, 'Alias directory',
    7, 'AVD volume file directory',
    8, 'Disk free space directory',
    9, 'Attributes directory',
    10, 'ASM user directory',
    11, 'ASM user group directory',
    12, 'Staleness directory',
    13, 'Password directory',
    253, 'ASM spfile',
    254, 'Stale bitmap space registry ',
    255, 'Oracle Cluster Repository ')
  "ASM metadata file name",
  count(AU_KFFXP) "Allocation units"
from X$KFFXP
where GROUP_KFFXP = 2    -- disk group 2
  and NUMBER_KFFXP < 256 -- ASM metadata files
group by NUMBER_KFFXP
;

ASM file number ASM metadata file name          Allocation units
--------------- ------------------------------- ----------------
              1 File directory                                 3
              2 Disk directory                                 3
              3 Active change directory                       69
              4 Continuing operations directory                6
              5 Template directory                             3
              6 Alias directory                                3
              8 Disk free space directory                      3
              9 Attributes directory                           3
             12 Staleness directory                            3
            253 ASM spfile                                     2
            254 Stale bitmap space registry                    3
            255 Oracle Cluster Repository                     83

12 rows selected.

SQL>
As we can see, the disk group does not have to have all metadata files.

4. ASM metadata blocks

ASM metadata is organized in ASM blocks, with the default block size of 4KB. Note that ASM blocks are independent and not related to Oracle database blocks or their sizes. An ASM block consists of a common block header and the rest of ASM metadata that would be block type specific.
The following are the ASM metadata block types:
  • KFBTYP_DISKHEAD - The ASM disk header - the very first block in every ASM disk. A copy of this block will be in the second last Partnership and Status Table (PST) block (in ASM version 11.1.0.7 and later). The copy of this block will also be in the very first block in Allocation Unit 11, for disk groups with COMPATIBLE.ASM=12.1 or higher.
  • KFBTYP_FREESPC - The Free Space Table block.
  • KFBTYP_ALLOCTBL - The Allocation Table block.
  • KFBTYP_PST_META - The Partnership and Status Table (PST) block. The PST blocks 0 and 1 will be of this type.
  • KFBTYP_PST_DTA - The PST blocks with the actual PST data.
  • KFBTYP_PST_NONE - The PST block with no PST data. Remember that Allocation Unit 1 (AU1) on every disk is reserved for the PST, but only some disks will have the PST data.
  • KFBTYP_HBEAT - The heartbeat block, in the PST.
  • KFBTYP_FILEDIR - The File Directory block.
  • KFBTYP_INDIRECT - The Indirect File Directory block, containing a pointer to another file directory block.
  • KFBTYP_LISTHEAD - The Disk Directory block. The very first block in the ASM disk directory. The field kfdhdb.f1b1locn in the ASM disk header will point the the allocation unit whose block 0 will be of this type.
  • KFBTYP_DISKDIR - The rest of the blocks in the Disk Directory will be of this type.
  • KFBTYP_ACDC - The Active Change Directory (ACD) block. The very first block of the ACD will be of this type.
  • KFBTYP_CHNGDIR - The blocks with the actual ACD data.
  • KFBTYP_COD_BGO - The Continuing Operations Directory (COD) block for background operations data.
  • KFBTYP_COD_RBO - The COD block that marks the rollback operations data.
  • KFBTYP_COD_DATA - The COD block with the actual rollback operations data.
  • KFBTYP_TMPLTDIR - The Template Directory block.
  • KFBTYP_ALIASDIR - The Alias Directory block.
  • KFBTYP_SR - The Staleness Registry block.
  • KFBTYP_STALEDIR - The Staleness Directory block.
  • KFBTYP_VOLUMEDIR -The ADVM Volume Directory block.
  • KFBTYP_ATTRDIR -The Attributes Directory block.
  • KFBTYP_USERDIR - The User Directory block.
  • KFBTYP_GROUPDIR - The User Group Directory block.
  • KFBTYP_USEDSPC - The Disk Used Space Directory block.
  • KFBTYP_ASMSPFALS -The ASM spfile alias block.
  • KFBTYP_PASWDDIR - The ASM Password Directory block.
  • KFBTYP_INVALID - Not an ASM metadata block.
Note that the KFBTYP_INVALID is not an actual block type stored in ASM metadata block. Instead, ASM will return this if it encounters a block where the type is not one of the valid ASM metadata block types. For example if the ASM disk header is corrupt, say zeroed out, ASM will report it as KFBTYP_INVALID. We will also see the same when reading such block with the kfed tool.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Connect to your ASM instance(s) and execute the first 3 scripts below (on each node if this is RAC configuration).

2) Also, execute the script #4  (located below) through ASMCMD to gather complementary metadata information (on each node if this is RAC configuration)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Script #1 (Generic ASM metadata):

SPOOL ASM<#>_GENERIC_ASM_METADATA.html
-- ASM VERSIONS 10.1, 10.2, 11.1,  11.2 & 12.1
SET MARKUP HTML ON
SET ECHO ON

SET PAGESIZE 200

ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';

SELECT 'THIS ASM REPORT WAS GENERATED AT: ==)> ' , SYSDATE " "  FROM DUAL;
SELECT 'INSTANCE NAME: ==)> ' , INSTANCE_NAME " " FROM V$INSTANCE;

SELECT 'HOSTNAME ASSOCIATED WITH THIS ASM INSTANCE: ==)> ' , MACHINE " " FROM V$SESSION WHERE PROGRAM LIKE '%SMON%';

SELECT * FROM V$INSTANCE;

SELECT * FROM GV$INSTANCE;

SELECT * FROM V$ASM_DISKGROUP;

SELECT * FROM  V$ASM_DISK ORDER BY GROUP_NUMBER,DISK_NUMBER;

SELECT SUBSTR(D.NAME,1,16) AS ASMDISK, D.MOUNT_STATUS, D.STATE,
     DG.NAME AS DISKGROUP FROM V$ASM_DISKGROUP DG, V$ASM_DISK D
     WHERE DG.GROUP_NUMBER = D.GROUP_NUMBER;


SELECT * FROM V$ASM_CLIENT;

 SELECT DG.NAME AS DISKGROUP, SUBSTR(C.INSTANCE_NAME,1,12) AS INSTANCE,
    SUBSTR(C.DB_NAME,1,12) AS DBNAME, SUBSTR(C.SOFTWARE_VERSION,1,12) AS SOFTWARE,
    SUBSTR(C.COMPATIBLE_VERSION,1,12) AS COMPATIBLE
    FROM V$ASM_DISKGROUP DG, V$ASM_CLIENT C
    WHERE DG.GROUP_NUMBER = C.GROUP_NUMBER;

SELECT * FROM V$ASM_ATTRIBUTE;

SELECT * FROM V$ASM_OPERATION;
SELECT * FROM GV$ASM_OPERATION;


SELECT * FROM V$VERSION;


SELECT * FROM   V$ASM_ACFSSNAPSHOTS;
SELECT * FROM   V$ASM_ACFSVOLUMES;
SELECT * FROM   V$ASM_FILESYSTEM;
SELECT * FROM   V$ASM_VOLUME;
SELECT * FROM   V$ASM_VOLUME_STAT;

SELECT * FROM   V$ASM_USER;
SELECT * FROM   V$ASM_USERGROUP;
SELECT * FROM   V$ASM_USERGROUP_MEMBER;

SELECT * FROM   V$ASM_DISK_IOSTAT;
SELECT * FROM   V$ASM_DISK_STAT;
SELECT * FROM   V$ASM_DISKGROUP_STAT;

SELECT * FROM   V$ASM_TEMPLATE;

SHOW PARAMETER

SHOW SGA

!echo "SELECT '" > /tmp/GPNPTOOL.SQL 2> /dev/null
! $ORACLE_HOME/bin/gpnptool get >> /tmp/GPNPTOOL.SQL 2>> /dev/null
!echo "'  FROM DUAL;" >> /tmp/GPNPTOOL.SQL 2>> /dev/null
! cat /tmp/GPNPTOOL.SQL
SET ECHO OFF

--DISPLAYS INFORMATION ABOUT THE CONTENTS OF THE SPFILE.
SELECT *  FROM  V$SPPARAMETER  ORDER BY 2;
SELECT *  FROM  GV$SPPARAMETER  ORDER BY 3;

--DISPLAYS INFORMATION ABOUT THE INITIALIZATION PARAMETERS THAT ARE CURRENTLY IN EFFECT IN THE INSTANCE.
SELECT *  FROM  V$SYSTEM_PARAMETER ORDER BY 2;
SELECT *  FROM  GV$SYSTEM_PARAMETER ORDER BY 3;


-- 12C ACFS VIEWS

SELECT * FROM  V$ASM_ACFS_ENCRYPTION_INFO;
SELECT * FROM  V$ASM_ACFSREPL;
SELECT * FROM  V$ASM_ACFSREPLTAG;
SELECT * FROM  V$ASM_ACFS_SEC_ADMIN;
SELECT * FROM  V$ASM_ACFS_SEC_CMDRULE;
SELECT * FROM  V$ASM_ACFS_SEC_REALM;
SELECT * FROM  V$ASM_ACFS_SEC_REALM_FILTER;
SELECT * FROM  V$ASM_ACFS_SEC_REALM_GROUP;
SELECT * FROM  V$ASM_ACFS_SEC_REALM_USER;
SELECT * FROM  V$ASM_ACFS_SEC_RULE;
SELECT * FROM  V$ASM_ACFS_SEC_RULESET;
SELECT * FROM  V$ASM_ACFS_SEC_RULESET_RULE;
SELECT * FROM  V$ASM_ACFS_SECURITY_INFO;
SELECT * FROM  V$ASM_ACFSTAG;

-- 12C ASM AUDIT VIEWS

SELECT * FROM  V$ASM_AUDIT_CLEAN_EVENTS;
SELECT * FROM  V$ASM_AUDIT_CLEANUP_JOBS;
SELECT * FROM  V$ASM_AUDIT_CONFIG_PARAMS;
SELECT * FROM  V$ASM_AUDIT_LAST_ARCH_TS;

-- 12C ASM ESTIMATE VIEW

SELECT * FROM  V$ASM_ESTIMATE;
SELECT * FROM  GV$ASM_ESTIMATE;


SPOOL OFF

EXIT

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Script #2 (ASM Files & ASM Alias):


 spool asm<#>_alias+files.html
-- ASM Versions 10.1, 10.2, 11.1,  11.2 & 12.1
SET MARKUP HTML ON
set echo on

set pagesize 200

COLUMN BYTES FORMAT  9999999999999999

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';

select 'THIS ASM REPORT WAS GENERATED AT: ==)> ' , sysdate " "  from dual;


select 'HOSTNAME ASSOCIATED WITH THIS ASM INSTANCE: ==)> ' , MACHINE " " from v$session where program like '%SMON%';

select * from v$asm_alias;

select * from v$asm_file;

show parameter asm
show parameter cluster
show parameter instance_type
show parameter instance_name
show parameter spfile

show sga

spool off

exit

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Script #3 (ASM Full Path Alias Directory):

spool asm<#>_full_path_alias_directory.html
-- ASM Versions 10.1, 10.2, 11.1,  11.2 & 12.1
SET MARKUP HTML ON
set echo on

set pagesize 200

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';

select 'THIS ASM REPORT WAS GENERATED AT: ==)> ' , sysdate " "  from dual;


select 'HOSTNAME ASSOCIATED WITH THIS ASM INSTANCE: ==)> ' , MACHINE " " from v$session where program like '%SMON%';

SELECT CONCAT('+'||GNAME, SYS_CONNECT_BY_PATH(ANAME, '/'))
 FULL_PATH, SYSTEM_CREATED, ALIAS_DIRECTORY, FILE_TYPE
 FROM ( SELECT B.NAME GNAME, A.PARENT_INDEX PINDEX,
 A.NAME ANAME, A.REFERENCE_INDEX RINDEX,
 A.SYSTEM_CREATED, A.ALIAS_DIRECTORY,
 C.TYPE FILE_TYPE
 FROM V$ASM_ALIAS A, V$ASM_DISKGROUP B, V$ASM_FILE C
 WHERE A.GROUP_NUMBER = B.GROUP_NUMBER
 AND A.GROUP_NUMBER = C.GROUP_NUMBER(+)
 AND A.FILE_NUMBER = C.FILE_NUMBER(+)
 AND A.FILE_INCARNATION = C.INCARNATION(+)
 )
 START WITH (MOD(PINDEX, POWER(2, 24))) = 0
 CONNECT BY PRIOR RINDEX = PINDEX;


spool off

exit

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Script #4 (ASMCMD commands to gather complementary metadata information):


################################################################################################
### Script Name:  asmcmd_script.sh                                                                                     ###   
################################################################################################
###  The next script generates additional ASM metadata information thru the ASMCMD interface ###
################################################################################################
###  Author: Esteban D. Bernal                                                               ###
################################################################################################
###  Property: Oracle Corporation                                                            ###
################################################################################################


echo "ASMCMD commands to gather complementary metadata information:"    > /tmp/asmcmd_script.out                2> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p ls -ls        >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsattr        >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsct  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsdg  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsdsk >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsof  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsod  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p iostat        >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p dsget >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p lsop  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p spget >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p  lstmpl       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p   lsusr       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p  lsgrp        >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p   lspwusr     >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
asmcmd -p   volinfo -a  >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "=================================="       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
echo "                                  "       >> /tmp/asmcmd_script.out               2>> /tmp/asmcmd_script.out
##############################################################################################################

Note: On Windows environments the “2> /tmp/asmcmd_script.out” or “2>> /tmp/asmcmd_script.out” statements is not required, thus it can be omitted.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[grid@node02 ~]$ . oraenv
ORACLE_SID = [+ASM] ? +ASM
The Oracle base remains unchanged with value /u01/app/grid
[grid@node02 ~]$
[grid@node02 ~]$ ./asmcmd_script.sh
[grid@node02 ~]$


Output file:

[grid@node02 ~]$ ls -l /tmp/asmcmd_script.out
-rw-r--r-- 1 grid oinstall 15873 Nov  6 11:03 /tmp/asmcmd_script.out


 Ref:

 

 

No comments:

Post a Comment