How to reduce the size of the datafiles of a oracle DB

oraclesize;

we use a oracle db (11g release2) and the undo tablespase exists of two datafiles and requires 48 GB.
But we just need this size for the boot and the import.
Currently we just use 10 % from the datafiles…

Is it possible to minimize the datafiles online to the needed size ??

Best Answer

-- create a new UNDO tablespace named UNDOTBS2

CREATE UNDO TABLESPACE undotbs2
DATAFILE '/01/oradata/dbname/undotbs201.dbf'
SIZE 50M AUTOEXTEND ON NEXT 5M;

Tablespace created.

-- Switch the database to the new UNDO tablespace.

ALTER SYSTEM SET UNDO_TABLESPACE=UNDOTBS2 SCOPE=BOTH;

-- Drop the old one

DROP TABLESPACE undotbs1 INCLUDING CONTENTS AND DATAFILES;

-- If Undo is still in use

*
ERROR at line 1:
ORA-30013: undo tablespace 'UNDOTBS1' is currently in use

I would try this out first on a test database:

(Following from dead link) from original answer:

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 = 'UNDOTBS1'
         );

The above query shows the name of the UNDO segment in the UNDOTBS1 tablespace and its status. See which users/sessions are running this pending transaction:

SELECT a.name,b.status , d.username , d.sid , d.serial#
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 = 'UNDOTBS1'
         );

You can then kill the session; the following assumes a SID of 147 and a SERIAL# of 4:

alter system kill session '147,4' immediate;