Latches vs Locks in SQL Server: The Difference That Trips Up Even Experienced DBAs

Latches vs Locks in SQL Server: The Difference That Trips Up Even Experienced DBAs

Both sound like “something is blocking something.” They protect completely different things, and misdiagnosing one as the other sends you fixing the wrong problem.

Locks vs latches: not the same fight(logical vs physical)LOCKSprotect LOGICAL data consistencyheld for the WHOLE transactionwait type: LCK_M_*LATCHESprotect PHYSICAL memory pagesheld for MICROSECONDSwait: PAGELATCH_*/PAGEIOLATCH_*VSThe most common latch-contention patternS1S2S3S4S5LAST PAGEIDENTITY columninsert herePAGELATCH_EX pileupCommon mistake: seeing PAGELATCH_EX andreaching for the LOCK playbook (shorter txns,isolation level) is the wrong fix. Latches needdifferent medicine: more files, hash keys. 📌

Two Different Jobs

Locks Protect LOGICAL data consistency Held for transaction duration Wait type: LCK_M_* Latches Protect PHYSICAL in-memory pages Held for microseconds, not transaction duration Wait type: PAGELATCH_*/PAGEIOLATCH_*

Why the Distinction Matters in Practice

A DBA seeing high PAGELATCH_EX waits and reaching for the usual lock-blocking playbook (shorten transactions, change isolation level) is solving the wrong problem — latch contention is about physical memory structure access, not logical transaction isolation. It needs a completely different fix.

-- Distinguish the two directly from current waits
SELECT wait_type, COUNT(*) AS waiting_now
FROM sys.dm_os_waiting_tasks
WHERE wait_type LIKE 'LCK%' OR wait_type LIKE '%LATCH%'
GROUP BY wait_type;

The Most Common Latch Contention Pattern

PAGELATCH_EX waits on the last page of a table with an ever-increasing key (like an IDENTITY column) under very high concurrent insert load is the single most common latch contention scenario — every session is racing to insert into the same physical page. This exact pattern sets up the tempdb contention lesson next, which is the same underlying phenomenon at a system-table level.


Enjoyed this?

Subscribe to get every new lesson as soon as it’s published, and share it with a developer who’d find it useful.

📡 Subscribe via RSS  | 
Share on X  | 
Share on LinkedIn  | 
Share on Facebook

Want the full structured course with quizzes and hands-on labs? Check out SQL Server Performance Tuning, coming soon on this site.