To simplify management of rollback segments, the Oracle9i
database introduced Automatic Undo Management (AUM) where the database automatically
manages allocation and management of undo (rollback) space among various active
sessions. In a database using AUM, all transactions share a single undo tablespace.
Any executing transaction can consume free space in this tablespace. Undo space
is dynamically transferred from committed transactions to executing transactions
in the event of space scarcity in the undo tablespace..The AUM feature also
provides a way for administrators to exert control on undo retention. You can
specify the amount of undo to be retained in terms of wall clock time (number
of seconds). With retention control, you can configure your systems to allow
long running queries to execute successfully without encountering ORA-1555 (Snapshot
too old) errors..The undo retention time is specified using a new persistent
initialization parameter, UNDO_RETENTION. This parameter is dynamic and hence
can be changed anytime during database operation using the ALTER SYSTEM command.
The AUM feature is further enhanced in Oracle Database 10g
by providing Automatic Undo Retention Tuning. This feature is used by default,
and it automatically determines the optimal undo retention time depending on
the size of the undo tablespace. Without your intervention, the Oracle Database
10g dynamically adjusts to the change in undo requirements depending
on the system activity. This maximizes the usage of the available space in the
undo tablespace and allows long running queries to complete without encountering
any Snapshot Too Old errors provide your undo tablespace is big
enough.
In this lesson, you will intentionally switch to a small undo
tbs, and although you use automatic undo retention tuning, you will encounter
1555 because the undo tbs is too small. In which case you need the undo advisor
to compute the right size that depends on the workload.
To see how undo management is handled, you need
to generate some activity. Perform the following:
1.
You will first need to determine the date and time of
your database. Open a terminal window and enter the following commands:
cd wkdir
sqlplus /nolog
connect / as sysdba;
@datetime
The datetime.sql
script looks as follows:
select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')
from dual;
2.
From the same session, execute the following command:
@newtable
The newtable.sql
script looks as follows:
create table newtable(b int, s varchar2(100)); begin for i in 1..100 loop insert into newtable values(i, rpad('s', 100)); end loop; commit; end; /
3.
From the first session, execute the following:
@uscript1
The uscript1.sql
script looks as follows:
declare b number; cursor c1 is select b from newtable; begin open c1; loop fetch c1 into b; dbms_lock.sleep(6); exit when c1%notfound; end loop; close c1; commit; end; /
4.
Open another terminal window and execute the following
commands:
cd wkdir
sqlplus /nolog
connect / as sysdba
@uscript2
The uscript2.sql
script looks as follows:
begin for i in 1..1000 loop update newtable set b=b+1, s=rpad('t', 100); commit; end loop; end; /
5.
Switch back to the first SQL*Plus session. Soon, you
get a "Snapshot too old" error. Although you are using Automatic
Undo Retention tuning, your undo tablespace is too small to accommodate
the update script.
To review the recommendations that the undo advisor
made, perform the following:
1.
Switch back to Enterprise Manager and
look at the Undo Management page. Notice that the current recommendation
(61MB) is because the default analysis is for the past seven days. Since
you want to analyze a particular workload, and not what had happened before
you will need to customize the time period. Select the Customized Time
Period for the Analysis Time Period and click Update Analysis.
2.
Use the date and time you determined previously for
the Period Starts field. For the Period Ends field, use the same value
plus two hours. Once done, press the OK button.
3.
You want perform the recommendation and raise the size
of your undo tablespace. Click Edit Undo Tablespace.
4.
Click Add to add a datafile.
5.
Enter ut2.dbf as the filename and specify whatever
the recommendation should be. Then click OK.
6.
Click Apply.
7.
Select your Database breadcrumb.
8.
Select Undo Management.
9.
You need to change the time period
again. Select the Customized Time Period for the Analysis Time
Period and click Update Analysis.
10.
Change the date and time to the
same as you did in step 2. Then click OK.
11.
Notice that there are no problems or recommendations
any longer. You may try running the uscript1 and uscript2 again to make
sure the size of your tablespace is appropriate.
Place the cursor on this icon to hide all screenshots.