Beruflich Dokumente
Kultur Dokumente
4. Extents in the ring are never skipped over and used out of order as the
head tries to advance.
5. If the head can't use the next extent, it allocates another extent and
inserts it into the ring.
From these principles it is evident that transaction time as well as
transaction size is important. For instance, a transaction that only modifies
one byte but waits a long period of time before ending could cause a rollback
segment to extend if the extent it occupied is needed again.
Size Considerations
------------------There are two issues that need to be considered when deciding if your segment
is large enough. First, you want to make sure that transactions will not
cause
the head to wrap around too fast and catch the tail. This causes the segment
to extend in size, as discussed above. Second, if you have long-running
queries that access data that changes frequently, you want to make sure that
the rollback segment doesn't wrap around and prevent the construction of a
read-consistent view. Read-consistency is discussed in more detail later in
the section on avoiding `ORA-1555 - snapshot too old' errors.
The size needed for a rollback segment depends directly on the transaction
activity of the database. The primary concern should be the activity during
normal processing of the database, not rare or semi-frequent large
transactions. These special cases should be dealt with separately.
The number of rollback segments needed to prevent contention between processes
can be determined with the use of the v$waitstat table. Waits are a definite
indication of contention. The following v$waitstat query will display number
of waits since instance startup:
SELECT CLASS, COUNT FROM V$WAITSTAT WHERE CLASS = '%undo%';
Any non-zero value in the count column indicates rollback segment header
contention.
To find out the size and number of rollback segments needed to handle normal
processing on the database you need to do some testing. A good test is to
start with small rollback segments and allow your application to force them to
extend.
Here are the steps to run such a test:
1. Create a rollback segment tablespace.
2. Select a number of rollback segments to test and create them in the
tablespace.
3. Create the rollback segments so that all extents are the same size.
Choose an extent size that you suspect will need between 10 to 30
extents when the segments grow to full size.
4. Each rollback segments should start with two extents before the test
is run. This is the minimum number of extents any rollback segment
can have.
6. Only the rollback segments that you are testing and the SYSTEM
rollback segment should be online. Run transactions and load typical
of the application.
7. Watch for rollback segment contention.
8. Watch for the maximum size a rollback extends to.
The maximum size any one of the rollback segments reaches during the test is
the size you want to use when configuring. This size we will call the
"minimum
coverage size". If you see contention, adjust the number of segments and
rerun
the test. Also, if the largest size requires fewer than 10 extents, or more
than 30, it is a good idea to lower or raise the extent size, respectively,
and
rerun the test. Otherwise, space may be getting wasted during the test and
this would throw the number off.
At the end of this test, you will have some good base estimates for the size
and number of rollback segments needed for normal processing. However,
handling large transactions has not been discussed yet. Calculating the
segment size needed for these types of transactions as well as how to meet the
requests for the calculated space will be addressed.
For sizing rollback segment extents, it is strongly recommended that each
extent be of the same size. In fact, for all strategies listed below it is
assumed that all rollback segments have extents of the same size and that the
size of the rollback tablespace is some multiple of the common extent size.
The
minimum number of extents for an individual segment should be around twenty
for
best performance.
Why size a rollback segment with a 'minimum' of twenty extents?
Rollback segments dynamically allocate space when required and deallocate
space
when no longer needed (if the OPTIMAL parameter is used). The fewer extents
that a rollback segment consists of, the larger the less granular these space
allocations and deallocations are. For example, consider a 200 megabyte
rollback segment which consists of only two 100-megabyte extents. If this
segment were to require additional space, it would allocate another 100M
extent. This immediately increases the size of the rollback segment by 50%
and
potentially acquires more space than is really needed. By contrast, if the
rollback segment consisted of twenty 10-megabyte extents, any additional space
required would be allocated in 10-megabyte pieces. When a rollback segment
consists of twenty or more extents, any single change in the number of extents
will not move the total size of the rollback segment by more than 5%,
resulting
-----------------------------------In the rollback segment storage clause, there is a parameter called OPTIMAL.
This specifies the `optimal' size of a rollback segment in bytes. When set,
Oracle will try to keep the segment at the specified size, rounded up to the
extent boundary. The RDBMS tries to have the fewest number of extents such
that the total size is greater than or equal to the size specified as OPTIMAL.
If additional space is needed beyond the optimal size, the rollback segment
will expand beyond optimal to accommodate the current transaction(s), but will
eventually deallocate extents to shrink back to this size.
The process of shrinking back to OPTIMAL is not instantaneous. When a
transaction that has expanded the segment beyond the set value has ended, the
rollback segment does not `snap' back to the optimal size. This could have
severe performance implications and cause considerable problems with
read-consistency. The process of deallocating extents is performed during
transactions after the one which caused the segment to extend.When the head
moves from one extent to the next during a transaction, the segment size is
checked. If the segment size is currently above the optimal, the RDBMS
determines if an extent should be deallocated. An extent will only be
deallocated if there are no active transactions in the next two extents (Why
the next two extents? If only the next extent is checked for availability,
Oracle might deallocate it then try to continue with the current transaction
only to find that the following extent is used. At that point, Oracle must
reallocate an extent.). If necessary, the RDBMS will deallocate multiple
extents in a single transaction (one each time the head crosses into a new
extent) until the segment has shrunk back to its optimal size. Since extents
are deallocated by the current transaction(s), the circular nature of rollback
segments guarantees that these are the oldest inactive extents (and the least
likely to be used for read consistency).
The OPTIMAL clause is a very handy tool, however, be aware of a couple of
points when using it.
Point one is that extent allocation and deallocation is expensive in regards
to
performance. This means that an OPTIMAL setting may decrease performance if
it
is too low. (Actually, it will always decrease performance. It may noticeably
decrease performance if set too low.) The best solution for performance is to
set all of your rollback segments to a size where every single transaction
will
always fit. In practical terms, this may well be impossible - if your largest
transaction is 2 gigabytes and you require ten rollback segments for
concurrency. The segments should have an optimal size large enough that 90%
or
better of transactions will fit without having to extend the segment. In
addition, the rollback tablespace should be large enough that when all
rollback
segments are at the optimal value, there is plenty of space for them to extend
when it becomes necessary. For example, if your segments are set with an
optimal value of 500 megs and you know that there is a particular transaction
that runs infrequently, but requires one gigabyte when it does run, your
rollback tablespace must have 500 megs free (absolute minimum) when all
segments in that tablespace are at optimal. Since you cannot normally count
on
all segments being at optimal or on that big transaction being the only one
using space in the rollback segment, prudence suggests having a bit more space
available than the absolute minimum.
Point two is that you are never guaranteed when a rollback segment will shrink
down to its optimal size. The rollback segment only shrinks when a
transaction
attempts to move into another extent and sees that the extent meets the
requirements for deallocation. If a rollback is a candidate for shrinks, but
no transactions are allocated to it, it will not shrink. The obvious
corollary
is that a segment must be online to shrink.
Bringing Rollback Segments Online and Offline
--------------------------------------------By default whenever a rollback segment is created it is offline and must be
acquired by the instance or brought online. The SQL command ALTER ROLLBACK
SEGMENT can be used to bring a rollback segment online or offline while the
instance is running. If a segment is taken offline and the specified rollback
segment does not have any active transactions, it is immediately taken
offline.
But if the segment contains active transactions then it is taken offline only
after all the active transaction are either committed or rolled back. No new
transactions will be written to a rollback segment that is waiting for other
transactions to complete so that it can be brought offline. To become
available again without shutting down the instance, a rollback segment that
has
been taken offline must be explicitly brought back online.
Rollback segments are also brought online during instance startup. There are
two basic ways that rollback segments can be brought online. The init.ora
file
can contain a parameter called rollback_segments. You can add this line to
the
init.ora and specify all rollback segments that are to be explicitly brought
online during instance startup. Note that if any of these rollback segments
do
not exist, an ORA-1534 error is returned and the instance does not complete
startup.
The segments must already exist before you can add them to the list
to be brought online.
Even if rollback segments are not explicitly brought online by being added to
the "rollback_segments" parameter, they may be brought online during startup.
Oracle will do this based on the values of two other parameters: transactions
and "transactions_per_rollback_segment". On startup, Oracle will divide
transactions by "transactions_per_rollback_segment" and round up. If the
resulting number is less than the number of rollback segments brought online
by
the "rollback_segments" parameter, nothing is done. However, if the resulting
number is greater and more rollback segments exist which are not currently
online, the segments will be brought online until the number is reached or
until there are no other offline segments. If neither parameter is set in the
init.ora, they will use default values.
tablespace. One is to reduce the number of segments so that all are large
enough to hold the largest transactions. This option may well introduce
contention and cause some degradation in performance.
It is a reasonable
choice if performance is not extremely critical. The second option is to
build
one or more large rollback segments and make sure that large transactions use
these segments. The SET TRANSACTION USE ROLLBACK SEGMENT command is necessary
to control the placement of these large transactions. This option is
difficult
to implement if large transactions are being run with adhoc queries and there
is no systematic control of large transactions. It is recommended in an
environment where the large transactions are issued from a controlled
environment (i.e. an application) that can set the transaction to the
appropriate rollback segment.
Infrequent Large Transactions
----------------------------For cases where large transactions are rare, you can use OPTIMAL feature to
set
up a flexible rollback segment scheme, one in which you are not concerned
about
which rollback segment the large transaction falls upon. The key is to leave
enough free space in the rollback tablespace that the largest transaction's
rollback information can fit entirely into it. To do this, create the
rollback
tablespace with the space needed for your calculated number of segments and
their minimum coverage size plus this additional space. Then set the OPTIMAL
for each segment equal to the minimum coverage size. What you will see is
that
the large transactions will randomly make one of the segments grow and eat up
the free space, but the segment will release the space before the next large
transaction comes along. Note that you are sacrificing some performance for
this flexibility.
NOTE:
====
DDL's will not be affected by SET TRANSACTION USE ROLLBACK SEGMENT.
Example:
------create table as select, alter table..
Create table as select is a data definition (DDL) statement, and as such it
does an implicit commit. A transaction ends once a commit is processed, so
any statements following a DDL command will not be part of the previous
transaction, and therefore commands following the DDL statement may use a
different rollback segment.