1-- UNDO tablespace current usage / available space
2SELECT a.TABLESPACE_NAME, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) AS FREEMB
3FROM (SELECT round(sum(BYTES) / 1e6) AS SIZEMB, b.TABLESPACE_NAME
4 FROM DBA_DATA_FILES a, DBA_TABLESPACES b
5 WHERE a.TABLESPACE_NAME = b.TABLESPACE_NAME AND b.CONTENTS LIKE 'UNDO'
6 GROUP BY b.TABLESPACE_NAME) a,
7 (SELECT c.TABLESPACE_NAME, sum(BYTES) / 1e6 AS USAGEMB
8 FROM DBA_UNDO_EXTENTS c
9 WHERE STATUS <> 'EXPIRED'
10 GROUP BY c.TABLESPACE_NAME) b
11WHERE a.TABLESPACE_NAME = b.TABLESPACE_NAME;
1-- UNDOTBS usage per User:
2SELECT u.TABLESPACE_NAME AS TABLESPACE,
3 s.USERNAME,
4 u.STATUS,
5 sum(u.BYTES) / 1024 / 1024 AS SUM_IN_MB,
6 count(u.SEGMENT_NAME) AS SEG_CNTS
7FROM DBA_UNDO_EXTENTS u, V$TRANSACTION T, V$SESSION s
8WHERE T.ADDR = s.TADDR
9GROUP BY u.TABLESPACE_NAME, s.USERNAME, u.STATUS
10ORDER BY 1, 2, 3;
1-- UNDO tablespace usage per user / session
2SELECT s.SID, s.USERNAME, round(sum(ss.VALUE) / 1e6, 2) AS UNDO_SIZE_MB,
3 sql.ELAPSED_TIME, sql.SQL_TEXT
4FROM V$SESSTAT ss JOIN V$SESSION s ON s.SID = ss.SID
5 JOIN V$STATNAME STAT ON STAT.STATISTIC# = ss.STATISTIC#
6 LEFT JOIN V$SQLAREA sql
7 ON s.SQL_ADDRESS = sql.ADDRESS AND s.SQL_HASH_VALUE = sql.HASH_VALUE
8WHERE STAT.NAME = 'undo change vector size' AND s.TYPE <> 'BACKGROUND'
9 AND s.USERNAME IS NOT NULL AND ss.VALUE >= 0.01 * 1e6
10GROUP BY s.SID, s.USERNAME, sql.ELAPSED_TIME, sql.SQL_TEXT
11ORDER BY s.USERNAME, round(sum(ss.VALUE) / 1e6, 2);