Sei sulla pagina 1di 8

1.

Managing Undo Table Spces

Create undo table space:-

Altering UNDO Tablespace

The following example adds a new datafile to undo tablespace

How to switch the database to a new UNDO tablespace and drop the old one

The current undo tablespace as suggested by the initialization parameter


undo_tablespace is UNDOTBS02. Leave this sysdba as is, open another console,
log in as user kusuma/kusuma and initiate a transaction.

Undo Table Space Management Page 1


With an update on emp table we have initiated a transaction. The undo data is
written to a segment in the UNDOTBS02 tablespace. Now leave this kusuma's
session intact and go back to the sysdba console without issuing any COMMIT or
ROLLBACK.

-- Switch the database to the new UNDO tablespace.

-- Try to drop the tablespace but failed.

With the alter system set undo_tablespace=UNDOTBS3, the database UNDO


tablespace is changed and any new transaction's undo data will go to the new
tablespace i.e. UNDOTBS3. But the undo data for already pending transaction
Undo Table Space Management Page 2
(e.g. the one initiated by kusuma before the database UNDO tablespace switch)
is still in the old tablespace with a status of PENDING OFFLINE. As far as it is
there you cannot drop the old tablespace.

set lines 10000


column name format a10

SELECT a.name,b.status
FROM v$rollname a,v$rollstat b
WHERE a.usn = b.usn
AND a.name IN (
SELECT segment_name
FROM dba_segments
WHERE tablespace_name = 'UNDOTBS02'
);

NAME STATUS
---------- ---------------
_SYSSMU8$ PENDING OFFLINE

The above query shows the name of the UNDO segment in the UNDOTBS02
tablespace and its status. Now lets see which users/sessions are running this
pending transaction.

column username format a6

SELECT a.name,b.status , d.username , d.sid , d.serial#

Undo Table Space Management Page 3


FROM v$rollname a,v$rollstat b, v$transaction c , v$session d
WHERE a.usn = b.usn
AND a.usn = c.xidusn
AND c.ses_addr = d.saddr
AND a.name IN (
SELECT segment_name
FROM dba_segments
WHERE tablespace_name = 'UNDOTBS02'
);

NAME STATUS USERNA SID SERIAL#


---------- --------------- ------ ---------- ----------
_SYSSMU8$ PENDING OFFLINE KUSUMA 31 27

So this is KUSUMA with SID=31 and SERIAL#=27 Since we know now the user,
we can go to him/her and request to end the transaction gracefully i.e. issue a
ROLLBACK or COMMIT. However, if this is not possible (say the user initiated
the transaction and left for annual leave :) and trust me this happens) you may
go ahead and kill the session to release the undo segments in the UNDOTBS02
tablespace.

Undo Table Space Management Page 4


Please see the below alert log messages.

Undo Table Space Management Page 5


If you are retaining undo data then you still won't be able to drop the
tablespace because it is still in use by undo_retention. Let the
UNDO_RETENTION time pass and then try to drop the tablespace. In my case it
is 900 seconds i.e. 15 minutes.

Please see the below alert.log file.

Undo Table Space Management Page 6


Undo is not used by users directly but by statements which modify many
database blocks. Try to search for session which generates a lot of redo.

This query lists information about undo segments in the SIUE DBORCL database.
Note the two segments in the SYSTEM tablespace and the remaining segments in
the UNDO tablespace.

Undo Table Space Management Page 7


This query checks the use of an undo segment by any currently active transaction
by joining the V$TRANSACTION and V$SESSION views.

Undo Table Space Management Page 8

Potrebbero piacerti anche