Error this answers
ORA-30036: unable to extend segment
When the undo tablespace fills up (ORA-30036), or a big delete has been running for hours, you need to know which transactions hold the undo and how much. This script lists every open transaction with its session, module, start time and undo used, then the undo extents by status.
Usage
SQL> @undo.sql
-- undo.sql: undo used by each open transaction, plus undo extent status
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/undo-usage-by-session/
--
-- Usage: @undo.sql
--
-- curr_trx_kb assumes an 8 KB block size: change the 8 if yours differs.
set feed on
set trims on
set lines 200
set pages 80
col sid_serial format a10 heading "S,SER"
col user_stat format a13 trunc heading "User[sts]"
col os_proc format a40 word wrap heading "Machine|[OSProc.OSUser@TERM]"
col lockwait format a1 heading "L|W"
col terminal format a8
col module format a50 trunc heading "Module"
col segment_name format a13 heading "RBS-Name"
col init_rbs_kb heading "RBS|Init KB"
col curr_trx_kb heading "TRX|Curr KB"
col trx_status format a12 heading "TRX-Status"
col TABLESPACE_NAME format a9
break on report
compute sum of curr_trx_kb on report
select
s.sid||','||s.serial# sid_serial
, s.username||'['||substr(s.status,1,3)||']' user_stat
--, s.machine||'['||s.process||'.'||s.osuser||'@'||s.terminal||']' os_proc
--, s.lockwait
, DECODE(s.program||' '||
s.module||' '||
s.action,
' ','MODULE DETAILS N/A'
,s.program||' '||s.module||' '||s.action) module
, t.start_time
--, r.segment_name
, r.TABLESPACE_NAME
--, (r.initial_extent*r.min_extents)/1024 init_rbs_kb
, (t.used_ublk*8*1024)/1024 curr_trx_kb
, decode(t.space, 'YES', 'SPACE TX',
decode(t.recursive, 'YES', 'RECURSIVE TX',
decode(t.noundo, 'YES', 'NO UNDO TX', t.status)
)) trx_status
from v$transaction t
, dba_rollback_segs r
, v$session s
where t.xidusn = r.segment_id
and t.ses_addr = s.saddr
order by sid;
select tablespace_name,STATUS,count(*),ceil(sum(bytes/1024/1024)) MB_SZ
from dba_undo_extents
group by tablespace_name,status
order by 1;
select ceil(sum(RSSIZE)/1024/1024) "UNDO Current Used Size (MB)" from v$rollstat a;curl -O https://hashjoin.com/kb/oracle/undo-usage-by-session/undo.sql
Reading the output
The first section has one row per open transaction. TRX Curr KB is the undo it holds right now; it only grows until the transaction commits or rolls back. A transaction that started hours ago with a large and growing number is the one to talk to its owner about.
The second section groups undo extents by status:
ACTIVE: in use by open transactions; can't be reused.UNEXPIRED: committed, but kept forundo_retentionso long-running queries can still read consistent data.EXPIRED: free to reuse.
ORA-30036 means there was no EXPIRED space left and the tablespace couldn't grow. Lots of ACTIVE means a big open transaction; lots of UNEXPIRED means retention is holding the space.
Gotchas
TRX Curr KBassumes an 8 KB block size. Change the8in the script if yourdb_block_sizediffers.- Killing a big transaction doesn't free its undo right away. It has to roll back first, which can take as long as the work did.
- It reads
v$views, so on RAC it shows the instance you're connected to.
What it reads
v$transaction v$session dba_rollback_segs dba_undo_extents v$rollstat
Related
- Parallel DML: the slaves of a query coordinator and the undo each uses
- Who is blocking whom across RAC instances (gv$lock decoded)
Tired of fixing the same thing twice?
HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.
New fixes and field notes by email, about once a month.