1) Identify and Move Indexes from Tablespace to another:-
DECLARE
x VARCHAR2 (512);
BEGIN
FOR i IN (SELECT s.tablespace_name, s.owner, s.segment_name,
s.segment_type, SUM (s.BYTES) size_in_bytes,
ROUND (SUM (s.BYTES) / 1024 / 1024, 2) size_in_m,
f.file_name
FROM SYS.dba_segments s, SYS.dba_data_files f
WHERE f.tablespace_name = s.tablespace_name
AND f.file_id = s.header_file
AND s.tablespace_name IN ('XLPDATA')
AND segment_type = 'INDEX'
AND Owner = 'OMFX'
GROUP BY s.tablespace_name,
s.owner,
s.segment_name,
s.segment_type,
f.file_name)
LOOP
x :=
'ALTER INDEX OMFX.' || i.segment_name
|| ' REBUILD TABLESPACE OMFX_TBS';
DBMS_OUTPUT.put_line
(x);
EXECUTE IMMEDIATE (x);
END LOOP;
END;
/
2) Identify and Move tables from Tablespace to another:-
DECLARE
y VARCHAR2 (512);
BEGIN
FOR i IN (SELECT s.tablespace_name, s.owner, s.segment_name,
s.segment_type, SUM (s.BYTES) size_in_bytes,
ROUND (SUM (s.BYTES) / 1024 / 1024, 2) size_in_m,
f.file_name
FROM SYS.dba_segments s, SYS.dba_data_files f
WHERE f.tablespace_name = s.tablespace_name
AND f.file_id = s.header_file
AND s.tablespace_name IN ('XLPIDX')
AND segment_type = 'TABLE'
AND Owner = 'OMFX'
GROUP BY s.tablespace_name,
s.owner,
s.segment_name,
s.segment_type,
f.file_name)
LOOP
y := 'ALTER TABLE OMFX.' || i.segment_name || ' MOVE TABLESPACE OMFX_TBS';
DBMS_OUTPUT.put_line
(Y);
EXECUTE IMMEDIATE (y);
END LOOP;
END;
/
3) Identify and LOB segments from Tablespace to another:-
SELECT 'alter table '
||
owner
|| '.'
||
table_name
|| ' move lob ('
||
column_name
|| ')'
|| 'store as (tablespace
AWFE_TBS);'
FROM dba_lobs
WHERE segment_name IN (
SELECT segment_name
FROM dba_segments
WHERE tablespace_name = 'AWFE_TBS'
AND owner = 'PORTAL'
AND segment_type = 'LOBSEGMENT');
No comments:
Post a Comment