AWR - ADDM

AWR - Automatic Workload Repository - è una infrastruttura di Oracle 11g che conserva le statistiche, le metriche etc per individuare problemi, valutare le performance ed effettuare tuning del db.
Di default ogni 60 min il processo di background MMON raccoglie le statistiche delle performance (aka snapshot) dalla SGA e li copia nell'AWR che è composto da tabelle memorizzate nel tablespace SYSAUX.



Gli snapshot vengono conservati per un tempo di retention visibile dalla seguente query:

SQL> select * from dba_hist_wr_control

Il parametro di inizializzazione legato alla raccolta delle statistiche è statistics_level che assume tre 
valori
SQL> show parameter statistics_level 

TYPICAL: è quello di default ed è raccomandato
BASE: disabilita
ALL: usato per raccogliere delle statistiche in più tramite una dignostica manuale.


Se si vuole generare un report AWR lanciare lo script seguente:

cd $ORACLE_HOME/rdbms/admin
SQL> sqlplus system/password@$ORACLE_SID @awrrpt.sql

Scegliere il formato di export: esempio txt  perchè di default è html
Enter value for num_days:  “cliccare return”


Instance     DB Name  Snap Id Snap Started    Level
------------ ------------ --------- ------------------ -----
picprod      PICPROD    87140 19 Feb 2019 01:00      1
                             87141 19 Feb 2019 02:00 1
                             87142 19 Feb 2019 03:00 1
                             87143 19 Feb 2019 04:00 1
                             87144 19 Feb 2019 05:00 1
                             87145 19 Feb 2019 06:00 1
                             87146 19 Feb 2019 07:00 1
                             87147 19 Feb 2019 08:00 1

                             87148 19 Feb 2019 09:00 1
                             87149 19 Feb 2019 10:00 1
                             87150 19 Feb 2019 11:00 1
                             87151 19 Feb 2019 12:00 1
                             87152 19 Feb 2019 13:00 1
                             87153 19 Feb 2019 14:00 1
                             87154 19 Feb 2019 15:00 1
                             87155 19 Feb 2019 16:00 1
                             87156 19 Feb 2019 17:00 1


Scegliere ad esempio la fascia oraria 15.00 - 16.00
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 87154
Begin Snapshot Id specified: 87154
Enter value for end_snap: 87155

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_87154_87155.html.
To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: /tmp/awrrpt_1_87154_87155.html


Se nella lista degli snapshot c'è una riga bianca, vuol dire che in quel momento non sono state raccolte le statistiche perchè il db è stato spento, pertanto occorre evitare di scegliere quei snap_id (ad esempio 87147 e 87148). Riceveristi l'errore: 
ORA-20200: The instance was shutdown between snapshots 87147 and 87148

Sotto la directory /tmp c’è il file html prodotto.

Nel tempo trascorso "Elapsed" il db ha lavorato "DB Time" quindi vuol dire che il db è attivo..lavora.





Il valore in "Execute to Parse" è basso perché vengono usate query senza bind variable e quindi non usa la memoria.


Questo è importante.


















Il valore "SQL*Net break/reset to client" indica che viene effettuato il “reset to client” cioè killate le sessioni ed in effetti nel database in esame c’è spesso il flush della PGA.

Visaulizzare anche SQL ordered by Elapsed Time  che indica il tempo di esecuzione delle query o dml.
Ad esempio se si verifica che ci sono più insert ci impiegano 1 minuto circa, vedere colonna Elapsed Tme(s), potrebbero rallentare il db.



ADDM - Automatic Diagnostic Database Monitor - gira automaticamente dopo ogni snapshot AWR.
Ogni volta che viene preso uno snapshot, ADDM analizza le performance del periodo corrispondente tra questo snapshot e il precedente e quindi monitora l’istanza e decide se c’è un collo di bottiglia e fornisce delle raccomandazioni su come risolverlo.

Lancio ADDM (questo contiene i consigli da apportare e l'analisi automatica delle performance).

cd $ORACLE_HOME/rdbms/admin
SQL> sqlplus system/password@$ORACLE_SID @addmrpt.sql

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 87154
Begin Snapshot Id specified: 87154
Enter value for end_snap: 87155
End   Snapshot Id specified: 87155

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is addmrpt_1_87154_87155.txt.  To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: /tmp/addmrpt_1_87154_87155.txt

Una raccomandazione interessante è questa

RECOMMENDATION 2: DB Configuration, 11% benefit (380 seconds)
 ACTION: Consider increasing the maximum number of open cursors a
session can have by increasing the value of parameter "open_cursors".
 ACTION: Consider increasing the session cursor cache size by increasing
the value of parameter "session_cached_cursors".
 RATIONALE: The value of parameter "open_cursors" was "1000" during the
analysis period.
 RATIONALE: The value of parameter "session_cached_cursors" was "20"
 during the analysis period.




SQL Tuning Advisor (STA) analizza solo una singola sql statement e fornisce raccomandazioni.

SQL Access Advisor analizza tutte le sql statement in un periodo id tempo e fornisce indicazioni di creazione
di indici, viste materializzate, materialized view log e partizioni per migliorare le performance del db.

Disabilitare AWR
Può essere un'opzione praticabile se AWR sta consumando una grande quantità di spazio nel tablespace SYSAUX.
Questa query indica quante volte viene utilizzato AWR 

SQL> SELECT name, detected_usages detected, total_samples samples, currently_used used, to_char(last_sample_date,'MMDDYYYY:HH24:MI') last_sample, sample_interval interval FROM dba_feature_usage_statistics WHERE name = 'Automatic Workload Repository'; 

NAME                              DETECTED     SAMPLES     USED                 LAST_SAMPLE        INTERVAL 
-------------------- ---------- ---------- ----- -------------- ---------------------------------------------------------------------
 Automatic Workload           15                  169              FALSE                     05012012:23:22       604800 
Repository 

The output mostra che AWR è stato rilevato 15 volte con 169 samples. 

Per disintallarlo: 
# sqlplus /nolog 
SQL> connect / as sysdba
SQL> show parameters statistics_level 
SQL> alter system set statistics_level=basic scope=spfile;
SQL> shutdown immediate
SQL> startup restrict 
# $ORACLE_HOME/rdbms/admin/catnoawr 
SQL> shutdown immediate
SQL>  startup

If the STATISTICS_LEVEL=BASIC during startup while SGA_TARGET is set <> 0 , 
you will see this error. 
SQL> startup restrict
ORA-00824: cannot set SGA_TARGET or MEMORY_TARGET due to existing internal settings
ORA-00848: STATISTICS_LEVEL cannot be set to BASIC with SGA_TARGET or MEMORY_TARGET

This can happen due to changes in the PFILE explicitly or the SPFILE using the ALTER SYSTEM command: 
SQL> alter system set statistics_level = basic scope=spfile; 
The problem is that "...SGA_TARGET cannot be set if STATISTICS_LEVEL=BASIC since the self-tuning mechanism requires information from component advisories that are not enabled at this level. 
It is therefore an error to try to set SGA_TARGET as well as STATISTICS_LEVEL=BASIC at the same time..." 


Post popolari in questo blog

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione

Create e Drop Pluggable Database