-- UNDO tablespace current usage / available space
SELECT a.TABLESPACE_NAME, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) AS FREEMB
FROM (SELECT round(sum(BYTES) / 1e6) AS SIZEMB, b.TABLESPACE_NAME
FROM DBA_DATA_FILES a, DBA_TABLESPACES b
WHERE a.TABLESPACE_NAME = b.TABLESPACE_NAME AND b.CONTENTS LIKE '%UNDO%'
GROUP BY b.TABLESPACE_NAME) a,
(SELECT c.TABLESPACE_NAME, sum(BYTES) / 1e6 AS USAGEMB
FROM DBA_UNDO_EXTENTS c
WHERE STATUS <> 'EXPIRED'
GROUP BY c.TABLESPACE_NAME) b
WHERE a.TABLESPACE_NAME = b.TABLESPACE_NAME;
-- UNDOTBS usage per User:
SELECT u.TABLESPACE_NAME AS TABLESPACE,
s.USERNAME,
u.STATUS,
sum(u.BYTES) / 1024 / 1024 AS SUM_IN_MB,
count(u.SEGMENT_NAME) AS SEG_CNTS
FROM DBA_UNDO_EXTENTS u, V$TRANSACTION T, V$SESSION s
WHERE T.ADDR = s.TADDR
GROUP BY u.TABLESPACE_NAME, s.USERNAME, u.STATUS
ORDER BY 1, 2, 3;