深入解析ckpt

ckpt是checkpoint Process的简称,即检查点进程。

To ensure that the data blocks that have their redo generated up to a certain point in the redo log (RBA) are written to the disk

The CKPT process does not write blocks to disk, DBWn (DB Writer Process) always performs that task.

Oracle Database uses checkpoints to achieve the following goals:

  • Reduce the time required for recovery in case of an instance or media failure
  • Ensure that dirty buffers in the buffer cache are written to disk regularly
  • Ensure that all committed data is written to disk during a consistent shutdown 。

When does a checkpoint happen:

  • At each switch of the redo log files.
  • When the delay for LOG_CHECKPOINT_TIMEOUT is reached.
  • When the size in bytes corresponding to (LOG_CHECKPOINT_INTERVAL* size of IO OS blocks) is written on the current redo log file.
  • When ALTER SYSTEM SWITCH LOGFILE command is issued.
  • When ALTER SYSTEM CHECKPOINT command is issued.

检查点仅仅是一个机制而已,其作用是通知dbwn进程将cache buffer中的脏块写入到disk中,当然这个通知的动作是通过检查点进程CKPT来完成的。那么检查点存在的意义是什么呢?其实很简单,目的就是减少db crash后的recover time。

当修改数据时,需要首先将数据读入内存中(Buffer Cache),修改数据的同时,Oracle会记录重做信息(Redo)用于恢复。因为有了重做信息的存在,Oracle不需要在提交时立即将变化的数据写回磁盘(立即写的效率会很低),重做(Redo)的存在也正是为了在数据库崩溃之后,数据就可以恢复。
最常见的情况,数据库可以因为断电而Crash,那么内存中修改过的、尚未写入文件的数据将会丢失。在下一次数据库启动之后,Oracle可以通过重做日志(Redo)进行事务重演,也就是进行前滚,将数据库恢复到崩溃之前的状态,然后数据库可以打开提供使用,之后Oracle可以将未提交的数据进行回滚。
在这个过程中,通常大家最关心的是数据库要经历多久才能打开。也就是需要读取多少重做日志才能完成前滚。当然用户希望这个时间越短越好,Oracle也正是通过各种手段在不断优化这个过程,缩短恢复时间。检查点的存在就是为了缩短这个恢复时间。

这里可能存在一个误区,那就是并不是只有检查点的情况下才会导致dbwr进程去写脏块到disk中,在cache buffer 空间不足的情况下,由于Cache buffer LRU的机制就决定了不管是否发生检查点,dbwr都会将脏块写入到disk中,以此来保证cache buffer能容纳更多的new block(这里其实涉及到2个参数).

Checkpoint structure includes:

  • Checkpoint SCN
  • Checkpoint RBA
  • Thread that allocated the checkpoint
  • Enabled thread bitmap
  • Timestamp

Types of Checkpoints

  • Thread checkpoints

  • Tablespace and data file checkpoints

  • Incremental checkpoints

  • instance and media recovery checkpoints
  • Mini-checkpoint

 

此条目发表在Oracle分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注