What are the Different Types of SQL Server CHECKPOINT? – Interview Question of the Week #230

Question: What are SQL Server’s checkpoint types? Automatic, indirect, manual and internal checkpoints.

Completed ceramic tiles are filed in a cabinet beside a tray awaiting storage

A checkpoint writes modified data pages and recovery information, so the engine has a known starting point for crash recovery. It doesn’t commit an open transaction, remove all cached pages or replace a backup.

TypeWhat initiates itConfiguration or command
AutomaticThe engine estimates work required for recovery and issues checkpoints in the background.Server recovery interval, expressed in minutes, applies when database target recovery time is 0.
IndirectA background writer manages dirty pages against the database’s recovery-time target.ALTER DATABASE … SET TARGET_RECOVERY_TIME.
ManualAn authorized user issues CHECKPOINT in the current database.CHECKPOINT, optionally with checkpoint_duration.
InternalEngine operations such as a database backup, snapshot creation or orderly shutdown require a checkpoint.No separate command to select this internal category.

These targets concern recovery time, not a timer that guarantees a checkpoint every specified number of seconds. New databases from SQL Server 2016 normally use a 60-second indirect target. A restored or upgraded database can keep its earlier setting, so inspect it.

-- Read-only inspection.
SELECT name, target_recovery_time_in_seconds
FROM sys.databases
WHERE database_id = DB_ID();
SELECT name, value_in_use
FROM sys.configurations
WHERE name = N'recovery interval (min)';

-- Syntax examples only. Do not run these to answer the interview question.
-- A reviewed server-level change also requires enabling advanced options
-- if necessary and applying RECONFIGURE.
-- EXEC sys.sp_configure N'recovery interval (min)', 1;
-- RECONFIGURE;
-- ALTER DATABASE CURRENT SET TARGET_RECOVERY_TIME = 60 SECONDS;
-- CHECKPOINT;

The first two queries only read the current settings. The commented statements show the configuration and manual syntax without silently changing your instance. A server configuration change needs the appropriate permission, advanced-option handling and RECONFIGURE; it’s a separate administrative decision.

Writing pages costs I/O. A more aggressive recovery target isn’t automatically a performance improvement. Understand storage capacity and recovery requirements before changing it.

Checkpoints: Four checkpoint types

A checkpoint is not a commit, it is a bookmark for recovery, and four different triggers can write it.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Previous Post
How Dirty or Clean is SQL SERVER’s Memory? – Interview Question of the Week #229
Next Post
What is Faster, SUM or COUNT? – Interview Question of the Week #231

Related Posts

No results found.

2 Comments. Leave new

  • ROSHAN KUMAR SHAH
    August 9, 2023 11:03 am

    Hi Pinal,

    Roshan here from Invia Pvt Ltd.

    It seems that there might be one error in the blog. Thanks for the Comprehensive Database health check that you performed for us in the last month.

    The unit of ‘recovery interval’ is minute.
    But, you have mentioned seconds in the blog.

    Request you to cross check it and rectify if needed.

    Reply
    • Thanks Roshan,

      You are very correct and I appreciate it. I have made the necessary adjustment to the blog post.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.