SQL SERVER 事务日志
谈到事务日志就不得不谈下检查点 Checkpoint ,简称 CKP. 事务日志和检查点都是为了数据库的快速恢复而存在的。我们需要知道检查点是干什么的,它和事务日志有什么关系。 CKP是干什么的? 总所周知,数据的更改并没有直接写入mdf/ndf 数据文件中,而是写入了b
谈到事务日志就不得不谈下检查点 Checkpoint ,简称 CKP. 事务日志和检查点都是为了数据库的快速恢复而存在的。我们需要知道检查点是干什么的,它和事务日志有什么关系。
CKP是干什么的?
总所周知,数据的更改并没有直接写入mdf/ndf 数据文件中,而是写入了buffer pool中; 当CKP被触发后,检查点将“全部”脏数据页从当前数据库的buffer pool刷新到数据文件上。所谓的脏数据,是那些被更改的 data page ,在内存中却没有写入磁盘。全部脏数据包括已提交的数据更改和未提交的数据更改。刷新到数据文件是指将数据更改的后镜像copy写入数据文件,对数据的更改会保留一个前镜像和一个后镜像,好比我们修改文章,先保存原文作为前镜像,而后将修改后的文章作为后镜像。同时CKP也会flush cached log 到日志文件中 点击打开链接 .我更愿意将CKP看作是一个闹钟,我们可以对它按照一个规则定时,然后提醒SQL的部件data writer / log writer去干活。
总之,大多数情况下,什么时候数据更改写入数据文件,是由CKP决定的。
CKP什么时候被触发
备份数据库 (全备,差异备份,日志备份)
checkpoint命令
关闭数据库
Alter database命令
自动的检查点触发 (SQL依据recovery interval 服务器配置选项建议的时间上限触发检查点 或者日志已满 70%触发检查点)
间接检查点 (SQL 2012 新特性 ,详情参与点击打开链接)
CKP, Lazywriter, Eagerwriter的区别
总所周知这三个SQL的process都会将脏数据写入数据文件,但是它们的目的和触发条件完全不同
CKP的使用目的是为了在SQL intance停止后(例如断电),快速的instance recovery。它是一个时间点的标记,标记了数据库恢复的起始点。在这个起始点,所有的脏数据copy都写入了磁盘(它不会释放内存空间),从而在以后的恢复过程中节省时间。
Lazy writer是为了更好的利用buffer pool。 它会定期检查data cache,按照LRU算法,将长期未使用到的dirty page 写入磁盘, 清除dirty page释放内存空间。
Eager writer 是为BCP等批量插入而存在的。该进程会写入与无日志记录的操作(例如大容量插入和选择插入)相关联的脏数据页。该进程允许以并行方式创建和写入新页。也就是说,调用操作不必等待整个操作完成,即可将页写入磁盘 (摘于msdn点击打开链接 )。这样可以保证Buffer Pool有足够的空间完成批量操作。
CKP和事务日志有什么关系呢?
与其说是与事务日志的关系,不如说是与事务日志序列号(Log Sequence Number, 简称LSN)的关系,,在我以后的blog会对LSN做阐述。
检查点触发有一个起始时间点,这个时间点会被记录在事务日志里,获得一个CKP起始时间点LSN。当完成脏数据写后,CKP同样在日志文件里记录一个结束时间点的LSN。检查点还会记录一个最小恢复LSN (minLSN), minLSN必须存在检查点记录里才能成功进行回滚(roll back / undo), minLSN告诉了SQL Server 可以回滚的最远时间点。至于minLSN是什么,SQL如何定义minLSN,SQL server如何使用它,在我以后的blog做阐述)这里只要记住CKP会纪录这个minLSN,它很对undo很重要。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The logs of win10 can help users understand the system usage in detail. Many users must have encountered log 6013 when looking for their own management logs. So what does this code mean? Let’s introduce it below. What is win10 log 6013: 1. This is a normal log. The information in this log does not mean that your computer has been restarted, but it indicates how long the system has been running since the last startup. This log will appear once every day at 12 o'clock sharp. How to check how long the system has been running? You can enter systeminfo in cmd. There is one line in it.

The logs of win10 can help users understand the system usage in detail. Many users must have seen a lot of error logs when looking for their own management logs. So how to solve them? Let’s take a look below. . How to solve win10 log event 7034: 1. Click "Start" to open "Control Panel" 2. Find "Administrative Tools" 3. Click "Services" 4. Find HDZBCommServiceForV2.0, right-click "Stop Service" and change it to "Manual Start "

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

Lockwaittimeoutexceeded;tryrestartingtransaction - How to solve the MySQL error: transaction wait timeout. When using the MySQL database, you may sometimes encounter a common error: Lockwaittimeoutexceeded;tryrestartingtransaction. This error indicates that the transaction wait timeout. This error usually occurs when

In Linux systems, you can use the following command to view the contents of the log file: tail command: The tail command is used to display the content at the end of the log file. It is a common command to view the latest log information. tail [option] [file name] Commonly used options include: -n: Specify the number of lines to be displayed, the default is 10 lines. -f: Monitor the file content in real time and automatically display the new content when the file is updated. Example: tail-n20logfile.txt#Display the last 20 lines of the logfile.txt file tail-flogfile.txt#Monitor the updated content of the logfile.txt file in real time head command: The head command is used to display the beginning of the log file

MySQL transaction processing: the difference between automatic submission and manual submission. In the MySQL database, a transaction is a set of SQL statements. Either all executions are successful or all executions fail, ensuring the consistency and integrity of the data. In MySQL, transactions can be divided into automatic submission and manual submission. The difference lies in the timing of transaction submission and the scope of control over the transaction. The following will introduce the difference between automatic submission and manual submission in detail, and give specific code examples to illustrate. 1. Automatically submit in MySQL, if it is not displayed

iPhone lets you add medications to the Health app to track and manage the medications, vitamins and supplements you take every day. You can then log medications you've taken or skipped when you receive a notification on your device. After you log your medications, you can see how often you took or skipped them to help you track your health. In this post, we will guide you to view the log history of selected medications in the Health app on iPhone. A short guide on how to view your medication log history in the Health App: Go to the Health App>Browse>Medications>Medications>Select a Medication>Options&a

On the occasion of releasing the build 26040 version of Windows Server, Microsoft announced the official name of the product: Windows Server 2025. Also launched is the Windows11WindowsInsiderCanaryChannel version build26040. Some friends may still remember that many years ago someone successfully converted Windows NT from workstation mode to server mode, showing the commonalities between various versions of Microsoft operating systems. Although there are clear differences between Microsoft's current version of the server operating system and Windows 11, those who pay attention to the details may be curious: why Windows Server updated the brand,
