LOGMGR Wait Type in SQL Server

LOGMGR is a wait that occurs when a database is being closed and a thread has to wait for all outstanding transaction log I/O to complete before the log can be shut down. Databases close during instance shutdown, when a database is taken offline or detached, and when the AUTO_CLOSE option closes an idle database.

Do not confuse it with LOGMGR_QUEUE, which is the log writer thread idling and is completely benign. Plain LOGMGR is about closing the log down cleanly.

Is It a Problem?

Almost never in a steady-state wait profile, because databases are not usually closing during normal operation. Where it can bite is in two situations. First, slow shutdowns or offline/detach operations that hang while in-flight log writes drain to slow storage. Second, databases with AUTO_CLOSE ON cycling open and closed repeatedly, paying this cost over and over.

If LOGMGR accumulates on a production instance, ask why databases are closing at all.

Common Causes

  • AUTO_CLOSE ON, common on databases restored from Express-edition or vendor-supplied backups, causing constant close/open cycles.
  • Taking databases offline, detaching them, or shutting the instance down while a heavy write workload still has log I/O in flight.
  • Slow log-drive storage stretching out the final flush during a close.

What To Do

  1. Check for auto-close: SELECT name FROM sys.databases WHERE is_auto_close_on = 1; and turn it off on anything a user or application touches: ALTER DATABASE [db] SET AUTO_CLOSE OFF;.
  2. If shutdowns or offlines hang, look at log write latency in sys.dm_io_virtual_file_stats before blaming the engine; the close is waiting on the same slow disk your commits are.
  3. Quiesce write activity before planned detach or offline operations so there is little log left to drain.

How To See It

Rank it against everything else with Get-WaitStatistics. If LOGMGR registers meaningfully, correlate it with database state changes in the error log rather than treating it as a workload wait.


Part of the SQL Server Wait Types Library.
Related deep dive: WRITELOG Wait Type.

Comments

Leave a Reply

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