Package DBMS_HM – Health Monitor
Autor: ORACLE Place | Publicado: 2013-12-02T02:20:00-08:00





A partir da
versão 11g a Oracle disponibilizou uma “package” que permite realizar testes e
diagnosticar problemas no banco de dados, seu nome é DBMS_HM. Neste artigo
vamos demonstrar o uso da DBMS_HM.

&nbsp;





NOTA: Neste artigo será abordada somente a execução manual utilizando
o SQL*Plus. Para a ativação ou execução via Enterprise Manager, favor verificar
o manual (Oracle®
Database Administrator´s Guide 11gR2).




&nbsp;

A “package”
DBMS_HM, permite examinar várias camadas e componentes do banco de
dados. Com ela é possível detectar corrupções de “datafiles”, corrupções de
blocos lógicos e físicos, corrupção de segmentos de “undo” ou de “redo” e
corrupções no dicionário de dados. As análises geram relatórios e em muitos
casos, a DBMS_HM faz recomendações para resolver os problemas encontrados. 

&nbsp;

As verificações podem ser
executadas de duas formas:


Reativa: O diagnóstico pode ser executado de modo automático
em resposta a um erro crítico ocorrido.

&nbsp;

Manual: O DBA pode
executar manualmente verificações utilizando a “package” DBMS_HM ou a interface
do Enterprise Manager. 

&nbsp;

As verificações podem ser
executadas com o banco “online” ou em “offline” (modo NOMOUNT).


Somente a verificação “Integrity Check Redo e o DB Structure Integrity Check”,
não pode ser realizada no modo “online”, as demais todas podem ser executadas.

&nbsp;

Tipos de verificações:

&nbsp;

DB Structure Integrity Check: Verifica a integridade dos “datafiles” e gera
relatórios de falhas se esses arquivos estiverem inacessíveis, corrompidos ou
inconsistentes. Se o banco de dados estiver “online” verifica os arquivos de “redolog”,
“datafiles” e “controlfile”. Se o banco de dados estiver “offline” verifica apenas
os arquivos de “controlfiles”.

&nbsp;

Data Block Integrity Check: Verifica e detecta corrupções
nos blocos dos discos, tais como falhas de checksum, incompatibilidades com os
“headers e tails” e inconsistências lógicas dentro do bloco. 


Redo Integrity Check: Verifica se o conteúdo do “redolog”
não está corrompido.

&nbsp;

Undo Segment Integrity Check: Verifica se o segmento de “undo”
possui corrupções. Ao localizar uma corrupção no segmento de “undo”, essa
verificação usa os processos de “PMON” e “SMON” para tentar recuperar a
transação corrompida. Se esta recuperação falhar, então a package DBMS_HM armazena
as informações sobre a corrupção na visão V$CORRUPT_XID_LIST.

&nbsp;

Transaction Integrity Check: Verificação identica a “Undo
Segment Integrity Check” exceto que é verifica apenas uma transação
específica.


Dicionário Integrity Check: Verificação que examina a
integridade dos objetos do dicionário de dados.

&nbsp;

&nbsp;

A seguir serão apresentados os
passos para a execução da verificação da base de dados, utilizando a “package”
DBMS_HM.

&nbsp;

Conectar-se ao SQL*Plus com o usuário
SYS.

&nbsp;

SQL&gt; conn / as sysdba

&nbsp;

Connected.

Verificar quais são as opções disponíveis para o “check” no banco de
dados, consultar a visão V$HM_CHECK:



SQL&gt; SELECT name
FROM v$hm_check WHERE internal_check='N';



NAME

----------------------------------------------------------------

DB Structure
Integrity Check

CF Block Integrity
Check

Data Block Integrity
Check

Redo Integrity Check

Transaction Integrity
Check

Undo Segment
Integrity Check

Dictionary Integrity
Check

ASM Allocation Check



8 rows selected.



A maioria das
verficações do banco de dados são apresentadas através da visão
V$HM_CHECK_PARAM.



SQL&gt; SET LINESIZE
200

SQL&gt; SET PAGES 200

SQL&gt; COLUMN
CHECK_NAME&nbsp;&nbsp;&nbsp;&nbsp; FORMAT A30 HEADING
"NOME"

SQL&gt; COLUMN
PARAMETER_NAME FORMAT A20 HEADING "PARAMETROS"

SQL&gt; COLUMN
TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT A15 HEADING
"TIPOS"

SQL&gt; COLUMN
DEFAULT_VALUE&nbsp; FORMAT A15 HEADING
"VALORES DEFAULT"

SQL&gt; COLUMN
DESCRIPTION&nbsp;&nbsp;&nbsp; FORMAT A40 HEADING
"DESCRICAO"

SQL&gt;

SQL&gt; SELECT C.NAME
CHECK_NAME, P.NAME PARAMETER_NAME, P.TYPE, P.DEFAULT_VALUE, P.DESCRIPTION

&nbsp; 2&nbsp;
FROM&nbsp;&nbsp; V$HM_CHECK_PARAM P,
V$HM_CHECK C

&nbsp; 3&nbsp;
WHERE&nbsp; P.CHECK_ID = C.ID

&nbsp; 4&nbsp;
AND&nbsp;&nbsp;&nbsp; C.INTERNAL_CHECK = 'N'

