副问题[/!--empirenews.page--]

概述
出产情形中,常常会碰着表因为数据不绝插入,导致空间越来越大,因为前期设置题目,没有做分区可能其他优化,并且出产数据及时向表插入。要删除汗青数据来开释空间。以是DBA一样平常都必要按期去对Oracle表碎片做清算,简朴清算表碎片清算流程如下:
1、定位存在碎片的工具
行使如下剧本,搜查必要举办碎片清算的工具:
- --all tables(partition_tables + non_partition_tables )
- select a.owner,
- a.table_name,
- a.num_rows,
- a.avg_row_len,
- round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB,
- round(b.seg_bytes_mb, 2) seg_bytes_mb,
- decode(a.num_rows,
- 0,
- 100,
- (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 /
- b.seg_bytes_mb,
- 2)) * 100) || '%' frag_percent
- from dba_tables a,
- (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb
- from dba_segments
- group by owner, segment_name) b
- where a.table_name = b.segment_name
- and a.owner = b.owner
- and a.owner not in
- ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS',
- 'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN')
- and decode(a.num_rows,
- 0,
- 100,
- (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 /
- b.seg_bytes_mb,
- 2)) * 100) > 30
- order by b.seg_bytes_mb desc;

2、统计信息搜查
2.1 统计信息搜查
查察统计信息网络日期,确保碎片查询功效精确:
- select owner,table_name,last_analyzed from dba_tables Where owner='<OWNER>' AND table_name='<TABLE_NAME>';

2.2 统计信息网络
假如统计信息过旧,则从头网络统计信息:
- exec dbms_stats.gather_table_stats(ownname=>'<OWNER>', tabname =>'<TABLE_NAME>');

3、表碎片清算
3.1 打开行移动
- alter table <TABLE_NAME> enable row movement ;
3.2 举办表紧缩
- alter table <TABLE_NAME> shrink space cascade ;
3.3 失效工具编译
语句也许会造成引用表
的工具(如存储进程、包、视图等)变为无效。
运行如下剧本,从头编译失效工具。
- @?/rdbms/admin/utlrp.sql
4、工具紧缩后的功效搜查
运行如下剧本,确认工具空间是否已经完成紧缩。
- --all tables(partition_tables + non_partition_tables )
- select a.owner,
- a.table_name,
- a.num_rows,
- a.avg_row_len,
- round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB,
- round(b.seg_bytes_mb, 2) seg_bytes_mb,
- decode(a.num_rows,
- 0,
- 100,
- (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 /
- b.seg_bytes_mb,
- 2)) * 100) || '%' frag_percent
- from dba_tables a,
- (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb
- from dba_segments
- group by owner, segment_name) b
- where a.table_name = b.segment_name
- and a.owner = b.owner
- and a.owner not in
- ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS',
- 'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN')
- and decode(a.num_rows,
- 0,
- 100,
- (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 /
- b.seg_bytes_mb,
- 2)) * 100) > 30
- order by b.seg_bytes_mb desc;
5、机能监控
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|