Month: January 2008

Move a Tablespace

This may be pointless, but maybe some of the SQL may help someone.  It is an attempt at boiling all the steps from another post into one SQL script.  The rename at the end didn’t seem to work for some reason, and I didn’t want to put any more time into it.


declare

  tblName varchar(25);

  tempName varchar(25);

  segmentCount number(10);

  osOutput number(3);

begin

   tblName := 'AAAPP';

   dbms_output.put_line('Moving tablespace: ' || tblName);

   tempName := tblName || 'NEW';

   dbms_output.put_line('Using temporary tablespace: ' || tempName);

   select count(*) into segmentCount from dba_segments

   where tablespace_name = tblName;

   dbms_output.put_line('Currently ' || segmentCount || ' segments');

   execute immediate 'create tablespace ' || tempName ||

       ' datafile ''e:\oradata\HCM90\' || tempName || '.DBF''' ||

       ' size 10m ' ||

       ' extent management local autoallocate ' ||

       ' segment space management auto ';

   execute immediate 'ALTER DATABASE DATAFILE ''e:\oradata\HCM90\' ||

      tempName || '.DBF'' AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED';

   for index_rec in (select owner, segment_name

                     from dba_segments

                     where segment_type = 'TABLE'

                     and tablespace_name = tblName)

   loop

      execute immediate 'alter table ' || index_rec.owner || '.' ||

          index_rec.segment_name || ' move tablespace ' || tempName;

   end loop;

   for index_rec in (select owner, table_name, column_name

                     from dba_lobs

                     where tablespace_name = tblName)

   loop

      execute immediate 'alter table ' || index_rec.owner || '.' ||

          index_rec.table_name || ' move lob(' || index_rec.column_name ||

          ') store as (tablespace ' || tempName || ')';

   end loop;

   select count(*) into segmentCount from dba_segments

   where tablespace_name = tblName;

   dbms_output.put_line('Now ' || segmentCount || ' segments');

   execute immediate 'alter tablespace ' || tblName || ' offline';

   execute immediate 'drop tablespace ' || tblName;

   execute immediate 'alter tablespace ' || tempName || ' rename to ' || tblName;

   dbms_output.put_line('Renaming ' || tempName || ' to ' || tblName);

   dbms_pipe.pack_message('cmd /c del e:\oradata\HCM90\' || tblName || '.DBF');

   osOutput := dbms_pipe.send_message('HOST_PIPE');

   dbms_output.put_line('Deleted e:\oradata\HCM90\' || tblName || '.DBF -- ' || osOutput);

end;

HCM90: More Tablespace Sizing

There is a fix out to reduce the database size:

  • Financials: 704935
  • HRMS: 704332
  • Portal: 704763

The only difference between the changes in the fix and what I had previously done,  is the blocksize setting.  As far as I could tell, it really didn’t make a sizeable impact.  What did make a difference was changing the properties on the other tablespaces besides the index tablespace.

Below I have listed some SQL and such that I used to shrink the database and move segments from the tablespaces.

Read More