歡迎您光臨本站 註冊首頁

清理Oracle歷史數據的準備工作

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  

客戶要求近期對現網的2個項目的資料庫中的歷史數據進行清理,於是整理了下應用中的段使用情況,主要是看錶段情況,使用的腳本如下。

create or replace procedure get_tab_rows
as
--Drop Table tabsrow
--Create Global Temporary Table tabsrow (Name Varchar2(30),Rowsnum Number) On Commit Delete Rows;
--Create  Table tabsrow (Name Varchar2(30),Rowsnum Number) ;
V_SQL Varchar2(300);
Begin
  Execute Immediate 'truncate table tabsrow';
  For x In (Select OWNER,table_name From dba_tables Where owner='XXX' and table_name<>'test') Loop
     V_SQL:='insert into tabsrow Select '''||x.table_name||''' ,Count(1) From  '||X.OWNER||'.'||x.table_name;
     Execute Immediate V_SQL;
  End Loop;
commit;
End;
/
exec get_tab_rows;
Select a.Owner,
       a.Table_Name,
       --b.Segment_Name,
       a.Tablespace_Name,
       b.Bytes/1024/1024 as "size(Mb)",e.rowsnum,
       --b.Blocks,
       --c.Table_Name,
       c.Partitioning_Type,
       d.column_name
  From Dba_Tables a
  Left Join (Select b.Segment_Name, Sum(b.Bytes) Bytes, Sum(b.Blocks) Blocks
               From Dba_Segments b
              WHERE B.OWNER = 'XXX'
                AND B.segment_type NOT IN ('INDEX')
              Group By b.Segment_Name) B on a.Table_Name = b.Segment_Name
  Left Join Dba_Part_Tables c On a.Table_Name = c.Table_Name
  left join Dba_Part_Key_Columns d on d.owner = 'XXX'
                                  and a.table_name = d.name   
                                  left join tabsrow e on a.table_name=e.name           
 Where a.Owner = 'XXX' order by "size(Mb)" desc;
drop procedure get_tab_rows;
Drop Table tabsrow;

-The End-



[火星人 ] 清理Oracle歷史數據的準備工作已經有382次圍觀

http://coctec.com/docs/linux/show-post-74051.html