managing rollback segments
DESCRIPTION
Managing Rollback Segments. Objectives. Planning the number and size of rollback segments Creating rollback segments using appropriate storage settings Maintaining rollback segments Obtaining rollback segment information from the data dictionary Troubleshooting rollback segment problems. - PowerPoint PPT PresentationTRANSCRIPT
1010
Managing Rollback Segments Managing Rollback Segments
10-10-22
ObjectivesObjectives
• Planning the number and size of rollback segments
• Creating rollback segments using appropriate storage settings
• Maintaining rollback segments• Obtaining rollback segment information
from the data dictionary• Troubleshooting rollback segment
problems
• Planning the number and size of rollback segments
• Creating rollback segments using appropriate storage settings
• Maintaining rollback segments• Obtaining rollback segment information
from the data dictionary• Troubleshooting rollback segment
problems
10-10-33
Rollback Segment (Introduction)
Rollback Segment (Introduction)
•Used for delete and update operations only
•Used to ‘undo’ a transaction
•Used to save the old value when a process
changes data.
•Stores location and value of data before
modification
•A transaction can use only one rollback segment
10-10-44
Rollback Segment Rollback Segment
Update Update transactiontransaction
Old Old imageimage
New New imageimage
Rollback Rollback segmentsegment
TableTable
10-10-55
Rollback Segment (Steps) Rollback Segment (Steps)
•Data block brought into DB buffer
•Rollback segment brought into DB buffer
•Old data written to the rollback segment
•Update made to data block
10-10-66
Rollback Segments: PurposeRollback Segments: Purpose
Transaction Transaction rollbackrollback
Transaction Transaction recovery recovery
(when (when instance instance
fails)fails)
Rollback Rollback segmentsegment
Read Read consistencyconsistency
10-10-77
Read-ConsistencyRead-Consistency
Image at statement Image at statement commencementcommencement
New imageNew image
TableTableSELECT * SELECT * FROM tableFROM table
10-10-88
Read-ConsistencyRead-Consistency
•When Oracle begins execution of a SELECT statement, it determines the current SCN
•Ensures that changes not committed before the SCN are not processed by the statement
•In the case of a long running transaction, Oracle constructs a read-consistent image of the block by retrieving the before-image and applying changes to it in memory
10-10-99
Read-ConsistencyRead-Consistency
•Read consistency is always provided for a SQL statement
•Request read consistency for a transaction:
SET TRANSACTION READ ONLY;
Or
SET TRANSACTION SERIALIZABLE;
10-10-1010
Types of Rollback SegmentsTypes of Rollback Segments
• SYSTEM: used for objects in the SYSTEM tablespace; created in the SYSTEM ts
• Non-SYSTEM: objects in other tablespaces
– At least one needed
– Private: acquire by a single instance
– Public: acquired by any instance (used with parallel server)
• SYSTEM: used for objects in the SYSTEM tablespace; created in the SYSTEM ts
• Non-SYSTEM: objects in other tablespaces
– At least one needed
– Private: acquire by a single instance
– Public: acquired by any instance (used with parallel server)
10-10-1111
Transactions and Rollback Segments
Transactions and Rollback Segments
• Transactions need rollback segments to be assigned:– SET TRANSACTION Use Rollback Segment rbs1
• If no request is made, Oracle uses segment with fewest transactions
• Transactions use extents in a circular fashion
• More than one transaction can write to the same extent of a segment; however each block contains information from only one transaction
• Transactions need rollback segments to be assigned:– SET TRANSACTION Use Rollback Segment rbs1
• If no request is made, Oracle uses segment with fewest transactions
• Transactions use extents in a circular fashion
• More than one transaction can write to the same extent of a segment; however each block contains information from only one transaction
10-10-1212
Transactions and Rollback Segments Example
Transactions and Rollback Segments Example
Transaction 1Transaction 1
Active extentActive extent Inactive extentInactive extent
4 3
1 2
Transaction 2Transaction 2
Begin at extent 3
When full, move to extent 4 (called a wrap)
When that fills, can use the 1st extent if it is free or inactive
10-10-1313
Growth of Rollback SegmentsGrowth of Rollback Segments
Active extentActive extent
Inactive extentInactive extent
1 2
4 3
1 2
3
4
5
New extentNew extent
Cannot skip an extent; if next extent is being used, an additional extent is allocated . This is called an extend. Can grow this way until it reaches the maximum number of extents specified in the MAXEXTENTS parameter
10-10-1414
Shrinkage of Rollback SegmentsShrinkage of Rollback Segments
Active extentActive extent
Inactive extentInactive extent
1 2
6 3
1
2
34
5
6
OptimalOptimal
10-10-1515
Shrinkage of Rollback SegmentsShrinkage of Rollback Segments
•Deallocation of extents is not done as soon as transactions end.
•Deallocation performed when head moves from one extent to next and:
•Current size of rollback segment > OPTIMAL
•There are contiguous inactive extents
10-10-1616
Creating Rollback SegmentsCreating Rollback Segments
CREATE ROLLBACK SEGMENT rbs01
TABLESPACE rbs
STORAGE (
INITIAL 100K NEXT 100K OPTIMAL 4M
MINEXTENTS 20 MAXEXTENTS 100);
CREATE ROLLBACK SEGMENT rbs01
TABLESPACE rbs
STORAGE (
INITIAL 100K NEXT 100K OPTIMAL 4M
MINEXTENTS 20 MAXEXTENTS 100);
Example
MINEXTENTS: at least 2; PCTINCREASE not specified: always 0
Always use INITIAL = NEXT;
OPTIMAL specifies size in bytes that the rollback segment must shrink to, if possible
AVOID setting MAXEXTENTS to UNLIMITED: can cause unnecessary extension due to program error
10-10-1717
Planning Rollback Segments: Number
Planning Rollback Segments: Number
• OLTP
– Small, but many segments
– One RBS/4 transactions
• Batch
– Large, but few
• Always place rollback segments in a separate exclusive tablespace
• Always use INITIAL=NEXT
• PCTINCREASE cannot be specified (always 0)
• Set an OPTIMAL value
• OLTP
– Small, but many segments
– One RBS/4 transactions
• Batch
– Large, but few
• Always place rollback segments in a separate exclusive tablespace
• Always use INITIAL=NEXT
• PCTINCREASE cannot be specified (always 0)
• Set an OPTIMAL value
10-10-1818
Planning Rollback Segments: Number of Extents
Planning Rollback Segments: Number of Extents
0.000.000.000.00
0.100.100.100.10
0.200.200.200.20
0.300.300.300.30
0.400.400.400.40
0.500.500.500.50
0000 10101010 20202020 30303030 40404040
Number of extentsNumber of extentsNumber of extentsNumber of extents
ProbabilityProbabilityof extendingof extending
10-10-1919
Bringing Rollback Segments Online
Bringing Rollback Segments Online
• Use the following command to make a rollback segment available (when created, they are offline):
• Specify the following initialization parameter to ensure rollback segments are brought online at STARTUP:
• Use the following command to make a rollback segment available (when created, they are offline):
• Specify the following initialization parameter to ensure rollback segments are brought online at STARTUP:
ALTER ROLLBACK SEGMENT rbs01 ONLINE;ALTER ROLLBACK SEGMENT rbs01 ONLINE;
ROLLBACK_SEGMENTS=(rbs01, rbs02)ROLLBACK_SEGMENTS=(rbs01, rbs02)
10-10-2020
How Instances Acquire Rollback Segments when DB is opened
How Instances Acquire Rollback Segments when DB is opened
Bring allacquired
RBSs ONLINE
Acquire namedprivate
RBS
Are there enoughRBS ?
AcquirepublicRBS
Computerequirednumberof RBS
Yes
No
10-10-2121
Changing Rollback Segment Storage Settings
Changing Rollback Segment Storage Settings
ALTER ROLLBACK SEGMENT rbs01
STORAGE( MAXEXTENTS 200 );
ALTER ROLLBACK SEGMENT rbs01
STORAGE( MAXEXTENTS 200 );
Use ALTER ROLLBACK SEGMENTUse ALTER ROLLBACK SEGMENT
10-10-2222
Manually Deallocating Space from Rollback Segments
Manually Deallocating Space from Rollback Segments
ALTER ROLLBACK SEGMENT rbs01
SHRINK TO 4M;
ALTER ROLLBACK SEGMENT rbs01
SHRINK TO 4M;
If OPTIMAL is specified, Oracle will attempt to deallocate
Use ALTER ROLLBACK SEGMENT
(if extents are active, may not shrink to the requested size)
If OPTIMAL is specified, Oracle will attempt to deallocate
Use ALTER ROLLBACK SEGMENT
(if extents are active, may not shrink to the requested size)
10-10-2323
Taking Rollback Segment Offline
Taking Rollback Segment Offline
ALTER ROLLBACK SEGMENT rbs01
OFFLINE;
ALTER ROLLBACK SEGMENT rbs01
OFFLINE;
Take a rollback segment offline to makeit unavailable.Take a rollback segment offline to makeit unavailable.
10-10-2424
Dropping Rollback SegmentsDropping Rollback Segments
A rollback segment must be offline before it can be dropped.A rollback segment must be offline before it can be dropped.
DROP ROLLBACK SEGMENT rbs01;DROP ROLLBACK SEGMENT rbs01;
10-10-2525
Rollback Segments in the Database
Rollback Segments in the Database
DBA_ROLLBACK_SEGS
• Identification
– SEGMENT_ID
– SEGMENT_NAME
• Location, type, and status
– TABLESPACE_NAME
– OWNER (PUBLIC or SYS)
– STATUS (ONLINE or OFFLINE)
DBA_ROLLBACK_SEGS
• Identification
– SEGMENT_ID
– SEGMENT_NAME
• Location, type, and status
– TABLESPACE_NAME
– OWNER (PUBLIC or SYS)
– STATUS (ONLINE or OFFLINE)
10-10-2626
Rollback Segments in the Database
Rollback Segments in the Database
Select segment_name, tablespace_name,
owner, status
From dba_rollback_segs;
Select segment_name, tablespace_name,
owner, status
From dba_rollback_segs;
10-10-2727
Rollback Segment StatisticsRollback Segment Statistics
V$ROLLNAMEUSNNAME
V$ROLLNAMEUSNNAME
V$ROLLSTAT USN
EXTENTSRSSIZE XACTS OPTSIZE HWMSIZE AVEACTIVESTATUS CUREXT CURBLK
V$ROLLSTAT USN
EXTENTSRSSIZE XACTS OPTSIZE HWMSIZE AVEACTIVESTATUS CUREXT CURBLK
10-10-2828
Rollback Segment: Current Activity Rollback Segment: Current Activity
V$SESSIONSADDRUSERNAMESIDSERIAL#
V$SESSIONSADDRUSERNAMESIDSERIAL#
V$TRANSACTION SES_ADDRXIDUSN UBAFIL UBABLK UBASQN UBAREC STATUS USED_UBLK USED_UREC
V$TRANSACTION SES_ADDRXIDUSN UBAFIL UBABLK UBASQN UBAREC STATUS USED_UBLK USED_UREC
10-10-2929
Rollback Segment ProblemsRollback Segment Problems
• Insufficient space for transactions
• Read-consistency error
• Blocking transaction
• Error in taking tablespace offline
• Insufficient space for transactions
• Read-consistency error
• Blocking transaction
• Error in taking tablespace offline
10-10-3030
Insufficient Space for TransactionsInsufficient Space for Transactions
• No space in tablespace to extend– Extend data files– Allow automatic extension of data
files– Add data files
• MAXEXTENTS reached for segment– Increase MAXEXTENTS– Recreate segments with larger extent
sizes
• No space in tablespace to extend– Extend data files– Allow automatic extension of data
files– Add data files
• MAXEXTENTS reached for segment– Increase MAXEXTENTS– Recreate segments with larger extent
sizes
10-10-3131
Read-Consistency Error(snapshot too old)
Read-Consistency Error(snapshot too old)
Image at statement Image at statement commencementcommencement
New imageNew image
TableTableSELECT * SELECT * FROM tableFROM table
Reused Reused blockblock
A long running Trans
Another transaction commits
Rollback segment is reused
Soln: Higher MINEXTENTS; larger extents; higher OPTIMAL value
10-10-3232
Blocking Session Blocking Session
Extent 3
Existing extentExisting extent
New extentNew extent
4 1
3 2
1 2
3
4
5
Blocking session
A long running trans keeps an extent occupied and blocks other trans from writing to it; segment keeps extending
Soln: DBA intervention
10-10-3333
Error in Taking a Tablespace Offline Error in Taking a
Tablespace Offline
Cannot take tablespace containing active RBS offline
• Check rollback segments in the tablespace
• Find active transactions using these rollback segments
• Find session ID and serial number
• Terminate the session, if necessary
Cannot take tablespace containing active RBS offline
• Check rollback segments in the tablespace
• Find active transactions using these rollback segments
• Find session ID and serial number
• Terminate the session, if necessary
10-10-3434
Summary Summary
• Creating adequate rollback segments
• Troubleshooting rollback segment problems
• Creating adequate rollback segments
• Troubleshooting rollback segment problems