网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.FORM程序中Oracle与Access表的导.
.Replace函数操作CLOB导致临时表空.
.Windows下如何彻底删除Oracle.
.如何压缩可执行文件.
.Oracle在Linux下的安装.
.oracle中解决汉字无法显示、输入.
.递归程序的应用.
.实例讲解Oracle里抽取随机数的多.
.如何在Oracle中实现时间相加处理.
.用JDBC连接Oracle数据库的十项技.
.Redhat 8.0 下Gaim0.58 for QQ、.
.ORACLE数据库中SQL*NET常见问题解.
.Linux: 单边生存之路.
.启动Oracle常见疑难问题分析.
.用ODP.NET执行SQL读取数据库记录.
.buffer cache深度分析:概念以及.
.Oracle基本数据类型存储格式浅析.
.如何自制 bootdisk.
.怎样自动将数据导入 Oracle数据库.
.新手上路:Oracle基础工具简介.

“Snapshot too old” Detailed Explanation

发表日期:2008-2-9



  Overview
  This article will discuss the circumstances under which a query can return the Oracle error ORA-01555 "snapshot too old (rollback segment too small)". The article will then proceed to discuss actions that can be taken to avoid the error and finally will provide some simple PL/SQL scripts that illustrate the issues discussed.
  
  Terminology
  It is assumed that the reader is familiar with standard Oracle terminology sUCh as 'rollback segment' and 'SCN'. If not, the reader should first read the Oracle Server Concepts manual and related Oracle documentation.
  
  In addition to this, two key concepts are briefly covered below which help in the understanding of ORA-01555:
  
  1. READ CONSISTENCY:
  ====================
  
  This is documented in the Oracle Server Concepts manual and so will not be discussed further. However, for the purposes of this article this should be read and understood if not understood already.
  
  Oracle Server has the ability to have multi-version read consistency which is invaluable to you because it guarantees that you are seeing a consistent view of the data (no 'dirty reads').
  
  2. DELAYED BLOCK CLEANOUT:
  ==========================
  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').
  
  Whenever Oracle changes a database block (index, table, cluster) it stores a pointer in the header of the data block which identifies the rollback segment used to hold the rollback information for the changes made by the transaction. (This is required if the user later elects to not commit the changes and wishes to 'undo' the changes made.)
  
  Upon commit, the database simply marks the relevant rollback segment header entry as committed. Now, when one of the changed blocks is revisited Oracle examines the header of the data block which indicates that it has been changed at some point. The database needs to confirm whether the change has been committed or whether it is currently uncommitted. To do this, Oracle determines the rollback segment used for the previous transaction (from the block's header) and then determines whether the rollback header indicates whether it has been committed or not.
  
  If it is found that the block is committed then the header of the data block is updated so that subsequent Accesses to the block do not incur this processing.
  
  This behaviour is illustrated in a very simplified way below. Here we walk through the stages involved in updating a data block.
  
  STAGE 1 - No changes made
  
  Description: This is the starting point. At the top of the data block we have an area used to link active transactions to a rollback segment (the 'tx' part),
and the rollback segment header has a table that stores information upon all the latest transactions that have used that rollback segment.
  
  In our example, we have two active transaction slots (01 and 02)and the next free slot is slot 03. (Since we are free to overwrite committed transactions.)
  
  Data Block 500       Rollback Segment Header 5
  +----+--------------+   +----------------------+---------+
   tx None         transaction entry 01 ACTIVE 
  +----+--------------+    transaction entry 02 ACTIVE 
   row 1           transaction entry 03 COMMITTED
   row 2           transaction entry 04 COMMITTED
   ... ..            ...   ...  ..  ...  
   row n           transaction entry nn COMMITTED
  +-------------------+    +--------------------------------+
  
  STAGE 2 - Row 2 is updated
  
  Description: We have now updated row 2 of block 500. Note that the data block header is updated to point to the rollback segment 5, transaction slot 3 (5.3) and that it is marked uncommitted (Active).
  
  Data Block 500       Rollback Segment Header 5
  +----+--------------+   +----------------------+---------+
   tx 5.3uncommitted-+  transaction entry 01 ACTIVE 
  +----+--------------+   transaction entry 02 ACTIVE 
   row 1       +--> transaction entry 03 ACTIVE 
   row 2 *changed*     transaction entry 04 COMMITTED
   ... ..            ...   ...  ..  ...  
   row n          transaction entry nn COMMITTED
  +------------------+   +--------------------------------+
  
  STAGE 3 - The user issues a commit
  
  Description: Next the user hits commit. Note that all that this does is it updates the rollback segment header's corresponding transaction slot as committed. It does *nothing* to the data block.
  
  Data Block 500          Rollback Segment Header 5
  +----+--------------+    +----------------------+---------+
   tx 5.3uncommitted--+   transaction entry 01 ACTIVE 
  +----+--------------+    transaction entry 02 ACTIVE 
   row 1        +---> transaction entry 03 COMMITTED
   row 2 *changed*      transaction entry 04 COMMITTED
   ... ..             ...   ...  ..  ...  
   row n           transaction entry nn COMMITTED
  +------------------+    +--------------------------------+
  
  STAGE 4 - Another user selects data block 500
  
  Description: Some time later another user (or the same user) revisits data block 500. We can see that there is an uncommitted change in the data block according to the data block's header.
  
  Oracle then uses the data block header to look up the corresponding rollback segment transaction table slot, sees that it has been committed, and changes data block 500 to reflect the true state of the datablock. (i.e. it performs delayed cleanout).
  
  Data Block 500          Rollback Segment Header 5
  +----+--------------+   +----------------------+---------+
   tx None         transaction entry 01 ACTIVE 
  +----+--------------+    transaction entry 02 ACTIVE 
   row 1           transaction entry 03 COMMITTED
   row 2           transaction entry 04 COMMITTED
   ... ..            ...   ...  ..  ... 
   row n           transaction entry nn COMMITTED
  +------------------+    +--------------------------------+
  
  ORA-01555 EXPlanation
  There are two fundamental causes of the error ORA-01555 that are a result of Oracle trying to attain a 'read consistent' image. These are :
  
  o The rollback information itself is overwritten so that Oracle is unable to rollback the (committed) transaction entries to attain a sufficiently old enough version of the block.
  
  o The transaction slot in the rollback segment's transaction table (stored in the rollback segment's header) is overwritten,
and Oracle cannot rollback the transaction header sufficiently to derive the original rollback segment transaction slot.
  
  Both of these situations are discussed below with the series of steps that cause the ORA-01555. In the steps, reference is made to 'QENV'. 'QENV' is short for 'Query Environment', which can be thought of as the environment that existed when a query is first star
上一篇:Oracle8i和9i中PLSQL程序的不同运行结果 人气:594
下一篇:动态SQL和PL/SQL的EXECUTE IMMEDIATE选项 人气:1245
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