Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3550110
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客

分类: Oracle

2022-09-03 22:28:38


简单的算法来评估:

  1. --先收集一下表的统计信息,也可忽略此步
  2. EXEC DBMS_STATS.GATHER_TABLE_STATS('A','BIG')

  3. --将平均长度(占几个字节)乘以要删除的记录数
  4. select round(AVG_ROW_LEN*5000000/1024/1024*1.4) arch_size_mb 
  5.  from dba_tables where table_name='BIG';

  6. 在这里用了一个系数 1.4,即占用空间要多40%出来,系数不具有普遍正确性,如果索引比较多,可能需要改为5!

大量的删除、更新通常会导致数据库块出现碎片的情况,影响性能和浪费空间。

oracle是这样设计的:
This is best illustrated with an example: Consider a transaction that updates a million row table. This obviously visits a large number of database blocks to make the change to the data. When the user commits the transaction Oracle does NOT go back and revisit these blocks to make the change permanent. It is left for the next transaction that visits any block affected by the update to 'tidy up' the block (hence the term 'delayed block cleanout')
更新百万行表的事务显然会访问大量数据库块以对数据进行更改。当用户提交事务时,Oracle不会返回并重新访问这些块以使更改永久化。它被留给下一个交易,该交易访问受更新影响的任何区块以“整理”区块(因此术语“延迟区块清理”)。

说到底还是为了性能。

评估库里哪些表存在碎片情况:

  1. col frag format 9999.99
  2. col owner format a30
  3. col table_name format a30

  4. SELECT *
  5. FROM
  6.     (SELECT a.owner,
  7.          a.table_name,
  8.          a.num_rows,
  9.          round(a.avg_row_len * a.num_rows/1024/1024) esti_size_mb,
  10.          round(sum(b.bytes/1024/1024)) real_size_mb,
  11.          (a.avg_row_len * a.num_rows) / sum(b.bytes) frag
  12.     FROM dba_tables a, dba_segments b
  13.     WHERE a.table_name = b.segment_name
  14.             AND a.owner= b.owner
  15.      AND b.bytes/1024/1024>100
  16.             AND a.owner IN
  17.         (SELECT username
  18.         FROM dba_users
  19.         WHERE ORACLE_MAINTAINED='N')
  20.         GROUP BY a.owner,a.table_name,a.avg_row_len, a.num_rows
  21.         HAVING a.avg_row_len * a.num_rows / sum(b.bytes) < 0.7
  22.         ORDER BY sum(b.bytes) desc)
  23.     WHERE rownum <= 30;
对100M以上的表进行估算,准确的情况可以参考show_space结果,详见之前的
http://blog.chinaunix.net/uid-20687159-id-5848525.html

如果发现碎片化高的表,消除的方法可以考虑:
1. alter table XXX move;  --索引需要重建
2. create table NEW as select * from OLD;  --适合保留数据较少的情况
3. 在线重定义

阅读(360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~