oracle数据占用空间过大的分析

通过exp/imp进行数据库备份或搭建测试环境。

在imp中导入一个用户模式时,即使是空表(ROWS=N),表空间占用很大(20多GB), 后续导入会报"Unable to INITIAL EXTENT ....tablespace"  错误。

 

查找原因发现是表空间已满了。(可通过数据库自带的em管理页面查看)

看一个简单的实验:

查看某个表空间大小:

  1. select /*+ ordered use_merge(a,b) */  
  2.    a.tablespace_name             表空间名,  
  3.    total/(1024*1024)             表空间大小,  
  4.    (total-free)/(1024*1024)        表空间使用大小,  
  5.    free/(1024*1024)             表空间剩余大小,  
  6.    round((total-free)/total,4)*100 "使用率%"  
  7. from (select   tablespace_name,sum(bytes) free from dba_free_space  
  8.        group by tablespace_name) a,  
  9.    (select   tablespace_name,sum(bytes) total from dba_data_files  
  10.        group by tablespace_name) b  
  11. where   a.tablespace_name = b.tablespace_name  
  12. and a.tablespace_name = 'TEST_GENERAL_DAT_TS';  

导入前:(单位MB)

表空间名                             表空间大小              表空间使用大小  剩余大小       使用率

IA_GENERAL_DAT_TS        37067.984375        .171875        37067.8125        0%


查看某个用户段大小:

  1. select sum(t.bytes) from dba_segments t where t.owner='TEST';  

导入前  0.

 

导入一个用户后,导出文件.dmp时的选项(compress = Y)

表空间大小

 1        IA_GENERAL_DAT_TS        37067.984375        26485.671875        10582.3125        71.45%

 

select sum(t.bytes) from dba_segments t where t.owner='TEST';

 sum  = 37725732864 bytes

 

把该用户删掉,重新导入。导出.dmp文件时的选项(compress = N)

表空间大小

1        IA_GENERAL_DAT_TS        37067.984375        5.421875        37062.5625        .01%

          

select sum(t.bytes) from dba_segments t where t.owner='TEST';

 sum  = 8847360 bytes

 

通过上述加上compress=n 选项即可解决导入空表时表空间过大的问题。

compress 选项并非压缩的意思,而是与表的initial storage 设置相关的, 如果为Y, 即导入的表大小跟原始数据库表大小一致(即使是空表!!)

posted @ 2013-09-06 09:54  lishoubin  阅读(1066)  评论(0编辑  收藏  举报