Home / Databases / Oracle

DatabasesRunbookAdvanced

Sev1: Oracle ORA-30036 unable to extend segment in undo tablespace. Transactions fail across the database

DML fails with ORA-30036 because undo is full. Find the transaction filling it, add undo space safely, decide whether to kill the session, and stop it happening again.

Deepak Bhardwaj6 min read

Applies toOracle Database 19c and 23ai (single instance and RAC, CDB with local undo), Amazon RDS for Oracle, OCI Base Database Service

Symptoms

  • Inserts, updates and deletes fail with ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS1'. The number and tablespace name vary.
  • One large batch job is often still running. Other sessions start failing once the undo tablespace runs out.
  • Long-running queries may also fail with ORA-01555 snapshot too old while undo is under pressure.
  • Selects without DML still work.

1. Confirm which undo tablespace is full

In a CDB with local undo (the default since 12.2), each PDB has its own undo tablespace. Connect to the PDB that reports the error. In RAC, each instance has its own undo tablespace, so check every instance.

SELECT inst_id, value AS undo_tablespace
FROM gv$parameter
WHERE name = 'undo_tablespace';

SELECT tablespace_name, file_name,
       ROUND(bytes/1024/1024)    AS size_mb,
       ROUND(maxbytes/1024/1024) AS max_mb,
       autoextensible
FROM dba_data_files
WHERE tablespace_name IN (SELECT tablespace_name FROM dba_tablespaces WHERE contents = 'UNDO');

Then see how the undo space is used:

SELECT tablespace_name, status, ROUND(SUM(bytes)/1024/1024) AS mb
FROM dba_undo_extents
GROUP BY tablespace_name, status
ORDER BY tablespace_name, status;

SELECT tablespace_name, retention FROM dba_tablespaces WHERE contents = 'UNDO';
What you see Cause Go to
Mostly ACTIVE One or more large, uncommitted transactions Step 2, then step 3
Mostly UNEXPIRED, retention GUARANTEE Retention guarantee stops Oracle reusing undo Step 4
Mostly UNEXPIRED, files at max_mb Undo is too small for the retention target and workload Step 3
Files autoextensible but not growing The filesystem or ASM disk group is full Free OS or ASM space, or add a file elsewhere

2. Find the transaction using the undo

SELECT s.inst_id, s.sid, s.serial#, s.username, s.program, s.module,
       s.sql_id, t.start_time, t.used_ublk, t.used_urec,
       ROUND(t.used_ublk * p.value / 1024 / 1024) AS undo_mb
FROM gv$transaction t
JOIN gv$session s   ON s.taddr = t.addr AND s.inst_id = t.inst_id
JOIN gv$parameter p ON p.name = 'db_block_size' AND p.inst_id = t.inst_id
ORDER BY t.used_ublk DESC
FETCH FIRST 10 ROWS ONLY;

used_ublk is the number of undo blocks the transaction holds. Get its statement with SELECT sql_text FROM gv$sql WHERE sql_id = '&sql_id';. Then contact the job owner. Often a batch delete or update without intermediate commits, or a session that started a transaction and went idle.

3. Add undo space (first move)

Adding space is the fastest way to bring back service and loses no work. Add a datafile:

-- with Oracle Managed Files (db_create_file_dest set) or ASM
ALTER TABLESPACE UNDOTBS1 ADD DATAFILE SIZE 8G AUTOEXTEND ON NEXT 1G MAXSIZE UNLIMITED;

-- with explicit file names
ALTER TABLESPACE UNDOTBS1 ADD DATAFILE '/u02/oradata/PROD/undotbs1_02.dbf'
  SIZE 8G AUTOEXTEND ON NEXT 1G MAXSIZE UNLIMITED;

Or grow an existing file if it is below its limit:

ALTER DATABASE DATAFILE '/u02/oradata/PROD/undotbs01.dbf' RESIZE 30G;

For smallfile tablespaces, MAXSIZE UNLIMITED still means the per-file limit (about 32 GB with an 8 KB block size). Check free space in the filesystem or disk group (SELECT name, free_mb FROM v$asm_diskgroup;) before you add a file.

On Amazon RDS for Oracle you cannot use file paths. Use OMF syntax (ADD DATAFILE SIZE ...) or resize the tablespace, and check allocated storage in the console first.

Tip

If a large batch job is close to finishing, adding space and letting it commit is usually far faster than killing it. A killed transaction must roll back, and rollback often takes as long as the work it is undoing.

4. Remove a retention guarantee

If the tablespace has RETENTION GUARANTEE, Oracle fails DML instead of reusing unexpired undo. During an outage, turn the guarantee off:

ALTER TABLESPACE UNDOTBS1 RETENTION NOGUARANTEE;

Long queries and flashback operations may then hit ORA-01555, which is usually better than failing all writes. Find out why the guarantee was set (Flashback Query requirements, GoldenGate, a past ORA-01555 problem) before you turn it on again.

Check whether the tuned retention is pushing undo use up:

SELECT begin_time, end_time, undoblks, maxquerylen, tuned_undoretention
FROM v$undostat
WHERE begin_time > SYSDATE - 1/24
ORDER BY begin_time;

5. Kill the session only if you must

Kill the session when space cannot be added quickly or the transaction is runaway (a bug, a missing WHERE clause, an idle session holding a transaction):

ALTER SYSTEM KILL SESSION '123,45678,@2' IMMEDIATE;  -- sid,serial#,@inst_id

Caution

Killing the session does not free undo right away. The transaction rolls back first and keeps its undo until rollback ends, which can take hours for a big transaction. Do not restart the instance to "speed it up". After a restart, SMON still has to finish the rollback, and the database may run slowly while it does.

Watch the rollback progress. used_ublk goes down while the session rolls back:

SELECT s.sid, t.used_ublk, t.used_urec
FROM v$transaction t JOIN v$session s ON s.taddr = t.addr
WHERE s.sid = 123;

-- after the session is gone, SMON recovery:
SELECT state, undoblocksdone, undoblockstotal
FROM v$fast_start_transactions;

6. Switch to a new undo tablespace (if the current one cannot grow)

CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE SIZE 20G AUTOEXTEND ON NEXT 1G MAXSIZE UNLIMITED;
ALTER SYSTEM SET undo_tablespace = 'UNDOTBS2' SCOPE = BOTH;   -- RAC: add SID = 'PROD1'

New transactions use the new tablespace right away. Undo segments in the old one show PENDING OFFLINE in v$rollstat until their active transactions finish. Drop it only after that, and only once nothing needs its unexpired undo.

7. Verify recovery

  • Application DML succeeds and no new ORA-30036 errors appear in the alert log (adrci> show alert -p "message_text like '%ORA-30036%'").
  • dba_undo_extents shows ACTIVE space falling after the big transaction commits or rolls back.
  • No sessions are left blocked: SELECT sid, blocking_session, event FROM v$session WHERE blocking_session IS NOT NULL;

Prevent it next time

  • Ask batch owners to commit in chunks (for example every 10,000 to 100,000 rows) instead of in one transaction for a whole table.
  • Use autoextend on undo files with a set limit, and alert at 80% of the limit, not of the current file size.
  • Alert on any transaction older than your batch window or using more than a set number of undo blocks, using the query in step 2.
  • Kill idle sessions that hold open transactions with a resource manager MAX_IDLE_BLOCKER_TIME directive or a profile IDLE_TIME.
  • For long-query undo errors, see ORA-01555 snapshot too old. For data tablespaces, see the tablespace full runbook.