admin管理员组文章数量:1660164
Oracle 准确估算数据泵导出数据大小
场景:
客户会有某种需求,想要估算出数据库的全库导出的逻辑大小,来判断预留磁盘空间是否足够,此时就需要我们尽可能的准确分析估算导出的数据大小。
分两种情况:(不考虑索引段情况下进行测试)
一:高水位线以下不存在空块
1.采用dba_segments视图估算的大小值
2.采用estimate进行估计(blocks/statistics)
3.实际导出大小值
二:高水位线以下存在空块
1.采用dba_segments视图进行估计
2.采用estimate进行估计(blocks/statistics)
3.实际导出大小值
实践流程:
创建一个测试表:(hr用户)
SQL> create table test as select * from employees;
Table created.
SQL> insert into test select * from test;
SQL> insert into test select * from test;
....
SQL> commit;
SQL> select count(*) from test;
COUNT(*)
219136
一.高水位线以下不存在空块:
1.dba_segments估计:
SQL> select sum(bytes)/1024/1024 from dba_segments where segment_name='TEST' and owner='HR';
SUM(BYTES)/1024/1024
18
2.estimate=blocks估计:
[oracle@server1 ~]$
expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=blocks;
. estimated "HR"."TEST" 18 MB
Total estimation using BLOCKS method: 18 MB
3.estimate=statistics估计(未收集统计信息):
[oracle@server1 ~]$ expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=statistics;
. estimated "HR"."TEST" 4.683 KB
Total estimation using STATISTICS method: 4.683 KB
进行一下统计信息收集:
begin
dbms_stats.gather_table_stats
( ownname => 'HR',
tabname => 'TEST',
granularity => 'ALL',
estimate_percent => 100,
method_opt => 'for all columns size auto',
no_invalidate => false,
degree => 1,
cascade => true);
END
4.estimate=statistics估计(收集统计信息):
[oracle@server1 ~]$
expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=statistics;
. estimated "HR"."TEST" 14.42 MB
Total estimation using STATISTICS method: 14.42 MB
5.expdp实际导出:
[oracle@server1 ~]$ expdp system/oracle dumpfile=hr1.dmp directory=pump_dir tables=hr.test
Total estimation using BLOCKS method: 18 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "HR"."TEST" 15.10 MB 219136 rows
二.高水位线存在空块:
SQL> delete from test where employee_id < 150;
102400 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from test;
COUNT(*)
116736
1.dba_segments估计:
SQL> select sum(bytes)/1024/1024 from dba_segments where segment_name='TEST' and owner='HR';
SUM(BYTES)/1024/1024
18
2.estimate=blocks估计:
[oracle@server1 ~]$
expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=blocks;
. estimated "HR"."TEST" 18 MB
Total estimation using BLOCKS method: 18 MB
3.estimate=statistics估计(未收集统计信息):
[oracle@server1 ~]$
expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=statistics;
. estimated "HR"."TEST" 14.42 MB
Total estimation using STATISTICS method: 14.42 MB
4.estimate=statistics估计(已收集统计信息):
再次收集统计信息
[oracle@server1 ~]$
expdp system/oracle estimate_only=y directory=pump_dir tables=hr.test estimate=statistics;
. estimated "HR"."TEST" 7.801 MB
Total estimation using STATISTICS method: 7.801 MB
5.实际expdp导出大小:
[oracle@server1 ~]$ expdp system/oracle dumpfile=hr2.dmp directory=pump_dir tables=hr.test
Total estimation using BLOCKS method: 18 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "HR"."TEST" 8.198 MB 116736 rows
结论:
当估算数据泵导出数据大小,使用dba_segments与estimate=blocks估计时,会计算高水位线以下的所有块,包含数据被delete而 产生的空块,而实际expdp进行导出,是按行进行导出,不会计算不包含数据的块,所以当高水位线以下存在不包含数据的块时,通过estimate=blocks与dba_segments估计并不准确,但是如果我们的统计信息收集准确,使用estimate=statistics这个参数收集最接近实际导出大小。
关于索引段的情况:
当索引段比较大时,dba_segments与 estimate=blocks ,实际expdp导出的大小差距就会比较大,因为dba_segments包含索引段的大小,而expdp estimate 与 实际expdp导出不会将索引段导出,仅会导出创建索引的DDL语句。
版权声明:本文标题:Oracle 准确估算数据泵导出数据大小 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729850853a1215389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论