&nbsp; 5&nbsp;
ORDER BY C.NAME;



NOME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PARAMETROS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIPOS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALORES DEFAULT DESCRICAO

---------------------------- -----------------
--------------- --------------- ---------------------

ASM Allocation Check&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASM_DISK_GRP_NAME DBKH_PARAM_TEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASM group name

CF Block Integrity Check&nbsp;&nbsp;&nbsp;&nbsp; CF_BL_NUM&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;DBKH_PARAM_UB4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Control file block 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
number

Data Block Integrity Check&nbsp;&nbsp; BLC_DF_NUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBKH_PARAM_UB4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File number

Data Block Integrity Check&nbsp;&nbsp; BLC_BL_NUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBKH_PARAM_UB4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Block number

Dictionary Integrity Check&nbsp;&nbsp; CHECK_MASK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBKH_PARAM_TEXT ALL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Check mask

Dictionary Integrity Check&nbsp;&nbsp; TABLE_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBKH_PARAM_TEXT ALL_CORE_TABLES Table
name

Redo Integrity Check&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SCN_TEXT&nbsp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ected.



A procedure utilizada para executar uma verficação no banco de dados é a
“DBMS_HM.RUN_CHECK”.





SQL&gt; BEGIN

&nbsp; DBMS_HM.run_check (

&nbsp; &nbsp; check_name &nbsp; =&gt; 'DB Structure Integrity Check',

&nbsp; &nbsp; run_name &nbsp; &nbsp; =&gt; 'TESTE_VERIF');

END;

/



PL/SQL procedure successfully completed.



Os resultados da verificação podem ser apresentados usando alguns dos recursos descrito abaixo:



Através da execução da função DBMS_HM.GET_RUN_REPORT, que retorna
um relatório dos resultados em
formato texto, HTML ou XML.

Os resultados também podem ser consultados diretamente nas visões V$HM_RUN, V$HM_FINDING e na V$HM_RECOMMENDATION.

&nbsp; &nbsp; &nbsp; O Oracle Enterprise Manager permite utilizar o “Health Monitor”.&nbsp;



Abaixo é apresentada a saída da verificação, utilizando a função DBMS_HM.GET_RUN_REPORT.&nbsp;



SQL&gt; SET LONG 100000

SET LONGCHUNKSIZE 1000

SET PAGESIZE 1000

SET LINESIZE 512

SELECT DBMS_HM.get_run_report('TESTE_VERIF') FROM
dual;



DBMS_HM.GET_RUN_REPORT('TESTE_VERIF')

------------------------------------------------------------------

Basic Run Information

&nbsp;Run Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : TESTE_VERIF

&nbsp;Run Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1

&nbsp;Check Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: DB Structure Integrity Check

&nbsp;Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MANUAL

&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : COMPLETED

&nbsp;Start Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2013-11-19 10:02:10.037605
-02:00

&nbsp;End Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2013-11-19
10:02:10.228833 -02:00

&nbsp;Error
Encountered&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0

&nbsp;Source Incident
Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0

&nbsp;Number of
Incidents Created&nbsp; : 0



Input Paramters for the Run

Run
Findings And Recommendations



Para
esse exemplo não foram
encontrados problemas na base de dados, porém abaixo segue um exemplo de onde
foi encontrado um problema.



SQL&gt; SET LONG 100000

SET LONGCHUNKSIZE 1000

SET PAGESIZE 1000

SET LINESIZE 512

SELECT DBMS_HM.get_run_report('TESTE_VERIF_2') FROM
dual;



DBMS_HM.GET_RUN_REPORT('TESTE_VERIF_2')

------------------------------------------------------------------------------

Basic Run Information

&nbsp;Run Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : teste_verif_2

&nbsp;Run Id&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 2

&nbsp;Check Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : DB Structure Integrity
Check

&nbsp;Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MANUAL

&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : COMPLETED

&nbsp;Start Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2013-11-19 10:02:10.037605
-02:00

&nbsp;End Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2013-11-19
10:02:10.228833 -02:00

&nbsp;Error
Encountered&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0

&nbsp;Source Incident
Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0

&nbsp;Number of
Incidents Created&nbsp; : 0



Input Paramters for the Run

Run Findings And Recommendations

&nbsp;Finding

&nbsp;Finding
Name&nbsp; : Corrupt Datafile

&nbsp;Finding ID&nbsp;&nbsp;&nbsp; : 334

&nbsp;Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : FAILURE

&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : OPEN

&nbsp;Priority&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : HIGH

&nbsp;Message&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Datafile 10:
'/app/oracle/oradata/test01.dbf' is corrupt

&nbsp;Message&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Some objects in tablespace TEST might
be unavailable



Para o exemplo acima será
necessário corrigir a corrupção do “datafile” da tablespace TESTE.



Concluímos portanto que o “Health
Monitor” dá mais um mecanismo para o DBA garantir o pleno
funcionamento do banco de dados.





Referências: Oracle®
Database Administrator´s Guide 11gR2 (11.2)

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Oracle®
Database PL/SQL Packages and Types Reference 11gR2 (11.2)









MSc.
Rubens Oliveira

DBA Oracle Consultor

olivert.dba@consultant.com