DOES LAZY WRITER OVERRIDES WRITE AHEAD LOGGING MECHANISM?

Subbarao DBA 21 Reputation points
2022-06-05T01:45:30.663+00:00

I READ THAT LAZY WRITER DOES NOT MAKE ANY ENTRY IN LOG, BUT FLUSHES DIRTY PAGES TO DISK, SO IF SERVER SHUTDOWNS IN BETWEEN A LAZYWRITE AND NEXT CHECKPOINT, THE LOG CACHE DATA LOST, BUT DIRTY DATA ALREADY WRITTEN TO DISK BUT CORRESPONDING LOG IS LOST, DURING RECOVERY HOW THE DATA IS VALID? IT MAY BE OUT OF SYNC WITH LOG

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,757 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,554 questions
0 comments No comments
{count} votes

Accepted answer
  1. YufeiShao-msft 7,056 Reputation points
    2022-06-06T07:02:23.28+00:00

    Hi @Subbarao DBA ,

    Regardless of the recovery mode, SQL Server will scan the log to the last checkpoint during crash recovery, rolls forward all data changes at that point, and then rolls back uncommitted transactions.

    According to the official doc:SQL Server Transaction Log Architecture and Management Guide

    SQL Server has logic that prevents a dirty page from being flushed before the associated log record is written

    Write ahead logging will guarantee that no data modifications are written to disk before the associated log record is written to disk. All data modifications are first written to the log, and then dirty pages written afterward

    https://dba.stackexchange.com/questions/287463/how-does-recovery-work-when-server-is-shutdown-before-a-checkpoint
    https://www.sqlshack.com/sql-server-checkpoint-lazy-writer-eager-writer-and-dirty-pages-in-sql-server/

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 101.4K Reputation points MVP
    2022-06-05T12:00:17.187+00:00

    If that happens, the pages will be undone to their earlier state. Note that these pages will always be for uncommitted transactions.

    0 comments No comments