|
 |
|
Monitoring UNDO Tips
Oracle Database Tips by Donald BurlesonFebruary 21, 2015
|
Question: How
do I monitor the undo logs in Oracle. I need large
UNDO logs for flashback.
Answer:
Oracle Undo segments support read consistent operations (and
other database operations such as flashback operations).
Also see my notes on how to
display_undo_for_session.
Oracle creates an undo segment in the SYSTEM tablespace when
the database is created. This undo segment only supports
operations in the SYSTEM tablespace. This script will
monitor UNDO usage changes:
select
substr(a.os_user_name,1,15) "OS User",
substr(a.oracle_username,1,8)
"DB User",
substr(b.owner,1,8)
"Schema",
substr(b.object_name,1,20)
"Object Name",
substr(b.object_type,1,10)
"Type",
substr(c.segment_name,1,15)
"RBS",
substr(d.used_urec,1,12)
"# of Records",
e.sid,
e.serial#
from
v$locked_object a,
dba_objects b,
dba_rollback_segs c,
v$transaction d,
v$session e
see code depot for full script
where
a.object_id = b.object_id
and
a.xidusn = c.segment_id
and
a.xidusn = d.xidusn
and
a.xidslot = d.xidslot
and
d.addr = e.taddr;
So, where do we get new undo
segments? We create our undo tablespace with the create undo
tablespace command (we will talk about tablespaces in more
detail next) and Oracle will create the undo segments and
manage the for us automatically.
This script also monitors UNDO
operations using v$session and v$transaction:
select
ses.username,
substr(ses.program,1,20),
tra.used_ublk
from
v$session ses,
v$transaction tra
where
ses.saddr = tra.ses_addr;
In Oracle, monitoring UNDO size can be
controlled with the undo_retention parameter, and the
setting for UNDO are determined by the level of DML activity
in the database. This script will monitor UNDO size
changes. Note that this script monitors UNDO by using
the v$undostat view:
select
d.undo_size/(1024*1024) "ACTUAL UNDO SIZE [MByte]",
SUBSTR(e.value,1,25) "UNDO RETENTION [Sec]",
(TO_NUMBER(e.value) * TO_NUMBER(f.value) *
g.undo_block_per_sec) / (1024*1024) "NEEDED
UNDO SIZE [MByte]" from (
SEE CODE DEPOT FOR FULL SCRIPTS
select SUM(a.bytes)
undo_size FROM v$datafile a,
v$tablespace b, dba_tablespaces c WHERE
c.contents = 'UNDO' AND
c.status = 'ONLINE' AND b.name =
c.tablespace_name AND a.ts# = b.ts# )
d, v$parameter e, v$parameter f, ( SELECT
MAX(undoblks/((end_time-begin_time)*3600*24))
undo_block_per_sec FROM v$undostat )
g WHERE e.name = 'undo_retention' AND f.name = 'db_block_size';
Also, note that the automatic undo
management feature introduced in Oracle 9i has been improved
with the following capabilities.
Some of the undo
management related initialization parameters are eliminated
(starting in Oracle 10g) because the UNDO size is
automatically calculated. These obselete UNDO monitoring
parameters include max_rollback_segment, row_locking,
undo_suppress_errors, serializable, and
transaction_auditing.
This script is useful in determining a
HWM for sessions, for UNDO sizing:
rem session.sql - displays all connected sessions
set echo off;
set termout on; set linesize 80; set pagesize 60;
set newpage 0;
select rpad(c.name||':',11)||rpad('
current logons='|| (to_number(b.sessions_current)),20)||'cumulative
logons='|| rpad(substr(a.value,1,10),10)||'highwater
mark='|| b.sessions_highwater Information from
v$sysstat a, v$license b, v$database c where
a.name = 'logons cumulative' ;
ttitle "dbname
Database|UNIX/Oracle Sessions";
set heading off;
select 'Sessions on database '||substr(name,1,8) from
v$database; set heading on; select substr(a.spid,1,9)
pid, substr(b.sid,1,5) sid, substr(b.serial#,1,5)
ser#, substr(b.machine,1,6) box, substr(b.username,1,10)
username, -- b.server, substr(b.osuser,1,8) os_user,
substr(b.program,1,30) program from
SEE CODE DEPOT FOR
FULL SCRIPTS
v$session b, v$process a where
b.paddr = a.addr and type='USER' order by spid;
ttitle off; set heading off; select 'To kill, enter
SQLPLUS> ALTER SYSTEM KILL SESSION', ''''||'SID,
SER#'||''''||';' from dual; spool off;
For complete scripts to monitor UNDO,
download the
Oracle script
collection.
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

|
|
|
|
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|
|
|
|