View Other Posts

Disclaimer

All data and information provided on this blog is for informational purposes only. Oracleapps11idba.blogspot.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.Please use your discretion before taking any decisions based on the information in this blog.

Monday, August 31, 2009

How to Monitor Undo Tablespace and Segment Usage


Starting from release 9i oracle introduced Automatic Undo Management to help DBAs and Developers to cope with ORA-01555: snapshot too old error. Ofcourse you can't completely avoid ORA-01555 error but you can tweak some parameters with Automatic Undo Management along with application code tuning to reduce it, Parameters like UNDO_RETENTION parameter, which defines time in minutes how long oracle will keep the committed transactions in UNDO segments.
One should use UNDO advisor in order to calculate optimum UNDO tablespace Size and UNDO_RETENTION parameter value.
Use following SQL script to monitor Undo tablespace and Undo Segments or Rollback Segments usage in Oracle Database.

------------Start of Script-------------------------------------
#!/bin/sh
# Undo Segment Usage
#

SPOOL_FILE=undo_seg.html
FINAL_FILE=Undo_Segments.html
echo "Content-Type: text/html" >> ${FINAL_FILE}
sqlplus -s "/ as sysdba" EOF
set echo off
set pagesize 220
set markup html on spool on
spool ${SPOOL_FILE}
TTITLE CENTER 'Undo Segments Usage'
SELECT gvs.inst_id "Instance",
gvs.SID,
glo.os_user_name "OS User",
glo.oracle_username "DB User",
dbo.owner "Schema",
SUBSTR (dbo.object_name, 1, 30) "Object Name",
SUBSTR (dbo.object_type, 1, 10) "Object Type",
SUBSTR (drs.segment_name, 1, 15) "RBS Name",
gvt.used_urec "# of Records",
gvt.used_ublk "# of Blocks",
drs.tablespace_name "Tablespace"
FROM
gv$locked_object glo,
dba_objects dbo,
dba_rollback_segs drs,
gv$transaction gvt,
gv$session gvs
WHERE glo.object_id = dbo.object_id
AND glo.xidusn = drs.segment_id
AND glo.xidusn = gvt.xidusn
AND glo.xidslot = gvt.xidslot
AND gvt.addr = gvs.taddr
AND gvt.used_ublk > 1000
ORDER BY gvt.used_ublk DESC;
spool off
set markup html off spool off
EOF

if [ `grep -c 'no rows selected' ${SPOOL_FILE}` -eq 1 ]
then
rm ${FINAL_FILE}
rm ${SPOOL_FILE}
exit 0
fi

cat ${SPOOL_FILE} | grep -v 'rows selected' >> ${FINAL_FILE}

(echo "Importance: High"; echo "Subject: $ORACLE_SID: Undo Segment Usage"; cat ${FINAL_FILE}) | /usr/sbin/sendmail -F $ORACLE_SID
test@testorcl.com
rm ${FINAL_FILE}
rm ${SPOOL_FILE}

------------Start of Script--------------------------------------

No comments:

Post a Comment