0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

肥大化したテーブルをSHRINKする

Posted at

よく忘れるので。
IMP、全テーブルDROP、同じテーブルをIMP・・・
を繰り返していると40MB程度のDMPのはずなのに、表領域が14GB・・・
そんなときに実行するSQL

動的SQL.sample
--SELECT 'TRUNCATE TABLE ' || table_name || ';' ,table_name FROM USER_ALL_TABLES
--order by table_name

declare
 tname varchar2(512);
 ssql  varchar2(512);
begin
 for rec in (SELECT SEGMENT_NAME, SEGMENT_TYPE, SUM(BYTES)/1024/1024 "MB"
                FROM USER_SEGMENTS
                WHERE SEGMENT_TYPE LIKE '%TABLE%' --テーブルで実施したらINDEXもSHRINKされた
                having SUM(BYTES)/1024/1024 > 5 
                GROUP BY SEGMENT_NAME, SEGMENT_TYPE
                order by 3 desc) loop
    ssql := 'ALTER TABLE ' || rec.SEGMENT_NAME || ' ENABLE ROW MOVEMENT';
    EXECUTE IMMEDIATE ssql;
    ssql := 'ALTER TABLE ' || rec.SEGMENT_NAME || ' SHRINK SPACE CASCADE';
    EXECUTE IMMEDIATE ssql;
    ssql := 'ALTER TABLE ' || rec.SEGMENT_NAME || ' DISABLE ROW MOVEMENT';
    EXECUTE IMMEDIATE ssql;

 end loop;
 

end ;
/
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?