Checkpoint Process in SQL Server - An Insight into it








Are you trying to know more about Checkpoint process in SQL server ?

This guide is for you.

Checkpoint is a process that writes current in-memory dirty pages (modified pages) and transaction log records to physical disk.
In SQL Server checkpoints are used to reduce the time required for recovery in the event of system failure.
Basically, When the SQL database server faces an unexpected shutdown or crash, the checkpoint creates a known good point from which the SQL Server Database Engine can start applying changes contained in the log during recovery.
Checkpoint is regularly issued for each database.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to handle SQL database servers.
In this context, we shall look into the different types of Checkpoint process in SQL server.

Operations that triggers when checkpoint occurs ?

The following set of operations starts when checkpoint occurs:
1. Log records from log buffer (including the last log record) are written to the disk.
2. All dirty data file pages (pages that have been modified since the last checkpoint or since they were read from disk) are written into the data file from the buffer cache.
3. Checkpoint LSN is recorded in the database boot page.

Types of Checkpoint process in SQL server ?

SQL Server performs many modifications to any database pages in memory/buffer cache. It will not write these modified pages to disk after every change.

Rather, SQL Server Database Engine periodically issues a checkpoint on each database.
A checkpoint writes the current in-memory modified pages (known as dirty pages). After that, it transactions log information from memory to disk along with recording the information in the transaction log.
Using a better checkpoint method will enhance the server performance along with rendering a better recovery plan.

SQL Server supports four types of checkpoints.

They are given below:
1. Automatic Checkpoints
2. Indirect Checkpoints
3. Manual Checkpoints
4. Internal Checkpoints

Now we will look into each type of checkpoint in detail.

1. Automatic Checkpoints

An automatic checkpoint occurs each time the number of log records reaches the number the Database Engine estimates it can process during the time specified in the recovery interval server configuration option.
We can set the value of recovery interval using the following:

sp_configure 'recovery interval','seconds'

The recovery interval is the maximum time that a server instance should use to recover a database during a system restart.
When a database using automatic checkpoints reaches this maximum number of log records, the Database Engine issues a checkpoint on the database.
The frequency depends on the value of the recovery interval option of server configuration.
Database Engine generates automatic checkpoints for every database when we don't define a value for target recovery time for a database. Usually, in a simple recovery model, an automatic checkpoint is queued if the log becomes 70 percent full.

2. Indirect Checkpoints

This checkpoint was introduced in SQL Server 2012. Indirect checkpoints provide a configurable database-level alternative to automatic checkpoints.
When a system crash, indirect checkpoints provide potentially faster, more predictable recovery time than automatic checkpoints.
We can set the TARGET_RECOVERY_TIME in the Indirect checkpoint for any database using the following ALTER DATABASE statement:

ALTER DATABASE DBNAME SET TARGET_RECOVERY_TIME =target_recovery_time {SECONDS | MINUTES}

Here the recovery interval configuration option uses the number of transactions to determine the recovery time as opposed to indirect checkpoints which make use of the number of dirty pages.
Indirect checkpoints allow us to reliably control database recovery time by factoring in the cost of random I/O during REDO.
It also reduces checkpoint-related I/O spiking by continuously writing dirty pages to disk in the background.


3. Manual Checkpoints

The manual checkpoint is issued when we execute a T-SQL CHECKPOINT command for a database. By default, manual checkpoints run to completion and its Throttling works the same way as that of automatic checkpoints.

4. Internal Checkpoints

Internal Checkpoints are generated by various server components to guarantee that disk images match the current state of the log.
They generate in response to the following events:
1. Adding or removing database files using ALTER DATABASE.
2. Backup of the database is taken
3. Creating a database snapshot, either explicitly or internally for DBCC CHECK.
4. Any activities leading to database shutdown.
5. An instance of SQL Server stops by stopping the SQL Server (MSSQLSERVER) service. Either action causes a checkpoint in each database in the instance of SQL Server.
6. Bringing a SQL Server failover cluster instance (FCI) offline.

[Need urgent assistance with your SQL server? – We can help you. ]



Conclusion

This article covers the Checkpoint process in SQL server and the four types of checkpoints available.
Checkpoints are the useful repositories of information and serve best for the recovery of SQL server databases.

Different Types of Checkpoint in #SQL:
1. Automatic Checkpoint
An automatic checkpoint is the most common type that is triggered by a background process. Server Configuration Option “Recovery Interval” is used by the SQL Server Database Engine to determine how often automatic checkpoints are issued on a given database.
2. Indirect Checkpoint
A new type of #checkpoint introduced in SQL Server 2012 is an Indirect checkpoint. Indirect checkpoint also runs in the background, but it meets user-specified target recovery time for a given database.
3. Manual Checkpoint
Manual checkpoint runs like any other Transact-SQL command. It runs to completion by default. This type of checkpoint occurs in the current database only. It is also possible to set the time frame in which you want your checkpoint completed.
4. Internal Checkpoint
The fourth type is Internal checkpoint that cannot be controlled by user.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com