Sei sulla pagina 1di 2

DETERMINING THE OPTIMAL UNDO RETENTION PERIOD

You can specify the length of time Oracle will retain undo data after a transaction commits, by
specifying
the UNDO_RETENTIONparameter
SQl> alter system set undo_retention=1800 scope=both;
System altered.
(1) Calculate the amount of undo that database is generating
select sum(d.bytes) "undo" from v$datafile d, v$tablespace t, dba_tablespaces s where s.contents
= 'UNDO' and s.status = 'ONLINE' and t.name = s.tablespace_name and d.ts# = t.ts#;
UNDO
---------104857600
(2) calculate the value of UNDO_BLOCKS_PER_SECwith the following query
select max(undoblks/((end_time-begin_time)*3600*24)) "UNDO_BLOCK_PER_SEC" FROM
v$undostat;
UNDO_BLOCK_PER_SEC
-----------------7.625
(3) Check the block size of database
show parameter db_block_size. Lets say the db_block_sizeis 8 KB
(4) Undo Retention
UNDO_RETENTION = UNDO SIZE/(DB_BLOCK_SIZE*UNDO_BLOCK_PER_SEC)
Undo Retention =1,678.69 = 104,857,600/(7.625 * 8,192)
the database uses the following criteria to determine how long it needs to retain undo data:
Length of the longest-running query
Length of the longest-running transaction
Longest flashback duration
FINDING WHAT IS CONSUMING THE MOST UNDO
High undo usage often involves a long-running query
to find out which SQL statement has run for the longest time in your database.
SQL> select s.sql_text from v$sql s, v$undostat u where u.maxqueryid=s.sql_id;
to find out the most undo used by a session for a currently executing transaction,
SQL> select s.sid, s.username, t.used_urec, t.used_ublk from v$session s, v$transaction t
where s.saddr = t.ses_addr order by t.used_ublk desc;

to find out which session is currently using the most undo in an instance
SQL>select s.sid, t.name, s.value from v$sesstat s, v$statname t where s.statistic# = t.statistic#
and t.name = 'undo change vector size' order by s.value desc;
another query that joins the V$TRANSACTION, V$SQLand V$SESSION views:
SQL> select sql.sql_text sql_text, t.USED_UREC Records, t.USED_UBLK Blocks,
(t.USED_UBLK*8192/1024) KBytes from v$transaction t, v$session s, v$sql sql
where t.addr = s.taddr and s.sql_id = sql.sql_id and s.username ='&USERNAME'
The column USED_URECshows the number of undo records used, and the USED_UBLKcolumn
shows the undo blocks consumed by a transaction.

Potrebbero piacerti anche