Monitoring Undo Tablespace Usage In Oracle: A Comprehensive Guide

how to monitor undo tablespace usage in oracle

Monitoring undo tablespace usage in Oracle is crucial for database management. The undo tablespace is used to store uncommitted data, allowing for rollback or recovery from system failures. Ignoring undo tablespace usage can lead to transaction failures. Oracle provides various queries and scripts to monitor undo space usage and prevent potential issues. These tools help administrators track overall and user-level undo usage, identify space pressure, and manage undo segments efficiently. Additionally, understanding undo tablespace usage is essential for flashback operations and snapshot queries. By proactively monitoring and optimising undo tablespace, administrators can ensure the smooth functioning of their Oracle databases.

Characteristics Values
Purpose of using UNDO Storing all uncommitted data in case it needs to be undone in rollback or after system failures
Query to check overall UNDO usage SQL> column tablespace format a20; SQL> column sum_in_mb format 999999.99; SQL> select tablespace_name tablespace, status, sum(bytes)/1024/1024 sum_in_mb, count(*) counts from dba_undo_extents group by tablespace_name, status order by 1,2;
Query to check user UNDO usage SQL> select u.tablespace_name tablespace, s.username, u.status, sum(u.bytes)/1024/1024 sum_in_mb, count(u.segment_name) seg_cnts from dba_undo_extents u left join v$transaction t on u.segment_name = '_SYSSMU' t.xidusn '$' left join v$session s on t.addr = s.taddr group by u.tablespace_name, s.username, u.status order by 1,2,3;
Script to 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;
Script to monitor 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;
Script to monitor UNDO size changes select d.undo_size/(10241024) "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) / (10241024) "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)360024)) undo_block_per_sec FROM v$undostat ) g WHERE e.name = 'undo_retention' AND f.name = 'db_block_size';
Script to monitor UNDO usage select a.tablespace_name, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) FREEMB from (select sum(bytes) / 1024 / 1024 SIZEMB, b.tablespace_name from dba_data_files a, dba_tablespaces b where a.tablespace_name = b.tablespace_name and b.contents = 'UNDO' group by b.tablespace_name) a, (select c.tablespace_name, sum(bytes) / 1024 / 1024 USAGEMB from DBA_UNDO_EXTENTS c where status <> 'EXPIRED' group by c.tablespace_name) b where a.tablespace_name = b.tablespace_name;
Script to show all tablespace usage for all tablespaces including the UNDO tablespace SELECT /* + RULE / df.tablespace_name "Tablespace", df.bytes / (1024 * 1024) "Size (MB)", SUM(fs.bytes) / (1024 * 1024) "Free (MB)", Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free", Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used" FROM dba_free_space fs, (SELECT tablespace_name,SUM(bytes) bytes FROM dba_data_files GROUP BY tablespace_name) df WHERE fs.tablespace_name (+) = df.tablespace_name GROUP BY df.tablespace_name,df.bytes UNION ALL SELECT / + RULE */ df.tablespace_name tspace, fs.bytes / (1024 * 1024), SUM(df.bytes_free) / (1024 * 1024), Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1), Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes) FROM dba_temp_files fs, (SELECT tablespace_name,bytes_free,bytes_used FROM v$temp_space_header GROUP BY tablespace_name,bytes_free,bytes_used) df WHERE fs.tablespace_name (+) = df.tablespace_name GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used ORDER BY 4 DESC;

shundigital

Using queries to monitor undo space usage

There are several queries that can be used to monitor undo space usage in Oracle. Here are some examples:

Overall undo tablespace usage

Sql

SQL> column tablespace format a20;

SQL> column sum_in_mb format 999999.99;

SQL> select tablespace_name tablespace, status, sum(bytes)/1024/1024 sum_in_mb, count(*) counts from dba_undo_extents group by tablespace_name, status order by 1,2;

This query provides information about the overall usage of undo tablespace, including the tablespace name, status, total size in MB, and the number of counts.

User-level undo tablespace usage

Sql

SQL> select u.tablespace_name tablespace, s.username, u.status, sum(u.bytes)/1024/1024 sum_in_mb, count(u.segment_name) seg_cnts from dba_undo_extents u left join v$transaction t on u.segment_name = '_SYSSMU' || t.xidusn || '$' left join v$session s on t.addr = s.taddr group by u.tablespace_name, s.username, u.status order by 1,2,3;

This query drills down to the user level, providing information about which users are using undo space and how much they are using.

Undo tablespace usage by session

Sql

Select s.sid,s.status, s.username, sum(ss.value) / 1024 / 1024 as undo_size_mb from v$sesstat ss join v$session s on s.sid = ss.sid join v$statname stat on stat.statistic# = ss.statistic# where stat.name = ‘undo change vector size’ and s.type ‘BACKGROUND’ and s.username IS NOT NULL group by s.sid,s.username,s.status;

This query provides information about undo space usage by session, including the session ID, status, username, and the size of undo space used in MB.

