SQL Server2012新功能 间接checkpoints

 SQL Server2012新功能 间接checkpoints  

https://msdn.microsoft.com/en-us/library/hh403416.aspx
https://learn.microsoft.com/zh-cn/sql/relational-databases/logs/database-checkpoints-sql-server?view=sql-server-ver16&redirectedfrom=MSDN

在系统崩溃后恢复给定数据库所需的时间主要取决于redo重做崩溃时的脏页所需的随机 I/O 量。

这意味着 recovery interval 设置不可靠。 它无法确定准确的恢复recovery时间。
注意:recovery interval和target_recovery_time是一个估计值,假设设置为1分钟,不是说recovery时间就是1分钟!!


target_recovery_time和recovery interval的优先级
target_recovery_time | recovery interval | 使用的检查点类型
---------------------|---------------------|--------------------------------------------------
0                    | 0                   | 目标恢复间隔为 1 分钟的自动检查点。
0                    | > 0                 | 自动检查点,其目标恢复间隔由“sp_configure 'recovery interval'”选项的用户定义的设置指定。
> 0                  | 不适用              | 间接检查点,其目标恢复时间由 TARGET_RECOVERY_TIME 设置确定,以秒为单位。





根据Aries的数据库恢复机制,检查点只能大概控制crash recovery的redo阶段,undo阶段无办法控制,一个大事务依然会导致DB要recovery很长时间
Aries是一种广泛应用的恢复算法,全称是"Algorithm for Recovery and Isolation Exploiting Semantics"。
Fuzzy Checkpoint比起Consistent Checkpoint更灵活

Fuzzy Checkpoint
Rec LSN:对于一个 Page,自从上一次刷盘以来,第一次更新操作对应的 Log 的 LSN,变为脏页的lsn。
Last LSN:每个事务最近一次更新操作对应的 Log 的 LSN。
DPT:全称是 Dirty Page Table。记录了所有的 Dirty Page 以及它们的 Rec LSN。它是一个内存中的数据结构。
ATT:全称是 Active Transaction Table。记录了所有活跃事务(事务在执行中,还没有提交或回滚)以及它们的状态(Undo Candidate,Committed)和 Last LSN。它也是内存中的一个数据结构。​
Redo 的起始位置在 Checkpoint Log 之前(DPT 中最小的 Rec LSN),在没有IO压力的情况下支持更频繁的做checkpoint

checkpoint的意义



只有下面两个参数可以给用户设置,两个参数的原理一样,只是范围不一样
recovery interval(实例级)
数据库引擎将估计它在恢复间隔内可以处理的最多事务日志记录数。
当数据库引擎估计脏页数量达到一定数量的时候,这个数量是指recovery interval指定时间内的脏页数量,通过脏页数量衡量修改量是最准确的,有多少脏页就产生多少wal日志(而不是通过DML量或者事务量,特别有些DML对同一个页修改好几次),数据库引擎会在数据库上发出一个checkpoint。
SQL Server 在发生故障恢复时所需的大概恢复时间长度。
默认值: 1 分钟(单位:秒)
命令:EXEC sp_configure 'recovery interval', '60'





indirect checkpoint(数据库级)
间接检查点是 SQL Server 2012 引入的一种新的检查点策略,原理跟recovery interval一样,只是提供了数据库级别控制。
在设置间接检查点之前,要衡量好RTO要求和磁盘IO压力,太频繁checkpoint会造成IO压力
通过为每个数据库设置 target_recovery_time(目标恢复时间)
默认值: 1 分钟(单位:秒或分钟)
命令:ALTER DATABASE AdventureWorks2012 SET TARGET_RECOVERY_TIME = 60 SECONDS;


 


 checkpoint刷盘遇到IO压力

https://blogs.msdn.microsoft.com/psssql/2012/06/01/how-it-works-when-is-the-flushcache-message-added-to-sql-server-error-log/

flushcache就是SQLSERVER的checkpoint操作,在sql2012开始可以通过打开跟踪标志(3502和3504)查看checkpoint操作的IO吞吐量
Is Long Checkpoint就是当上一个周期的checkpoint还没执行完,下一个周期的checkpoint发现上一个周期的checkpoint还没执行完,而把flushcache-message日志打印到errorlog里
表示磁盘IO不给力,还未flush完数据到磁盘

FlushCache is the SQL Server routine that performs the checkpoint operation.  The following message is output to the SQL Server error log when trace flag (3504) is enabled.

    2012-05-30 02:01:56.31 spid14s     FlushCache: cleaned up 216539 bufs with 154471 writes in 69071 ms (avoided 11796 new dirty bufs) for db 6:0

    2012-05-30 02:01:56.31 spid14s                 average throughput:  24.49 MB/sec, I/O saturation: 68365, context switches 80348
    2012-05-30 02:01:56.31 spid14s                 last target outstanding: 1560, avgWriteLatency 15

Prior to SQL Server 2012 the trace flag had to be enabled in order to output the information to the SQL Server error log. (Trace flag was the only way to obtain the output.)

 

SQL Server 2012 adds an additional condition (is long checkpoint) to the logic. If the trace flag is enabled or the checkpoint ‘TRUE == IsLong’ the message is added to the SQL Server error log.
 
Is Long Checkpoint: A long checkpoint is defined as a ‘FlushCache / checkpoint’ operation on a database that has exceeded the configured recovery interval.
 
If your server does not have the trace flag enabled (use dbcc tracestatus(-1) to check) the message is indicating that the checkpoint process, for the indicated database, exceeded the configured recovery interval. If this is the case you should review your I/O capabilities as well as the checkpoint and recovery interval targets.
 
Not meeting the recovery interval target means that recovery from a crash could exceeded operational goals.

Bob Dorr – Principal SQL Server Escalation Engineer
<footer >
Tags 2008 2008 R2 Denali Engine How It Works SQL 2008 SQL 2012 SQL Denali SQL Server 2008 SQL Server 2008 R2 Troubleshooting: The DB Engine
</footer>

 

关于216539 bufs
FlushCache: cleaned up 216539 bufs  ,一个bufs代表一个页面,刷新了216539个页面到磁盘

 

 

参考文章:

https://zhuanlan.zhihu.com/p/455122515?utm_id=0

posted @ 2015-11-15 09:02  桦仔  阅读(2067)  评论(0编辑  收藏  举报