谈到事务日志就不得不谈下检查点 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很重要。

MySQL processes data replication through three modes: asynchronous, semi-synchronous and group replication. 1) Asynchronous replication performance is high but data may be lost. 2) Semi-synchronous replication improves data security but increases latency. 3) Group replication supports multi-master replication and failover, suitable for high availability requirements.

The EXPLAIN statement can be used to analyze and improve SQL query performance. 1. Execute the EXPLAIN statement to view the query plan. 2. Analyze the output results, pay attention to access type, index usage and JOIN order. 3. Create or adjust indexes based on the analysis results, optimize JOIN operations, and avoid full table scanning to improve query efficiency.

Using mysqldump for logical backup and MySQLEnterpriseBackup for hot backup are effective ways to back up MySQL databases. 1. Use mysqldump to back up the database: mysqldump-uroot-pmydatabase>mydatabase_backup.sql. 2. Use MySQLEnterpriseBackup for hot backup: mysqlbackup--user=root-password=password--backup-dir=/path/to/backupbackup. When recovering, use the corresponding life

The main reasons for slow MySQL query include missing or improper use of indexes, query complexity, excessive data volume and insufficient hardware resources. Optimization suggestions include: 1. Create appropriate indexes; 2. Optimize query statements; 3. Use table partitioning technology; 4. Appropriately upgrade hardware.

MySQL view is a virtual table based on SQL query results and does not store data. 1) Views simplify complex queries, 2) Enhance data security, and 3) Maintain data consistency. Views are stored queries in databases that can be used like tables, but data is generated dynamically.

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
