estimate table size after reorg (using dbms_space)
来源:互联网 发布:linux认证去那里考试 编辑:程序博客网 时间:2024/05/22 16:20
When table had huge amount of records deleted, you may need a reorg to lower the high water mark and improve full scan performance.
If using ASSM, you may use dbms_space.space_usage to estimate the emptiness of the blocks.
This script checks how many blocks are 0%, 25%,50%,75%,100% filled for all tables of one user, and gives corresponding estimation for the reorg.
works only on ASSM tablespaces
the script assumes that the pct_free will be the same.
set serveroutput on linesize 132
declare
l_fs1_bytes number;
l_fs2_bytes number;
l_fs3_bytes number;
l_fs4_bytes number;
l_fs1_blocks number;
l_fs2_blocks number;
l_fs3_blocks number;
l_fs4_blocks number;
l_full_bytes number;
l_full_blocks number;
l_unformatted_bytes number;
l_unformatted_blocks number;
l_used_bytes_l number;
l_used_bytes_h number;
l_current_bytes number;
begin
for seg in (
select segment_space_management,seg.owner,seg.segment_name,segment_type,seg.partition_name,pct_free,bytes
from dba_segments seg join (
select owner,pct_free, cluster_name segment_name,'' partition_name from DBA_CLUSTERS
union all
select owner,pct_free, index_name,'' partition_name from DBA_INDEXES
union all
select owner,pct_free, table_name,'' partition_name from DBA_TABLES
union all
select table_owner,pct_free, table_name,partition_name from DBA_TAB_PARTITIONS
union all
select index_owner,pct_free, index_name,partition_name from DBA_IND_PARTITIONS
union all
select table_owner,pct_free, table_name,partition_name from DBA_TAB_SUBPARTITIONS
union all
select index_owner,pct_free, index_name,partition_name from DBA_IND_SUBPARTITIONS
) obj on (obj.owner=seg.owner and obj.segment_name=seg.segment_name and (seg.partition_name is null or seg.partition_name=obj.partition_name))
join dba_tablespaces using(tablespace_name)
where segment_space_management='AUTO' and seg.owner = '&owner'
and segment_type in ('TABLE','TABLE PARTITION','TABLE SUBPARTITION','INDEX','INDEX PARTITION','INDEX SUBPARTITION','CLUSTER','LOB')
)
loop
dbms_space.space_usage(
segment_owner => seg.owner,
segment_name => seg.segment_name,
segment_type => seg.segment_type,
partition_name => seg.partition_name,
fs1_bytes => l_fs1_bytes,
fs1_blocks => l_fs1_blocks,
fs2_bytes => l_fs2_bytes,
fs2_blocks => l_fs2_blocks,
fs3_bytes => l_fs3_bytes,
fs3_blocks => l_fs3_blocks,
fs4_bytes => l_fs4_bytes,
fs4_blocks => l_fs4_blocks,
full_bytes => l_full_bytes,
full_blocks => l_full_blocks,
unformatted_blocks => l_unformatted_blocks,
unformatted_bytes => l_unformatted_bytes
);
--dbms_output.put_line(' FS1 Blocks = '||l_fs1_blocks||' Bytes = '||l_fs1_bytes);
--dbms_output.put_line(' FS2 Blocks = '||l_fs2_blocks||' Bytes = '||l_fs2_bytes);
--dbms_output.put_line(' FS3 Blocks = '||l_fs3_blocks||' Bytes = '||l_fs3_bytes);
--dbms_output.put_line(' FS4 Blocks = '||l_fs4_blocks||' Bytes = '||l_fs4_bytes);
--dbms_output.put_line('Full Blocks = '||l_full_blocks||' Bytes = '||l_full_bytes);
l_used_bytes_l:=0;
l_used_bytes_h:=0;
-- full blocks will reorg in between current and current + pctfree
l_used_bytes_l:=l_used_bytes_l + l_full_bytes ;
l_used_bytes_h:=l_used_bytes_h + l_full_bytes * (1+seg.pct_free/100) ;
-- FS1 will reorg in between 75% and 100% its size
l_used_bytes_l:=l_used_bytes_l + l_fs1_bytes * 0.75 ;
l_used_bytes_h:=l_used_bytes_h + l_fs1_bytes * 0.99 ;
-- FS2 will reorg in between 50% and 75% its size
l_used_bytes_l:=l_used_bytes_l + l_fs2_bytes * 0.50 ;
l_used_bytes_h:=l_used_bytes_h + l_fs2_bytes * 0.75 ;
-- FS3 will reorg in between 25% and 50% its size
l_used_bytes_l:=l_used_bytes_l + l_fs3_bytes * 0.25 ;
l_used_bytes_h:=l_used_bytes_h + l_fs3_bytes * 0.50 ;
-- FS4 will reorg in between 0 and 25% its size
l_used_bytes_l:=l_used_bytes_l + 0 ;
l_used_bytes_h:=l_used_bytes_h + l_fs4_bytes * 0.25 ;
l_current_bytes:=l_full_bytes+l_fs1_bytes+l_fs2_bytes+l_fs3_bytes+l_fs4_bytes+l_unformatted_bytes;
--dbms_output.put_line(seg.segment_type||' '||seg.owner||'.'||seg.segment_name||' '||seg.partition_name||' reorg will be between '||to_char(l_used_bytes_l,'999G999G999')||' and ' ||to_char(l_used_bytes_h,'999G999G999')||' bytes, CURRENT SIZE: '||to_char((l_full_bytes+l_fs1_bytes+l_fs2_bytes+l_fs3_bytes+l_fs4_bytes+l_unformatted_bytes),'999G999G999'));
dbms_output.put_line(seg.segment_type||' '||seg.owner||'.'||seg.segment_name||' '||seg.partition_name||' reorg will be between '||round(100*l_used_bytes_l/l_current_bytes)||'% and ' ||round(100*l_used_bytes_h/l_current_bytes)||' % of current size '||round(l_current_bytes/1024/1024)||' Mb');
end loop;
end;
/
SQL>
SQL> define owner=FRANCK
SQL> /
old 36: where segment_space_management='AUTO' and seg.owner = '&owner'
new 36: where segment_space_management='AUTO' and seg.owner = 'FRANCK'
TABLE FRANCK.TEST reorg will be between 50% and 70 % of current size 50 Mb
PL/SQL procedure successfully completed.
- estimate table size after reorg (using dbms_space)
- Estimate in progress using
- DB2 REORG TABLE
- Estimate
- Reorg
- How to Estimate Export File Size Without Creating Dump File
- Estimate, Estimate, Estimate
- Fastest way to estimate rows in a table
- DB2中ALTER TABLE为什么需要REORG操作?
- 如何使用REORG TABLE命令优化数据库性能
- 如何使用REORG TABLE命令优化数据库性能
- DB2 Alter Table导致表处于Reorg Pending状态
- 数据库重组函数:call sysproc.admin_cmd('reorg table TABLE_NAME');
- Script: Computing Table Size
- Hash table size-prime
- Oracle table size
- Using Functions after the Pipeline
- dbms_space.free_space
- Checkpoint Tuning and Troubleshooting
- 刚入道的一点浅浅的感受
- 27 FAQs on Oracle loading data and exporting data
- Amazing Oracle 10g benchmark with a terabyte of RAM
- Comparison of Oracle, MySQL and PostgreSQL DBMS
- estimate table size after reorg (using dbms_space)
- 将自己的程序与文件关联
- 想成为嵌入式程序员应知道的0x10个基本问题(太经典了)
- 一些C#相关知识整理
- Locks tree sessions
- Create Dynamic URLs With Mod_Rewrite and PHP Functions
- 电话号码存储系统(包括姓名/地址)
- Msql乱码问题分析
- 动荡的心