Tuesday, March 20, 2018

How to Resize the Undo Tablespace


1. To Shrink the Undo Tablespace Size.
2. Add Space to the Undo Tablespace.

Solution:

1. To Shrink the Undo Tablespace Size.
Undo space once allocated will be available for reuse but will not be deallocated to the OS. The best way to shrink Undo tablespace is to switch to a new Undo tablespace and drop the old Undo tablespace. The steps are:

a) Create a new undo tablespace of the same size (larger or smaller) depending on your database requirements.

SQL> create undo tablespace undotbs02 datafile '/u01/oracle/prod/undotbs02.dbf' size 5000M;

b) Switch to the new Undo tablespace

ALTER SYSTEM SET UNDO_TABLESPACE = undotbs02 SCOPE=BOTH;

c) Check the status of the undo segments and determine if all the segments in the old undo tablespace are offline.

select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status;

If there are Undo segments with status other than OFFLINE in the tablespace to be dropped, we need to wait till they become OFFLINE. You may have to wait for the duration of the tuned_undoretention (from v$undostat) to ensure all Undo segments have become OFFLINE.

select status,segment_name from dba_rollback_segs where status not in ("OFFLINE') and tablespace_name=<undo tablespace to be dropped>;

eg:

select status,segment_name from dba_rollback_segs where status not in ("OFFLINE') and tablespace_name='UNDOTBS1';

d). If all the Undo segments in the old Undo tablespace to the dropped is of status OFFLINE, then drop the tablespace.

select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status;

Verify and then drop:

SQL>Drop tablespace <tablespace_name> including contents and datafiles;

eg:

SQL>Drop tablespace UNDOTBS1 including contents and datafiles;

2. Add Space to the Undo Tablespace.

For increasing / resize undo tablespace there are two options :
a) Resize the existing undo datafile
b) Add new undo datafile to the tablespace.

a) To resize the existing undo datafile:

select tablespace_name T_NAME,file_name, bytes/1024/1024 MB from dba_data_files where tablespace_name =(SELECT UPPER(value) FROM v$parameter WHERE name = 'undo_tablespace') order by file_name;

alter database datafile '<COMPLETE_PATH_OF_UNDO_DBF_FILE>' resize <SIZE>M;

Example:
alter database datafile '/u01/oracle/prod/undotbs02.dbf' resize 1500M;
 

b) Step to add a new datafile:

alter tablespace <UNDO tbs name> ADD DATAFILE '<COMPLETE_PATH_OF_UNDO_DBF_FILE>' size 20M;

Example:
alter tablespace UNDOTBS1 ADD DATAFILE '/u01/oracle/prod/undotbs02.dbf' size 20M;

No comments:

Post a Comment