当前位置:Gxlcms > mysql > 清理Oracle历史数据的准备工作

清理Oracle历史数据的准备工作

时间:2021-07-01 10:21:17 帮助过:16人阅读

客户要求近期对现网的2个项目的数据库中的历史数据进行清理,于是整理了下应用中的段使用情况,主要是看表段情况,使用的脚本如下

客户要求近期对现网的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-

linux

人气教程排行