LCK_M_SCH_M Wait Type in SQL Server

⏳Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: LCK_M_X, LCK_M_S, and LCK_M_U Wait TypesRelated pillar: Performance & Troubleshooting
⚡LCK_M_SCH_M is DDL waiting for a schema modification lock, and while it waits, new queries on the same table queue up behind it. Something still has the table open. Run the check to find the session in the way, then finish or kill it, or move the DDL to a quiet window.

LCK_M_SCH_M is a wait to acquire a Schema Modification (SCH-M) lock. DDL needs this lock to change an object’s structure: ALTER TABLE, offline index rebuilds, partition switches, truncates, and drops all take SCH-M. It is the least compatible lock in the engine; it conflicts with every other lock, including the Schema Stability locks that every running query holds.

This wait means your DDL is stuck. Something is still using the object, and the schema change cannot start until every last reader and writer lets go.


Is It a Problem?

Yes, while it lasts, because it hurts twice. First, the DDL is delayed. Second, and worse, while the SCH-M request queues it blocks every new query against the object, so a stuck ALTER TABLE quickly turns into an application-wide stall on that table. If LCK_M_SCH_M shows up in your top waits, deployments or maintenance are colliding with the workload.

Judge it over an interval rather than the cumulative totals. The baseline to monitor is its wait time per interval, lined up against your job and deployment schedule: time inside a maintenance window explains itself, and time outside one is worth chasing.


Common Causes

  • Running DDL while the application is active, with long-running queries or open transactions still holding locks on the object.
  • Index maintenance jobs overlapping business hours, especially offline rebuilds.
  • Partition switch or TRUNCATE TABLE steps in ETL waiting for readers to clear.
  • An idle session with an uncommitted transaction that touched the table hours ago.

The Check To Run

Rank it against everything else with Get Wait Statistics. When DDL is hanging right now, find the waiter and the session in its way. sys.dm_os_waiting_tasks shows both, and the LIKE also catches the _LOW_PRIORITY and _ABORT_BLOCKERS variants:

SELECT
    wt.session_id,
    wt.wait_type,
    wt.wait_duration_ms,
    wt.blocking_session_id,
    wt.resource_description,
    t.text AS waiting_sql
FROM sys.dm_os_waiting_tasks AS wt
JOIN sys.dm_exec_requests AS r ON r.session_id = wt.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE wt.wait_type LIKE 'LCK_M_SCH_M%'
ORDER BY wt.wait_duration_ms DESC;

blocking_session_id is the session in the way, objid in resource_description is the table, and mode= is the lock held against it. If the blocker is itself blocked, follow the chain to its head with Get Blocking Chains. If the head is a session sitting idle with a transaction open, Get Open Transactions shows how long it has been open. Both need VIEW SERVER STATE.


What To Do

  1. Kill or complete the blocker if it is an abandoned transaction; DBCC OPENTRAN in the database points at the oldest one, and killing the session rolls its open work back, which can take a while on a big transaction.
  2. Schedule DDL for quiet windows, and use ONLINE = ON where the edition allows. An online rebuild still takes a short shared lock at the start and a brief SCH-M at the end, so it can still queue behind a long transaction, but it does not hold the table for the whole rebuild.
  3. On SQL Server 2014 and later, use WAIT_AT_LOW_PRIORITY with ABORT_AFTER_WAIT so index operations and partition switches give up or remove blockers deliberately, instead of freezing the table for everyone. Those waits show as the LOW_PRIORITY and ABORT_BLOCKERS variants.
  4. Keep ETL steps that switch partitions or truncate tables away from long reports on the same tables, since both take SCH-M.

The LCK_M Family

Every lock mode has its own wait type, and the name says which lock the waiting session asked for. The check is the same for all of them: find the waiter, then follow blocking_session_id to the head of the chain.

  • LCK_M_X / S / URow and page locks. Exclusive, shared and update, the everyday blocking waits, with the full blocking walkthrough.The main lock waits page
  • LCK_M_SCH_SSchema stability. Every query needs it, so a queued SCH-M request stalls them all.Worth investigating
  • LCK_M_SCH_MSchema modification. DDL waiting for every user of the table to let go.Worth investigating. This page.
  • LCK_M_ISIntent shared. A reader cannot mark the table because a writer holds the whole of it.Worth investigating
  • LCK_M_IXIntent exclusive. A writer cannot mark the table, so modifications stall at table level.Worth investigating
  • LCK_M_SIXShared with intent exclusive. A transaction that reads the whole table and changes some of it; rare, so any amount stands out.Worth investigating
  • LCK_M_RS_SRange shared. Serializable reads locking key ranges; check whether that isolation level was chosen.Worth investigating
  • LCK_M_RS_URange update. A serializable search for rows it means to update.Worth investigating
  • LCK_M_RX_XRange exclusive. Serializable writes locking the gaps between keys, a common deadlock ingredient.Worth investigating
  • LCK_M_RIn_NLInsert range. A serializable insert waiting to lock the gap it lands in.Worth investigating
  • _LOW_PRIORITYLow priority variants. Index operations and partition switches waiting under WAIT_AT_LOW_PRIORITY.Usually the feature working

Frequently Asked Questions

Why does a waiting SCH-M lock block queries that only read?

Lock requests on an object queue in order. A new query needs a schema stability lock, which is compatible with the locks already granted but not with the SCH-M request waiting ahead of it, so it queues behind the DDL. Those queued queries show up as LCK_M_SCH_S.

Does ONLINE = ON stop LCK_M_SCH_M?

Not entirely. An online index rebuild needs a short lock at the start and a brief SCH-M in its final phase, and both wait for open write transactions on the table to finish. The difference is that the table stays usable for the rest of the rebuild.

What is LCK_M_SCH_M_LOW_PRIORITY?

The same lock requested with WAIT_AT_LOW_PRIORITY on ALTER INDEX or ALTER TABLE, from SQL Server 2014. The request waits without blocking others, and ABORT_AFTER_WAIT decides what happens when MAX_DURATION runs out: give up (SELF), kill the blockers (BLOCKERS), or carry on waiting normally (NONE).


Where To Go Next

If LCK_M_SCH_M is in your top waits or a deployment is hanging on it, these are the next places to look.

Comments

Leave a Reply

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