Skip to content

UNDO_RETENTION - Prevent ORA-01555 Snapshot Too Old

UNDO_RETENTION specifies the minimum number of seconds that Oracle should attempt to retain committed undo data before overwriting it. This retained undo is what Oracle uses to satisfy read-consistent queries: when a long-running SELECT needs to read a block as it looked at query-start, Oracle reconstructs the old version from undo data. If that undo has already been overwritten, the query fails with ORA-01555: snapshot too old.

The parameter is a target, not a guarantee. By default, Oracle may still overwrite unexpired undo if the tablespace has no free space. To make retention a hard guarantee, enable RETENTION GUARANTEE on the undo tablespace (Oracle 10g+). The setting must be large enough to cover the longest expected query execution time in your environment.

Parameter Type: Dynamic (ALTER SYSTEM) Default Value: 900 (15 minutes) Valid Range: 0 to 2^31 − 1 seconds (no practical upper limit, but tablespace must be sized accordingly) Available Since: Oracle 9i Modifiable: Yes — ALTER SYSTEM (effective immediately, no restart required) PDB Modifiable: Yes — settable at PDB level in Oracle 12.2+ with local undo


-- Current in-memory value
SELECT name,
value,
description,
isdefault
FROM v$parameter
WHERE name = 'undo_retention';
-- SPFILE value (survives restarts)
SELECT name, value
FROM v$spparameter
WHERE name = 'undo_retention';
-- Check if RETENTION GUARANTEE is active on the undo tablespace
SELECT tablespace_name,
retention
FROM dba_tablespaces
WHERE contents = 'UNDO';
-- RETENTION column: NOGUARANTEE (default) or GUARANTEE
-- Set undo retention to 1 hour (3600 seconds)
ALTER SYSTEM SET undo_retention = 3600 SCOPE = BOTH;
-- Set undo retention to 4 hours for a reporting environment with long queries
ALTER SYSTEM SET undo_retention = 14400 SCOPE = BOTH;
-- Verify the change
SELECT name, value FROM v$parameter WHERE name = 'undo_retention';
-- Force Oracle to never overwrite unexpired undo (requires adequately sized tablespace)
ALTER TABLESPACE undotbs1 RETENTION GUARANTEE;
-- To revert to the default (allow overwrite when space is tight)
ALTER TABLESPACE undotbs1 RETENTION NOGUARANTEE;
-- Confirm the retention mode
SELECT tablespace_name, retention
FROM dba_tablespaces
WHERE contents = 'UNDO';

EnvironmentRecommended ValueRationale
OLTP, short transactions900 – 1800 sDefault sufficient; queries are fast
Mixed OLTP + reporting3600 – 7200 sAccommodate ad-hoc reports (up to 2 hours)
Data Warehouse / batch14400 – 28800 sLong ETL and analytical queries
Flashback Query enabledMatch flashback windowMust cover the desired flashback interval
Active Data Guard readsMatch longest standby queryUndo must survive replication lag + query time

V$UNDOSTAT captures a 10-minute statistical sample. The MAXQUERYLEN column records the longest running query in each interval — that value is the minimum safe UNDO_RETENTION.

-- Find the maximum query length over the past 7 days
SELECT MAX(maxquerylen) AS max_query_seconds,
MAX(maxquerylen) / 60 AS max_query_minutes,
MAX(maxquerylen) / 3600 AS max_query_hours,
ROUND(MAX(maxquerylen) * 1.25) AS recommended_retention
FROM v$undostat
WHERE begin_time >= sysdate - 7;
-- Detailed view: query length by day to spot batch windows
SELECT trunc(begin_time) AS day,
MAX(maxquerylen) AS max_query_secs,
SUM(undoblks) AS total_undo_blocks,
SUM(txncount) AS total_txns,
SUM(ssolderrcnt) AS ora_01555_errors
FROM v$undostat
WHERE begin_time >= sysdate - 7
GROUP BY trunc(begin_time)
ORDER BY day DESC;

Add a 25% buffer to the maximum query length as the recommended retention value. If ORA-01555 errors appear in the SSOLDERRCNT column, retention is too low or the undo tablespace is too small for the current retention target.

Sizing the Undo Tablespace for a Given Retention

Section titled “Sizing the Undo Tablespace for a Given Retention”

Once you know the target retention, calculate the required tablespace size:

-- Required undo size = UNDO_RETENTION * undo blocks per second * block size
SELECT p_ret.value AS retention_secs,
p_blk.value AS block_size_bytes,
ROUND(AVG(us.undoblks / 600)) AS avg_undo_blks_per_sec,
ROUND(
p_ret.value
* AVG(us.undoblks / 600)
* p_blk.value
/ (1024*1024*1024),
2
) AS required_gb
FROM v$undostat us,
(SELECT value FROM v$parameter WHERE name = 'undo_retention') p_ret,
(SELECT value FROM v$parameter WHERE name = 'db_block_size') p_blk
WHERE us.begin_time >= sysdate - 1
GROUP BY p_ret.value, p_blk.value;
-- Check for ORA-01555 occurrences and unexpired undo pressure
SELECT begin_time,
end_time,
undoblks,
txncount,
maxquerylen,
maxconcurrency,
ssolderrcnt AS ora_01555_count,
nospaceerrcnt AS no_space_count,
activeblks,
unexpiredblks,
expiredblks
FROM v$undostat
ORDER BY begin_time DESC
FETCH FIRST 48 ROWS ONLY;
-- Current undo extent status breakdown
SELECT status,
COUNT(*) AS extents,
ROUND(SUM(bytes)/1024/1024, 1) AS total_mb
FROM dba_undo_extents
GROUP BY status
ORDER BY status;
-- Alert if ORA-01555 errors have occurred in the last hour
SELECT SUM(ssolderrcnt) AS recent_01555_errors
FROM v$undostat
WHERE begin_time >= sysdate - 1/24;

Issue 1: ORA-01555 despite a large UNDO_RETENTION value

Section titled “Issue 1: ORA-01555 despite a large UNDO_RETENTION value”

Symptom: Queries fail with ORA-01555 even though UNDO_RETENTION is set to a large value.

Cause: UNDO_RETENTION is a best-effort target. When the undo tablespace runs out of free space, Oracle overwrites unexpired undo to make room for active transactions — ignoring the retention target. This is the default RETENTION NOGUARANTEE behaviour.

Resolution:

-- Step 1: Confirm that undo is being overwritten (nospaceerrcnt will be > 0)
SELECT SUM(nospaceerrcnt) AS space_pressure FROM v$undostat WHERE begin_time >= sysdate - 1;
-- Step 2: Either add space or enable GUARANTEE
ALTER TABLESPACE undotbs1 RETENTION GUARANTEE;
-- Step 3: If GUARANTEE causes ORA-30036 (space full), add a datafile
ALTER TABLESPACE undotbs1
ADD DATAFILE '/u01/oradata/PROD/undotbs01b.dbf'
SIZE 4G AUTOEXTEND ON NEXT 512M MAXSIZE 20G;

Issue 2: Setting UNDO_RETENTION too high causes the tablespace to fill

Section titled “Issue 2: Setting UNDO_RETENTION too high causes the tablespace to fill”

Symptom: After increasing UNDO_RETENTION, the undo tablespace grows quickly and DML begins to fail with ORA-30036.

Cause: A higher retention value means Oracle retains more unexpired undo blocks. If the tablespace is not sized to hold that volume, it exhausts available space.

Resolution: Calculate the required tablespace size using the formula above before raising retention. Either pre-allocate sufficient space or keep RETENTION NOGUARANTEE and accept that retention is best-effort.

Issue 3: Flashback Query fails with ORA-01555

Section titled “Issue 3: Flashback Query fails with ORA-01555”

Symptom: SELECT ... AS OF TIMESTAMP or Flashback Table operations fail.

Cause: The Flashback query requires undo data older than the current UNDO_RETENTION interval.

Resolution:

-- Determine how far back the Flashback query needs to go
SELECT systimestamp - INTERVAL '2' HOUR FROM dual; -- example: 2-hour flashback
-- Set retention to cover the flashback window (e.g., 3 hours = 10800 seconds)
ALTER SYSTEM SET undo_retention = 10800 SCOPE = BOTH;
-- Note: undo_retention only helps going forward; historical undo already purged cannot be recovered

  • UNDO_TABLESPACE — Specifies which UNDO tablespace is used. Must be sized to support the retention target.
  • UNDO_MANAGEMENT — Must be AUTO for UNDO_RETENTION to apply.
  • DB_FLASHBACK_RETENTION_TARGET — Controls how long Flashback Database logs are kept in the FRA; works alongside UNDO_RETENTION for point-in-time recovery.

  • ORA-01555 — Snapshot too old; undo expired before the query completed. The primary error this parameter prevents.
  • ORA-30036 — Unable to extend undo segment; typically caused by RETENTION GUARANTEE with an undersized undo tablespace.

VersionNotes
Oracle 9iParameter introduced with Automatic Undo Management.
Oracle 10gRETENTION GUARANTEE option added to tablespace DDL. Oracle also introduced auto-tuning of undo retention when AUTOEXTEND is enabled on the undo tablespace.
Oracle 11gWhen the undo tablespace has AUTOEXTEND ON, Oracle dynamically tunes retention upward (above the UNDO_RETENTION floor) to avoid ORA-01555; the parameter becomes the minimum.
Oracle 12.2Per-PDB undo retention via local undo mode; each PDB can tune independently.
Oracle 19c+No changes to the parameter itself; local undo mode recommended for all new CDBs.