Script to monitor UNDO usage changes

Sql

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;

This script monitors UNDO usage changes, providing information about the OS user, DB user, schema, object name, type, rollback segment, number of records, session ID, and serial number.

Script to monitor UNDO size changes

Sql

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';

This script monitors UNDO size changes, providing information about the actual UNDO size in MB, UNDO retention time in seconds, and the needed UNDO size in MB.

shundigital

Viewing full details with a My Oracle Support account

To view full details of how to monitor undo tablespace usage in Oracle, you need to sign in with your My Oracle Support account. My Oracle Support provides customers with access to a large number of knowledge articles and a vibrant support community of peers and Oracle experts.

If you don't already have a My Oracle Support account, you can create one by clicking the "Get Started" button on the Oracle website.

Once you have signed in to your My Oracle Support account, you can access the various queries that can be used to monitor undo space usage. The undo space, once allocated, will not be deallocated to the OS by default. However, the space can be reused by other transactions once the UNDO_RETENTION (or TUNED_UNDORETENTION) period is met.

You can also use My Oracle Support to identify the session or process using a specific undo tablespace. This is useful if you need to shrink the undo tablespace but don't want to reboot the instance. By identifying the sessions or processes using the old undo tablespace, you can kill those sessions and free up space.

Additionally, My Oracle Support provides information on how to check the overall and separate user usage of undo tablespace. This includes details on the active, expired, and unexpired transaction space usage, as well as how to identify the users consuming undo space.

shundigital

The purpose of using UNDO for storing uncommitted data

The primary purpose of using UNDO in Oracle is to store all uncommitted data in case it needs to be rolled back or undone after system failures. This is important because ignoring undo tablespace usage can lead to transaction failures. During busy system hours, the UNDO space can grow very quickly.

The second purpose of using UNDO is for snapshot queries. It is also important to note that changing UNDO_RETENTION is usually ineffective in resolving ORA-01555 errors.

shundigital

How to check overall and separate user usage on UNDO

To check overall and separate user usage on UNDO, you can use the following queries:

Overall UNDO Tablespace Usage

Sql

SQL> column tablespace format a20;

SQL> column sum_in_mb format 999999.99;

SQL> select tablespace_name tablespace, status, sum(bytes)/1024/1024 sum_in_mb, count(*) counts from dba_undo_extents group by tablespace_name, status order by 1,2;

The output of this query will provide information about the tablespace name, its status (ACTIVE, EXPIRED, or UNEXPIRED), the total size of the tablespace in MB, and the number of counts.

User-Level UNDO Tablespace Usage

Sql

SQL> select u.tablespace_name tablespace, s.username, u.status, sum(u.bytes)/1024/1024 sum_in_mb, count(u.segment_name) seg_cnts from dba_undo_extents u left join v$transaction t on u.segment_name = '_SYSSMU' || t.xidusn || '$' left join v$session s on t.addr = s.taddr group by u.tablespace_name, s.username, u.status order by 1,2,3;

This query will give you a breakdown of the tablespace usage by specific users, including their usernames, the tablespace name, status, the amount of space used in MB, and the number of segment names.

By running these queries, you can effectively monitor the usage of the UNDO tablespace and identify any potential issues related to space usage.

shundigital

Monitoring UNDO size changes

Oracle creates an undo segment in the SYSTEM tablespace when the database is created. This undo segment only supports operations in the SYSTEM tablespace. The undo tablespace can be monitored using the following script:

Sql

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;

This script will monitor UNDO usage changes. The size of the UNDO tablespace can be controlled with the `undo_retention` parameter, and the setting for UNDO is determined by the level of DML activity in the database.

The following script will monitor UNDO size changes:

Sql

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';

Note that this script monitors UNDO by using the `v$undostat` view.

The following script is useful in determining a HWM for sessions, for UNDO sizing:

Sql

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;

Frequently asked questions

You can use a script to monitor UNDO usage changes. Here is an example script:

```

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;

```

You can use the v$session and v$transaction views. Here is an example script:

```

select ses.username, substr(ses.program,1,20), tra.used_ublk from v$session ses, v$transaction tra where ses.saddr = tra.ses_addr;

```

You can monitor UNDO size changes by using the v$undostat view. Here is an example script:

```

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';

```

You can use the following script to get the details about undo tablespace usage and find the free space:

```

select a.tablespace_name, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) FREEMB from (select sum(bytes) / 1024 / 1024 SIZEMB, b.tablespace_name from dba_data_files a, dba_tablespaces b where a.tablespace_name = b.tablespace_name and b.contents = 'UNDO' group by b.tablespace_name) a, (select c.tablespace_name, sum(bytes) / 1024 / 1024 USAGEMB from DBA_UNDO_EXTENTS c where status <> 'EXPIRED' group by c.tablespace_name) b where a.tablespace_name = b.tablespace_name;

```

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment