Expurgando dados do AWR manualmente
Autor: ORACLE Place | Publicado: 2013-11-02T19:36:00-07:00



Mesmo com as
rotinas de retenção que são configuradas no AWR, algumas vezes, pode ser que o
repositório do AWR necessite ser expurgado manualmente. Neste artigo vamos
demonstrar um procedimento para o expurgo controlado do repositório do AWR.

&nbsp;

Importante: Para a execução deste procedimento, certifique-se
que seus dados foram “salvos” em um “backup” ou mesmo que você não irá utilizar
as informações que serão removidas.

&nbsp;

A primeira
coisa que devemos verificar é a quantidade de informação armazenada pelo AWR,
deve-se executar a consulta abaixo:

&nbsp;

SQL&gt; set lines 200

SQL&gt; col Nome&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for
a10

SQL&gt; col Descrição&nbsp; for a60

SQL&gt;

SQL&gt; SELECT OCCUPANT_NAME
NOME,

&nbsp;
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OCCUPANT_DESC DESCRIÇÃO,

&nbsp;
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ROUND(
SPACE_USAGE_KBYTES/1024) "ESPAÇO (M)"

&nbsp;
4&nbsp;&nbsp;&nbsp; FROM V$SYSAUX_OCCUPANTS

&nbsp;
5&nbsp;&nbsp; WHERE OCCUPANT_NAME LIKE
'SM/%'

&nbsp;
6&nbsp;&nbsp; ORDER BY 1&nbsp; ;

&nbsp;

NOME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DESCRIÇÃO&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;
ESPAÇO (M)

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

SM/ADVISOR Server Manageability -
Advisor Framework&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;
323

SM/AWR&nbsp;&nbsp;&nbsp;&nbsp; Server Manageability - Automatic Workload
Repository&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4187

SM/OPTSTAT Server Manageability -
Optimizer Statistics History&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
344

SM/OTHER&nbsp;&nbsp; Server Manageability - Other Components&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; 8

&nbsp;

&nbsp;

A linha
em destaque é a informação que desejamos saber, ou seja, o tamanho do
repositório de dados do AWR, para este exemplo, o tamanho do repositório é de 4
MB.

&nbsp;

Depois vamos
verificar os intervalos de meses que estão armazenados no repositório para que
posteriormente executemos o expurgo.

&nbsp;

SQL&gt;
COL BEGIN_INTERVAL_TIME FOR A30

SQL&gt;
COL END_INTERVAL_TIME&nbsp;&nbsp; FOR A30

SQL&gt;

SQL&gt;
SELECT SNAP_ID, BEGIN_INTERVAL_TIME, END_INTERVAL_TIME

&nbsp; 2&nbsp;&nbsp;&nbsp;
FROM SYS.WRM$_SNAPSHOT

&nbsp; 3&nbsp;&nbsp;
WHERE SNAP_ID = (SELECT MIN (SNAP_ID) FROM SYS.WRM$_SNAPSHOT)

&nbsp; 4 UNION

&nbsp; 5 SELECT SNAP_ID, BEGIN_INTERVAL_TIME,
END_INTERVAL_TIME

&nbsp; 6&nbsp;&nbsp;&nbsp;
FROM SYS.WRM$_SNAPSHOT

&nbsp; 7&nbsp;&nbsp;
WHERE SNAP_ID = (SELECT MAX (SNAP_ID) FROM SYS.WRM$_SNAPSHOT)

&nbsp; 8 ORDER BY 2

&nbsp; 9 /

&nbsp;

&nbsp;&nbsp; SNAP_ID BEGIN_INTERVAL_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END_INTERVAL_TIME

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

&nbsp;&nbsp; &nbsp;156971 27-SEP-13 12.00.29.580 AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27-SEP-13 12.10.31.001 AM

&nbsp;&nbsp;&nbsp; 160065 18-OCT-13
11.40.27.729 AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18-OCT-13
11.50.28.105 AM

&nbsp;

Os
valores apresentados pela coluna SNAP_ID, indicam as informações gravadas no
repositório do AWR. Neste exemplo temos informações do mês de Setembro e
Outubro.

