oracle10G占用硬盘空间,oracle10G dmp导入占用表空间过大问题

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 1月 14 10:25:17 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

连接到:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> SELECT  COUNT(*) FROM TEST01;

COUNT(*)

----------

4119

结论:TEST01表中有4119条记录

SQL> analyze table  TEST01 compute statistics;

表已分析。

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125          124    14-1月 -10

结论:TEST01表占用了2.03125M的大小

SQL> DELETE FROM TEST01;

已删除4119行。

SQL> analyze table  TEST01 compute statistics;

表已分析。

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125           124     14-1月 -10

结论:delete数据后,高水位线不释放,TEST01占用的存储大小与删除前不变。

--用默认的方式导出TEST01表的数据

SQL> host exp report/report@report file=test01.dmp tableS=TEST01

--导出TEST01表的数据,加参数compress=n

SQL> host exp report/report@report file=test01n.dmp tableS=TEST01 compress=n

-- 删除TEST01表

SQL> DROP TABLE TEST01;

表已删除。

-- 导入默认方式导出的TEST表数据,test01.dmp

SQL> host imp report/report@report file=test01.dmp full=y

--查询表中记录数

SQL> select count(*) from test01;

COUNT(*)

----------

0

-- 结论:目前表中没有记录

--查询没有记录的test01表的大小

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125           124     14-1月 -10

-- 结论:虽然test01表没有记录,但仍然占用了2.03125M的存储空间。与删除前占用

的存储空间无变化。

--对TEST01表进行统计分析

SQL> analyze table  TEST01 compute statistics;

表已分析。

--查看统计分析后TEST01表的大小

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119             0           384     14-1月 -10

--结论: 用dmp导入的TEST01表,统计分析后,TEST01表的存储空间发生了改变。

SQL> DROP TABLE TEST01;

表已删除。

-- 导入加compress=n的TEST01表的dmp,test01n.dmp

SQL> host  imp report/report@report file=test01n.dmp  full=y

--查询TEST01表的数据

SQL> select count(*) from test01;

COUNT(*)

----------

0

-- 查询TEST01表占用的存储空间

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125           124     14-1月 -10

--结论:delete表TEST01数据后,导入使用compress=n参数导出的test01n.dmp,未做

统计分析前表存储空间没有改变。

SQL>

-- 对TEST01做统计分析

SQL> analyze table  TEST01 compute statistics;

表已分析。

--查看统计分析后TEST01表大小

SQL> select owner,table_name, NUM_ROWS ,

2  BLOCKS * 8192/1024/1024 "Size M",

3  EMPTY_BLOCKS,

4  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119             0           8     14-1月 -10

--结论:结果表明delete表TEST01数据后,导入使用compress=n参数导出的test01n.dmp,做

统计分析后表存储空间发生改变,为表实际的存储空间。

SQL> spool off

-- 结论:1.在delete数据后,表的高水位线不释放,存储空间不发生改变。

2.在delete数据后导出dmp时,compress参数与表的存储空间无关。

3.在导入delete数据后导出的dmp,对表做统计分析可以改变表的存储空间。

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 1月 14 11:05:17 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

连接到:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

-- 统计TEST01表中的记录数

SQL> select COUNT(1)  from TEST01;

COUNT(1)

----------

4119

--对TEST01表进行统计分析

SQL> analyze table  TEST01 compute statistics;

表已分析。

-- 计算TEST01表占用的表空间

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125           124     14-1月 -10

-- truncate 掉表TEST01

SQL> TRUNCATE TABLE  TEST01;

表被截断。

-- 计算截断后TEST01表占用表空间

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119        2.03125           124     14-1月 -10

--结果表明:截断表后表的存储信息不能立即更新到dba_tables表中。

--对truncate后的表TEST01做统计分析

SQL> analyze table  TEST01 compute statistics;

表已分析。

--计算截断并做统计分析后TEST01占用表空间

SQL> select owner,table_name,

2  NUM_ROWS ,

3  BLOCKS * 8192/1024/1024 "Size M",

4  EMPTY_BLOCKS,

5  LAST_ANALYZED from  dba_tables where table_name='TEST01';

OWNER   TABLE_NAME   NUM_ROWS    Size M   EMPTY_BLOCKS   LAST_ANALYZED

------- ----------   ---------   -------   ----------    -------------

REPORT  TEST01       4119             0           8     14-1月 -10

--结果表明:截断并做统计分析后,TEST01表的存储空间发生改变。

SQL> spool off

结论:  对表进行truncate操作,会影响高水位线,能释放表占用的存储空间。

但不能及时更新到字典表中dba_tables。需要统计分析后才能更新到

字典表中。

为了避免这个问题在导出数据前可以对记录为0的表进行truncate,在统计分析。这样能体现出表所使用的实际表空间值。或者在导入数据后对表进行统计分析也可能释放一部份表空间。至此困扰我的,dmp导入后占用巨大表空间的问题暂时告一段落。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值