UNDO_RETENTION - Prevent ORA-01555 Snapshot Too Old
UNDO_RETENTION
Section titled “UNDO_RETENTION”Overview
Section titled “Overview”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
Configuration
Section titled “Configuration”Viewing Current Value
Section titled “Viewing Current Value”-- Current in-memory valueSELECT name, value, description, isdefaultFROM v$parameterWHERE name = 'undo_retention';
-- SPFILE value (survives restarts)SELECT name, valueFROM v$spparameterWHERE name = 'undo_retention';
-- Check if RETENTION GUARANTEE is active on the undo tablespaceSELECT tablespace_name, retentionFROM dba_tablespacesWHERE contents = 'UNDO';-- RETENTION column: NOGUARANTEE (default) or GUARANTEESetting the Parameter
Section titled “Setting the Parameter”-- 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 queriesALTER SYSTEM SET undo_retention = 14400 SCOPE = BOTH;
-- Verify the changeSELECT name, value FROM v$parameter WHERE name = 'undo_retention';Enabling Retention Guarantee
Section titled “Enabling Retention Guarantee”-- 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 modeSELECT tablespace_name, retentionFROM dba_tablespacesWHERE contents = 'UNDO';Tuning Guidance
Section titled “Tuning Guidance”Recommended Values
Section titled “Recommended Values”| Environment | Recommended Value | Rationale |
|---|---|---|
| OLTP, short transactions | 900 – 1800 s | Default sufficient; queries are fast |
| Mixed OLTP + reporting | 3600 – 7200 s | Accommodate ad-hoc reports (up to 2 hours) |
| Data Warehouse / batch | 14400 – 28800 s | Long ETL and analytical queries |
| Flashback Query enabled | Match flashback window | Must cover the desired flashback interval |
| Active Data Guard reads | Match longest standby query | Undo must survive replication lag + query time |
How to Size Using V$UNDOSTAT
Section titled “How to Size Using V$UNDOSTAT”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 daysSELECT 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_retentionFROM v$undostatWHERE begin_time >= sysdate - 7;
-- Detailed view: query length by day to spot batch windowsSELECT 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_errorsFROM v$undostatWHERE begin_time >= sysdate - 7GROUP 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 sizeSELECT 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_gbFROM 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_blkWHERE us.begin_time >= sysdate - 1GROUP BY p_ret.value, p_blk.value;Monitoring
Section titled “Monitoring”-- Check for ORA-01555 occurrences and unexpired undo pressureSELECT begin_time, end_time, undoblks, txncount, maxquerylen, maxconcurrency, ssolderrcnt AS ora_01555_count, nospaceerrcnt AS no_space_count, activeblks, unexpiredblks, expiredblksFROM v$undostatORDER BY begin_time DESCFETCH FIRST 48 ROWS ONLY;
-- Current undo extent status breakdownSELECT status, COUNT(*) AS extents, ROUND(SUM(bytes)/1024/1024, 1) AS total_mbFROM dba_undo_extentsGROUP BY statusORDER BY status;
-- Alert if ORA-01555 errors have occurred in the last hourSELECT SUM(ssolderrcnt) AS recent_01555_errorsFROM v$undostatWHERE begin_time >= sysdate - 1/24;Common Issues
Section titled “Common Issues”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 GUARANTEEALTER TABLESPACE undotbs1 RETENTION GUARANTEE;
-- Step 3: If GUARANTEE causes ORA-30036 (space full), add a datafileALTER 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 goSELECT 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 recoveredRelated Parameters
Section titled “Related Parameters”UNDO_TABLESPACE— Specifies which UNDO tablespace is used. Must be sized to support the retention target.UNDO_MANAGEMENT— Must beAUTOforUNDO_RETENTIONto apply.DB_FLASHBACK_RETENTION_TARGET— Controls how long Flashback Database logs are kept in the FRA; works alongsideUNDO_RETENTIONfor point-in-time recovery.
Related Errors
Section titled “Related Errors”- 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 GUARANTEEwith an undersized undo tablespace.
Version Notes
Section titled “Version Notes”| Version | Notes |
|---|---|
| Oracle 9i | Parameter introduced with Automatic Undo Management. |
| Oracle 10g | RETENTION GUARANTEE option added to tablespace DDL. Oracle also introduced auto-tuning of undo retention when AUTOEXTEND is enabled on the undo tablespace. |
| Oracle 11g | When 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.2 | Per-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. |