Best Practices to avoid ORA-01555
Prepared by:Deiby GómezOracle Certified Master 11gPythian Oracle Consultant
© 2014 Pythian Confidential2
© 2014 Pythian Confidential3
WHAT IS UNDO DATA• Rollback an active transaction• Recover a terminated transaction• Provide read consistency• Recovery from logical corruptions• Perform some logical flashback operations
© 2014 Pythian Confidential4
FLASHBACK AND UNDO
© 2014 Pythian Confidential5
UPDATE PROCESS
Update…
Undo
Redo Log Buffer
Redo Record• Undo Change Vector • Data Change Vector
Table’s Data Blocks
© 2014 Pythian Confidential6
CONSISTENT READ
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Target SCN Current SCN
Trans#1 – C - - SCN
1 ‘A’ ‘A’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential7
CONSISTENT READ
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#4 SCN > SCN we are looking for?
© 2014 Pythian Confidential8
CONSISTENT READ
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘C’ ‘C’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential9
CONSISTENT READ
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
1 ‘C’ ‘C’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential10
CONSISTENT READ
Trans#3 – C - - SCN
1 ‘C ‘C’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#3 SCN > SCN we are looking for? >
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential11
CONSISTENT READExtent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
1 ‘B ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
© 2014 Pythian Confidential12
CONSISTENT READ
Trans#2 – C - - SCN
1 ‘B’ ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential13
CONSISTENT READ
Trans#2 – C - - SCN
1 ‘B’ ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#2 SCN > SCN we are looking for? >
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential14
CONSISTENT READExtent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#2 – C - - SCN
1 ‘A’ ‘A’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
© 2014 Pythian Confidential15
CONSISTENT READ
Trans#1 – C - - SCN
1 ‘A’ ‘A’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential16
CONSISTENT READ
Trans#1 – C - - SCN
1 ‘A’ ‘A’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#1 SCN > SCN we are looking for? <
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
1 ‘A’ ‘A’
© 2014 Pythian Confidential17
SNAPSHOT TOO OLD
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Target SCN Current SCN
Trans#1 – C - - SCN
1 ‘A’ ‘A’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential18
SNAPSHOT TOO OLD
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#4 SCN > SCN we are looking for?
© 2014 Pythian Confidential19
SNAPSHOT TOO OLD
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘C’ ‘C’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential20
SNAPSHOT TOO OLD
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
1 ‘C’ ‘C’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential21
SNAPSHOT TOO OLD
Trans#3 – C - - SCN
1 ‘C ‘C’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#3 SCN > SCN we are looking for? >
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential22
SNAPSHOT TOO OLDExtent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
Trans#3 – C - - SCN
1 ‘B ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
© 2014 Pythian Confidential23
SNAPSHOT TOO OLD
Trans#2 – C - - SCN
1 ‘B’ ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
© 2014 Pythian Confidential24
SNAPSHOT TOO OLD
Trans#2 – C - - SCN
1 ‘B’ ‘B’
2 ‘D’ ‘D’
3 ‘D’ ‘D’
4 ‘D’ ‘D’
Extent
Segment
Trans#2 SCN > SCN we are looking for? >
Trans#3 – C - - SCN
Trans#4 – A - - SCN
1 ‘D’ ‘D’
2 ‘A’ ‘A’
3 ‘A’ ‘A’
4 ‘A’ ‘A’
ORA-0600ORA-1555
© 2014 Pythian Confidential25
UNDO MANAGEMENT
There are now two modes of rollback segments management and usage:
• AUTOMATIC• MANUAL
When undo_management=AUTO:• RDBMS creates undo segments when you create a new undo
tablespace• RDBMS alters undo segments ONLINE/OFFLINE when you choose a
specific undo tablespace• RDBMS drops undo segments when you drop an undo tablespace• DBA can not manage the undo segments
• You can only CREATE/DROP UNDO Tablespaces
© 2014 Pythian Confidential26
UNDO MANAGEMENT
Undo tablespace uses the following schema for extents:
• Until segment size is 1M, 64K extents are allocated (16 such)• Until segment size reaches 64M, 1M extents are allocated (63 such)• Until segment size reaches 1G, 8M extents are allocated (120 such)• Beyond 1G, 64M extents are allocated.
Automatic Undo Management in RAC
• All instances within RAC must run in the same undo mode.• Same value of undo_management in all instance.
• Each instance requires its own undo tablespace.• Set UNDO_TABLESPACE for the right undo tablespace for
each instance• If UNDO_TABLESPACE parameter is not set, each instance uses
the first available undo tablespace.
© 2014 Pythian Confidential27
Oracle strongly recommends leaving the database in automatic undo management mode.
if manual undo management: Note 69464.1 Rollback Segment Configuration & Tips
© 2014 Pythian Confidential28
UNDO_RETENTION PARAMETER
Undo retention period is the minimum amount of time that Oracle Database attempts to retain old undo information before overwriting it.
• ACTIVE (Uncommitted transaction)• UNEXPIRED ( current time - transaction’s commit time<=retention period)
• EXPIRED ( current time - transaction’s commit time>retention period)
The undo data is not required after a transaction is committed Undo data is used for consistent reads Undo data is used for some Flashback features
DBA_UNDO_EXTENTS--->STATUS
© 2014 Pythian Confidential29
UNDO TABLESPACE AUTOEXTENDABOUT RETENTION TIME
• Autoextend=YES• Undo_retention is ignored. • RDBMS tunes the retention time based on statistics gathered.
• Autoextend=NO• RDBMS tunes the retention to the highest possible value • The value could be significantly greater than the duration of the longest-
running active query.• If the undo tablespace is so big, then the undo retention time will so
large.
Note: It is NOT recommended to have a mix of AUTOEXTENSIBLE and NON-AUTOEXTENSIBLE files within an UNDO tablespace as this can cause tuned undo retention to miscalculate
© 2014 Pythian Confidential30
UNDO TABLESPACE AUTOEXTENDABOUT RETENTION TIME
In some cases with undo tablespace is non-autoextensible, especially with large undo tablespace, This will make it to be calculated so large.
To fix this behaviour, Set the following instance parameter:
Set the parameter: _smu_debug_mode=33554432
With this setting:
• Tuned undo retention time is not calculated based on a percentage of the fixed size undo tablespace.
• Tuned undo retention time is set to the maximum of (MAXQUERYLEN secs + 300) and UNDO_RETENTION.
© 2014 Pythian Confidential31
UNDO TABLESPACE AUTOEXTENDABOUT RETENTION TIME
How do I know what is the current tuned retention time ?
TUNED_UNDORETENTION column of the V$UNDOSTAT view. • The statistics are gathered each 10 minutes. (only 4 last days.)• Beyond 4 days, the data is available in the DBA_HIST_UNDOSTAT view.• TUNED_UNDORETENTION is given in seconds.
select to_char(begin_time, 'DD-MON-RR HH24:MI') begin_time,to_char(end_time, 'DD-MON-RR HH24:MI') end_time, tuned_undoretentionfrom v$undostat order by end_time;
BEGIN_TIME END_TIME TUNED_UNDORETENTION--------------- --------------- -------------------07-FEB-05 23:31 07-FEB-05 23:41 8670007-FEB-05 23:41 07-FEB-05 23:51 8670007-FEB-05 23:51 07-FEB-05 23:52 86700
© 2014 Pythian Confidential32
_UNDO_AUTOTUNE PARAMETER
If _undo_autotune=true (The default)• RDBMS will tune the retention time and it will ignore undo_retention
parameter. Oracle uses autoextensible properties and statistics of long running queries, etc.
• undo_retention parameter is set as the minimum value but this is not always true, DML’s has higher priority in the RDBMs and if one tracsaction needs more undo data even unexpired extents will be overwriten.
If _undo_autotune=false • RDBMS will not tune the retention time. undo_retention parameter
sets the retention time. This
© 2014 Pythian Confidential33
UNDO TABLESPACE AUTOEXTENDABOUT UNEXPIRED OVERWRITING
A New Extent is needed:
If autoextend=falseif a new extent can be created?
create new extent and use it. End.else if there is Expired extents to overwrite?
Overwrite Expired extentselse if there is Unexpired extents to overwrite?
Overwrite Unexpired Extentselse
Fail. Undo tablespace needs more space.else - - autoextend=true
....next slide.
© 2014 Pythian Confidential34
UNDO TABLESPACE AUTOEXTENDABOUT UNEXPIRED OVERWRITING
A New Extent is needed:
else - - autoextend=trueif a new extent can be created?
create new extent and use it. End.else if undo tablespace’s size = maxsize property?
if there is Expired extents to overwrite?Overwrite Expired extents
else if there is Unexpired extents to overwrite?Overwrite Unexpired Extents
elseFail. Undo tablespace needs more
space.else
Autoextend a datafile The real differenceCreate a new extent and use it.
© 2014 Pythian Confidential35
Oracle recommends to have autoextensible undo tablespace.
Health Check Alert: Consider using AUTOEXTEND for UNDO tablespaces (Doc ID 957424.1)
© 2014 Pythian Confidential36
RETENTION UNDO GUARANTEE
WARNING:Enabling retention guarantee can cause multiple DML operations to fail. Use with caution.
If retention guarantee is enabled• The specified minimum undo retention is guaranteed• The database never overwrites unexpired undo data even if it means
that transactions fail due to lack of space in the undo tablespace.• This option is disabled by default.
If retention guarantee is not enabled:The database can overwrite unexpired undo extents when space is low
Note: RDBMS never overwrites active undo extents.
© 2014 Pythian Confidential37
RETENTION UNDO GUARANTEE
If you have ( and you are really sure) enough undo space, you can use undo
retention guarantee but if you use it then I recommend you to use it with _undo_autotune=false and a well tuned undo_retention parameter value.
© 2014 Pythian Confidential38
LOBS: IN-ROW & OUT-OF-ROW
In-row• LOBs should be utilizing normal UNDO algorithms in the UNDO
tablespace.
Out-of-row• Use of PCTVERSION• Use of RETENTION (current method for use with AUM)
© 2014 Pythian Confidential39
HOW TO IDENTIFY IF IT IS LOB?
ORA01555:snapshot too old: rollback segment number 9 with name "_SYSSMU9$" too small
ORA01555:snapshot too old: rollback segment number 9 with name “" too small
Master Note for ORA1555 Errors (Doc ID 1307334.1)
© 2014 Pythian Confidential40
LOBS: PCTVERSION & RETENTION
Use of PCTVERSION (old method)• Specify the maximum percentage of overall LOB storage space
used for maintaining old versions of the LOB. • The default value is 10
o Older versions of the LOB data are not overwritten until they consume 10% of the overall LOB storage space.
o Frequent updates or deletes impacts tables with LOBs using pctversion
Use of RETENTION (current method for use with AUM)• Oracle Database uses the value of the UNDO_RETENTION to
determine the amount of committed undo data to retain in the database.
© 2014 Pythian Confidential41
LOBS: PCTVERSION & RETENTION
Use of PCTVERSION (old method)• Specify the maximum percentage of overall LOB storage space
used for maintaining old versions of the LOB. • The default value is 10
o Older versions of the LOB data are not overwritten until they consume 10% of the overall LOB storage space.
o Frequent updates or deletes impacts tables with LOBs using pctversion
Use of RETENTION (current method for use with AUM)• Oracle Database uses the value of the UNDO_RETENTION to
determine the amount of committed undo data to retain in the database.
© 2014 Pythian Confidential42
RecommendationCheck if your Tables with Lobs have so frequent modifications
© 2014 Pythian Confidential43
LOBS: UNDO_RETENTION NO UPDATED
SQL> show parameters undo_retention
NAME TYPE VALUE----------------------- ----------- ------------------------------undo_retention integer 60
SQL> create table LobWithRetention (col1 number, col2 blob) LOB ( col2 ) STORE AS ( retention);
Table created.
select table_name, segment_name, pctversion, retention from dba_lobs where owner='DGOMEZ' and retention is not null;
TABLE_NAME SEGMENT_NAME PCTVERSION RETENTION-------------------------- ------------------------- ---------- ----------LOBWITHRETENTION SYS_LOB0000087573C00002$$ 60
© 2014 Pythian Confidential44
SQL> alter system set undo_retention=120 scope=both;
System altered.
SQL> show parameters undo_retention
NAME TYPE VALUE---------------------- ----------- ------------------------------undo_retention integer 120SQL>
SQL> select table_name, segment_name, pctversion, retention from dba_lobs where owner='DGOMEZ' and retention is not null;
TABLE_NAME SEGMENT_NAME PCTVERSION RETENTION------------------------ --------------------------- ---------- ----------LOBWITHRETENTION SYS_LOB0000087573C00002$$ 60
LOBS: UNDO_RETENTION NO UPDATED
© 2014 Pythian Confidential45
LOBS: UNDO_RETENTION NO UPDATED
SQL> alter table LobWithRetention modifyLOB ( col2 ) ( pctversion 5);
Table altered.
SQL> alter table LobWithRetention modifyLOB ( col2 ) ( retention); Table altered.
SQL> select table_name, segment_name, pctversion, retention from dba_lobs where owner='DGOMEZ' and retention is not null;
TABLE_NAME SEGMENT_NAME PCTVERSION RETENTION------------------------ --------------------------- ---------- ----------LOBWITHRETENTION SYS_LOB0000087573C00002$$ 120
© 2014 Pythian Confidential46
LOBS: UNDO_RETENTION IGNORED
• if the LOB resides in a tablespace using MANUAL space management (MSSM) the Lob Retention parameter is ignored.
• Automatic Segment Space Managemetn (ASSM) should be used in order to honour the lob retention parameter.
select tablespace_name, extent_management, segment_space_managementfrom dba_tablespaceswhere tablespace_name in(select tablespace_name from dba_segmentswhere owner=’<owner>' and segment_name=’<segmentName>');
© 2014 Pythian Confidential47
SCRIPT - UNDO INFORMATIONScript - Check Current Undo Configuration and Advise Recommended Setup (Doc ID 1579035.1)
© 2014 Pythian Confidential48
THE UNDO ADVISOR PL/SQL INTERFACE
Output:Automatic Database Diagnostic Monitor in Enterprise ManagerDBA_ADVISOR_*
• DBA_ADVISOR_TASKS• DBA_ADVISOR_OBJECTS• DBA_ADVISOR_FINDINGS• DBA_ADVISOR_RECOMMENDATIONS• ETC.
© 2014 Pythian Confidential49
Questions?
Twitter: @hdeibyFacebook: /HDeibyEmail: [email protected]: www.oraclefromguatemala.com.gt
Top Related