DB2的日志理解难点

在DB2中最早的recovery时间点,是由minBuffLsn 和 lowTranLsn 的最小值决定的。

minBuffLsn: represents the oldest change to a page in the buffer pool that has not been written and persisted to disk yet.

lowTranLsn: represents the oldest active uncommitted transaction (specifically the LSN of the first log record it wrote).

在DB2和ORACLE数据库都还有一个约定,从buffer pool中写数据到磁盘之前其对应的redo log必须先从log buffer pool中写到磁盘中。

注意:这里的log buffer pool中的redo log没有要求是已经committed的。

所以,在数据库中,还没有被提交的数据被写到磁盘中是很正常的事情,只要这块数据所对应的redo log已经被写入到磁盘中,对于这个交易是否已经提交,不关紧要。

那么在recovery的时候就会出现这样的情况:

minBuffLsn < lowTranLsn : 有已经提交的交易(commit动作会触发数据库将对应的redo log写入到磁盘)数据还有没有被从buffer pool中写入到磁盘,所以recovery时从minBuffLsn对应的log开始,redo后面那些已经提交的或者未提交的交易,重建transaction table。

lowTranLsn > minBuffLsn : 有还没有提交的交易(但是redo log是已经写入到磁盘中的)的数据已经被写入到磁盘中,所以recovery时将从lowTranLsn对应的log开始,这部分数据已经被写入到磁盘中的redo log只是读取一下,创建transaction table。

这张图片做出了比较清晰的解释。

posted @ 2013-07-27 14:59  胡.杰  阅读(922)  评论(0编辑  收藏  举报