&nbsp;

Antes de
removermos os dados, vamos verificar os registros de um determinado intervalo,
para esse exemplo vamos listar todos os registros do mês de Setembro.

&nbsp;

SQL&gt; col begin_interval_time
for a30

&nbsp;

SELECT snap_id, begin_interval_time

&nbsp;
FROM SYS.WRM$_SNAPSHOT

&nbsp;WHERE instance_number = 1

&nbsp;&nbsp;
AND begin_interval_time like '%SEP%'

&nbsp;order by 1;

/

&nbsp;

&nbsp;&nbsp;
SNAP_ID BEGIN_INTERVAL_TIME

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

&nbsp;&nbsp;&nbsp; 156971 27-SEP-13
12.00.29.580 AM

&nbsp;&nbsp;&nbsp; 156972 27-SEP-13 12.10.31.001 AM

&nbsp;&nbsp;&nbsp; 156973 27-SEP-13 12.20.31.381 AM

&nbsp;&nbsp;&nbsp; 156974 27-SEP-13 12.30.31.722 AM

&nbsp;&nbsp;&nbsp; .

&nbsp;&nbsp;&nbsp; .

&nbsp;&nbsp;&nbsp; .

&nbsp;&nbsp;&nbsp; 157543 30-SEP-13 11.20.24.685 PM

&nbsp;&nbsp;&nbsp; 157544 30-SEP-13 11.30.27.979 PM

&nbsp;&nbsp;&nbsp; 157545 30-SEP-13 11.40.28.395 PM

&nbsp;&nbsp;&nbsp; 157546 30-SEP-13
11.50.34.756 PM

&nbsp;

De posse das informações a serem expurgadas
(SNAP_ID), deve-se executar o passo abaixo:

&nbsp;

SQL&gt; execute dbms_workload_repository.drop_snapshot_range(low_snap_id
=&gt; 156971, high_snap_id=&gt;157546);

&nbsp;

&nbsp;

PL/SQL procedure successfully completed.

&nbsp;

&nbsp;

Para a execução da DBMS_WORKLOAD_REPOSITORY, deve-se
informar o intervalo inicial e final, em destaque no texto e apresentado na
relação (coluna SNAP_ID). Para esse exemplo a rotina irá remover as linhas
referentes ao mês de Setembro.



Após o expurgo, podemos verificar
agora que temos somente o mês de Outubro.



SQL&gt; COL END_INTERVAL_TIME&nbsp;&nbsp; FOR
A30

SQL&gt;

SQL&gt; SELECT SNAP_ID, BEGIN_INTERVAL_TIME, END_INTERVAL_TIME

&nbsp; 2&nbsp;&nbsp;&nbsp; FROM SYS.WRM$_SNAPSHOT

&nbsp; 3&nbsp;&nbsp; WHERE SNAP_ID = (SELECT MIN (SNAP_ID) FROM
SYS.WRM$_SNAPSHOT)

&nbsp; 4 UNION

&nbsp; 5 SELECT SNAP_ID,
BEGIN_INTERVAL_TIME, END_INTERVAL_TIME

&nbsp; 6&nbsp;&nbsp;&nbsp; FROM SYS.WRM$_SNAPSHOT

&nbsp; 7&nbsp;&nbsp; WHERE SNAP_ID = (SELECT MAX (SNAP_ID) FROM
SYS.WRM$_SNAPSHOT)

&nbsp; 8 ORDER BY 2

&nbsp; 9 /



&nbsp;&nbsp; SNAP_ID BEGIN_INTERVAL_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END_INTERVAL_TIME

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

&nbsp;&nbsp;&nbsp; 157547 01-OCT-13 12.00.35.054 AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 01-OCT-13
12.10.38.520 AM

&nbsp;&nbsp;&nbsp; 160075 18-OCT-13 01.20.39.554 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18-OCT-13
01.30.39.997 PM





Referências: Oracle®
Database Performance Tuning Guide 11gR2 (11.2)

Oracle®
Database Concepts 11gR2 (11.2)









MSc.
Rubens Oliveira

DBA Oracle Consultor

olivert.dba@consultant.com