数据库切换日志的时候,为什么一定要发生检查点

数据库切换日志的时候,为什么一定要发生检查点,第1张

先写日志文件为保证数据库的可恢复性,日志文件能够用来进行事务故障恢复、系统故障恢复,并能够协助后备副本进行介质故障恢复。当数据库文件毁坏后,可重新装入后援副本把数据库恢复到转储结束时刻的正确状态,再利用建立的日志文件,可以把已完成的事务进行重做处理,而对于故障发生时尚未完成的事务则进行撤消处理,这样不用运行应用程序就可把数据库恢复到故障前某一时刻的正确状态。

CKPT is responsible for:

• Signaling DBWn at checkpoints

• Updating data file headers with

checkpoint information

• Updating control files with

checkpoint information

Background Processes and Recovery: Checkpoint (CKPT)

To understand instance recovery, you need to understand the functioning of certain background

processes.

Every three seconds (or more frequently), the CKPT process stores data in the control file to

document which modified data blocks DBWn has written from the SGA to disk. This is called a

“checkpoint.” The purpose of a checkpoint is to identify that place in the online redo log file

where instance recovery is to begin (which is called the “checkpoint position”).

In the event of a log switch, the CKPT process also writes this checkpoint information to the

headers of data files.

Checkpoints exist for the following reasons:

• To ensure that modified data blocks in memory are written to the disk regularly so that data

is not lost in case of a system or database failure

• To reduce the time required for instance recovery. Only the online redo log file entries

following the last checkpoint need to be processed for recovery.

• To ensure that all committed data has been written to data files during shutdown

The checkpoint information written by the CKPT process includes checkpoint position, system

change number, location in the online redo log file to begin recovery, information about logs,

and so on.

ORACLE CHECKPOINT的作用

checkpoint是一个数据库事件,它将已修改的数据从高速缓存刷新到磁盘,并更新控制文件和数据文件。

我们知道了checkpoint会刷新脏数据,但什么时候会发生checkpoint呢?以下几种情况会触发checkpoint。

1.当发生日志组切换的时候

2.当符合LOG_CHECKPOINT_TIMEOUT,LOG_CHECKPOINT_INTERVAL,fast_start_io_target,fast_start_mttr_target参数设置的时候

3.当运行ALTER SYSTEM SWITCH LOGFILE的时候

4.当运行ALTER SYSTEM CHECKPOINT的时候

5.当运行alter tablespace XXX begin backup,end backup的时候

6.当运行alter tablespace ,datafile offline的时候

你再好好看看文档吧

当我们进行redo 切换的时候,会触发checkpoint 事件。 触发该事件有5个条件。 下文有说明。 Checkpoint做的事情之一是触发DBWn把buffer cache中的Dirty cache磁盘。另外就是把最近的系统的SCN更新到datafile header和control file(每一个事务都有一个SCN),做第一件事的目的是为了减少由于系统突然宕机而需要的恢复时间,做第二件事实为了保证数据库的一致性。

Checkpoint will flush dirty block to datafile, 从而触发DBWn书写dirty buffer,等到redo log覆盖的dirty block全部被写入datafile后才能使用redo log(循环使用),如果DBWn写入过慢,LGWR必须等待DBWn完成,则这时会出现“checkpoint not completed!”。 所以当出现checkpointnot competed的时候,还会伴随cannot allocate new log的错误。

如果遇到这个问题,可以增加日志组和增大日志文件,当然也可以修改 checkpoint参数使得检查点变频繁一些。

在出现这个错误的时候,数据库是短暂hang住的,等待checkpoint的完成。 在hang住的时候,没有日志产生。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/sjk/6665152.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存