Oracle 准确估算数据泵导出数据大小

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语句。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值