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
1 2 3 4 5 6 7 |
A Redo log thread is a set of operating system files in which an instance records all changes it makes - committed and uncommitted - to memory buffers containing datafile blocks. The redo log is organized into redo threads. The redo log of a single-instance (non-Parallel Server / RAC option) database consists of a single thread. A Parallel Server/Real Application Cluster redo log has a thread per instance. A thread checkpoint event guarantees that all pre-thread-checkpoint-SCN redo generated in that thread for all online datafiles has been written to disk. The database writes to disk all buffers modified by redo in a specific thread before Thread Checkpoint SCN. The set of thread checkpoints on all instances in a database is a database checkpoint. Thread checkpoints occur in the following situations: 1.Consistent database shutdown 2.ALTER SYSTEM CHECKPOINT statement 3.Online redo log switch 4.ALTER DATABASE BEGIN BACKUP statement. |
- Tablespace and data file checkpoints
1 |
The database writes to disk all buffers modified by redo before a specific target. A tablespace checkpoint is a set of data file checkpoints, one for each data file in the tablespace. These checkpoints occur in a variety of situations, including making a tablespace read-only or taking it offline normal, shrinking a data file, or executing ALTER TABLESPACE BEGIN BACKUP. |
- Incremental checkpoints
1 |
An incremental checkpoint is a type of thread checkpoint partly intended to avoid writing large numbers of blocks at online redo log switches. DBWn checks at least every three seconds to determine whether it has work to do. When DBWn writes dirty buffers, it advances the checkpoint position, causing CKPT to write the checkpoint position to the control file, but not to the data file headers. |
- instance and media recovery checkpoints
- Mini-checkpoint
1 |
table truncate/drop、user drop、direct path read |