查看完整版本: 【百科】Rollback(undo) Segment 优化

hanboying18e435 2008-4-11 11:24

【百科】Rollback(undo) Segment 优化

  1、概念
  Transaction以轮循的方式使用[url=http://whatis.ctocio.com.cn/searchwhatis/218/6093718.shtml]rollback[/url] segment里的extent,当前所在的extent满时就移动到下一个extent。可能有多个[url=http://whatis.ctocio.com.cn/searchwhatis/297/6092797.shtml]transaction[/url]同时向同一个extent写数据,但一个rollback [url=http://whatis.ctocio.com.cn/searchwhatis/469/5948969.shtml]segment[/url] block中只能保存一个transaction的数据。
  [url=http://whatis.ctocio.com.cn/searchwhatis/14/6093014.shtml]Oracle[/url] 在每个Rollback segment header中保存了一个transaction [url=http://whatis.ctocio.com.cn/searchwhatis/456/6028456.shtml]table[/url],包括了每个rollback segment中包含的事务信息,rollback segment header的活动控制了向rollbak segment写入被修改的数据。rollback segment header是经常被修改的[url=http://database.ctocio.com.cn/]数据库[/url]块,因此它应该被长时间留在buffer [url=http://whatis.ctocio.com.cn/searchwhatis/459/5946959.shtml]cache[/url]中,为了避免在transaction table产生竞争导致性能下降,应有多个rollback segment或应尽量使用oracle [url=http://whatis.ctocio.com.cn/searchwhatis/497/5948997.shtml]server[/url] 自动管理的rollback segment。
  2、诊断rollback segment header的竞争
  如果rollback segment 由手工管理,下列措施诊断rollback segment header的竞争
  SELECT [url=http://whatis.ctocio.com.cn/searchwhatis/213/5947213.shtml]class[/url],count FROM v$waitstat WHERE class LIKE ’%undo%’ ;
  SELECT Sum(Value) [url=http://whatis.ctocio.com.cn/searchwhatis/422/6026422.shtml]sum[/url] FROM v$sysstat WHERE NAME IN (’db block gets’,’consistent gets’);
  任何类型的等待次数(count)与总请求数(sum)的比率,不能超过1%。
  或
  select sum(waits)*100/sum(gets) "Ratio", sum(waits) "Waits", sum(gets) "Gets" from v$rollstat;
  waits的汇总数与gets的汇总数的比率应低于1%,如果超过1%,应创建更多的rollback segment。
  下列字段数值如果大于0,则表明在rollback segment header上存在竞争:
  A、v$rollstat 中的waits
  B、v$waitstat中的undo header行
  C、v$system_event中的undo segment tx slot事件
  3、消耗更少的rollback segment
  1)如果是删除表里所有的数据,尽可能使用trauncate而不是delete。
  2)在应用中允许用户有规律的提交,尽可能不用长事务。
  3)? Import
  – Set COMMIT = Y
  – Size the [url=http://whatis.ctocio.com.cn/searchwhatis/23/5949023.shtml]set[/url] of rows with BUFFER
  ? Export: Set CONSISTENT=N
  ? SQL*Loader: Set the COMMIT intervals with ROWS
  4、小回滚段可能出现的问题
  A、事务由于缺少回滚空间失败
  B、由于下列原因导致的“Snapshot too old”问题:
  [url=http://whatis.ctocio.com.cn/searchwhatis/364/5946864.shtml]Block[/url]里的事务列表被刷新,block里的SCN比列表Interested Transaction List(ITL)里起始事务的SCN更新;
  Rollback segment header里的Transaction slot被重用;
  回滚数据已经被重写;
  5、9i的自动回滚管理
  Undo_managment指定了回滚空间的管理方式:Auto:自动管理;Manual:手工管理回滚段。
  Undo_retention指定了回滚数据的保留期限;
  Undo_tablespace指定了被使用的回滚表空间;
  Oracle自动管理的表空间可以在常见数据库的时候创建,也可以单独建立。回滚表空间可以相互转换([url=http://whatis.ctocio.com.cn/searchwhatis/462/6026462.shtml]switch[/url]),但在某一时刻只能有一个回滚表空间处于活动状态。回滚表空间处于非活动状态时可以删除,如果有对处于被删除回滚表空间里的已提交事务的查询时,oracle会返回一个错误。
  估计undo [url=http://whatis.ctocio.com.cn/searchwhatis/458/6028458.shtml]tablespace[/url]大小的公式:
  Undo space = (undo_retention * (undo blocks per [url=http://whatis.ctocio.com.cn/searchwhatis/451/5948951.shtml]second[/url] * db_block_size)) + db_block_size;
  可以使用下列的sql设定undo_retention和undo tablespace:
  select (rd*(ups*[url=http://whatis.ctocio.com.cn/searchwhatis/43/6093043.shtml]overhead[/url])+overhead) "bytes" from (select value rd from v$[url=http://whatis.ctocio.com.cn/searchwhatis/420/6025920.shtml]parameter[/url] where name =’undo_retention’),(select (sum(undoblks)/sum(((end_tim[url=http://whatis.ctocio.com.cn/searchwhatis/246/5947746.shtml]e-[/url]begin_time)*10800))) ups from v$undostat),(select value overhead from v$parameter where name=’db_block_size’);
  其中:
  Rd:undo_retention设置的时间;
  Ups:undo blocks per second;
  Overhead:rollback segment header;

杀死白雪公主 2008-4-15 14:43

谢谢~不错~
页: [1]
查看完整版本: 【百科】Rollback(undo) Segment 优化