0

I understand sql server writes the updates to the data pages (making them dirty) in memory and writes the tlog onto the disk before sending the commit notification to the user.

This question is to ask in either of following scenarios:

  1. After flushing dirty pages from memory to disk
  2. Or after reboot post sql crash

How does the sql server know which dirty pages (data changes due to the recent set of tlogs) had been written to the disk or are yet to be written to disk?

3
  • Generically, it doesn't, nor does it really care. The DPT (dirty page table) will be re-created upon recovery. learn.microsoft.com/en-us/sql/relational-databases/… Commented Oct 4, 2022 at 17:20
  • But eventually it needs to write it to the data pages on the disk. I'm trying to understand how sql server knows which data pages are yet to be written to disk in the given scenarios.
    – variable
    Commented Oct 4, 2022 at 17:23
  • SQL Server follows the ARIES recovery protocol, like several other systems. It's a bit involved but well documented. Commented Oct 5, 2022 at 7:10

1 Answer 1

2

Ref:

As Sean Gallardy mentioned in the comment, SQL Server does not need to know which dirty pages are written to disk. SQL Server only needs to know which pages are dirty.

The key here is all dirty pages, it does not matter if the transaction is committed or not.

For performance reasons, the Database Engine performs modifications to database pages in memory, in the buffer cache, and doesn't write these pages to disk after every change. Rather, the Database Engine periodically issues a checkpoint on each database. A checkpoint writes the current in-memory modified pages (known as dirty pages) and transaction log information from memory to disk, and also records the information in the transaction log.

After a crash database boot page has the log sequence number of the last checkpoint. That is how SQL Server knows from where to start the crash recovery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.