Page LSNs and Recovery

简介:

Page LSNs and Recovery

Every database page has an LSN in the page header that reflects the location in the transaction log of the last log entry that modified a row on this page. Each log record for changes to a data page has two LSNs associated with it. In addition to the LSN for the actual log record, it also keeps track of the LSN which was on the data page before the change recorded by this log record. During a redo operation of transactions, the LSNs on each log record are compared to the page LSN of the data page that the log entry modified. If the page LSN is equal to the previous page LSN in the log record, the operation indicated in the log entry is redone. If the LSN on the page is equal to or higher than the actual LSN for this log record, SQL Server will skip the REDO operation. These two possibilities are illustrated in Figure 5-2. The LSN on the page cannot be in between the previous and current value for the log record.

数据库中存储的每一个page在其header中都有一个LSN,这个LSN用来标记最后修改这个page的log record,我们称它为page LSN。而每一个log record都有两个LSN,其中一个LSN就是log record当前的LSN,用来标识log record本身,我们叫他Actual LSN。而另外一个LSN是在这一次日志记录发生更改之前,data page上所记录的LSN,我们叫他Prev LSN

Redo操作与LSN比较

if(Page LSN==Prev LSN)
  redo operation
else if(Page LSN>=Actual LSN)
  skip redo operation

在我们执行redo操作的时候,如下图1所示,我们的事务日志中的一个log record需要更新page 1:25,该log record的actual LSN=2:210:6,prev LSN=2:200:7;而要修改的页page 1:25的header中我们发现Page LSN=2:200:7,则Page LSN==Prev LSN,那么表示我们可以执行当前LSN的log record的修改。

同理我们再来看图2,我们发现log record需要修改Page1:42,而该页中header存储的Page LSN=2:200:10,我们log record的actual LSN=2:290:6,那么Page LSN>Actual LSN,那么跳过这个修改操作。这是因为当前data page中的内容比我们要修改的内容更新,所以我们可以跳过当前log record的redo操作。

Figure 5-2. Comparing LSNs to decide whether to process the log entry during recovery

Because recovery finds the last checkpoint record in the log (plus transactions that were still active at the time of the checkpoint) and proceeds from there, recovery time is short, and all changes committed before the checkpoint can be purged from the log or archived. Otherwise, recovery could take a long time and transaction logs could become unreasonably large. A transaction log cannot be truncated prior to the point of the earliest transaction that is still open, no matter how many checkpoints have occurred since the transaction started and no matter how many other transactions have started or completed. If a transaction remains open, the log must be preserved because it's still not clear whether the transaction is done or ever will be done. The transaction might ultimately need to be rolled back or rolled forward.

 


本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2012/07/16/2593652.html,如需转载请自行联系原作者

目录
相关文章
|
缓存 Java 关系型数据库
关于page Cache和memory mappped Files 和zero copy
关于page Cache和memory mappped Files 和zero copy
140 0
关于page Cache和memory mappped Files 和zero copy
My FioriTest navigation from master page to detail page
Created by Wang, Jerry, last modified on Feb 16, 2015
101 0
My FioriTest navigation from master page to detail page
|
SQL 关系型数据库
ORA-1652: unable to extend temp segment by 128 in tablespace xxx Troubleshootin
当收到告警信息ORA-01652: unable to extend temp segment by 128 in tablespace xxxx 时,如何Troubleshooting ORA-1652这样的问题呢? 当然一般xxx是临时表空间,也有可能是用户表空间。
2050 0
|
关系型数据库 数据库管理 Oracle
|
SQL Oracle 关系型数据库
|
Oracle 关系型数据库 数据库
[20170209]理解pre_page_sga参数.txt
[20170209]理解pre_page_sga参数.txt --昨天测试pre_page_sga=true的情况: http://blog.itpub.net/267265/viewspace-2133198/ --//再次看看官方的定义: http://docs.
993 0
|
Oracle 关系型数据库 测试技术
[20170208]关于pre_page_sga参数.txt
[20170208]关于pre_page_sga参数.txt --//昨天晚上看链接: https://blogs.oracle.com/Database4CN/entry/%E5%85%B3%E4%BA%8Esys_cpu_usage_100_%E9%97%A...
938 0
|
关系型数据库
InnoDB: Error: space id and page n:o stored in the page?
2016-06-08 04:38:11 7fa7ddd86700  InnoDB: Error: space id and page n:o stored in the page InnoDB: read in are 4294967295:4294967295, ...
1903 0