MSQL_XP Wait Type in SQL Server

⏳Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: ASYNC_NETWORK_IO Wait TypeRelated pillar: Performance & Troubleshooting
⚡MSQL_XP is SQL Server waiting for an extended stored procedure, external DLL code, to finish. The wait lasts as long as the external code runs, so it tells you where the time went, not why. Run the check to catch which procedure is running and who called it.

Microsoft’s definition: a task waiting for an extended stored procedure to end. SQL Server also uses this wait state to detect potential MARS application deadlocks. Extended stored procedures are DLLs called through the old XP interface: xp_cmdshell, xp_fixeddrives, and add-ons from backup and monitoring vendors. It is recorded in preemptive mode, so the thread keeps running outside SQL Server’s scheduler until the procedure returns.


Is It a Problem?

The wait is honest accounting; the question is what it measures. Large totals mean a lot of time inside code SQL Server cannot see into. A procedure that hangs holds its worker until it returns, and there is little you can do about it from inside SQL Server. On our SQL Server 2025 lab it had about 3,700 waits and 28 seconds in a day,. Get Wait Statistics does not filter it out, so if it ranks, you will see it.

Judge it over an interval rather than the cumulative totals. The baseline to monitor is its average wait per call; a jump usually means the external work, or something it depends on, has slowed.


Common Causes

  • xp_cmdshell running slow external commands.
  • Backup or monitoring products implemented as extended procedures.
  • Older vendor integrations calling their own XP DLLs.
  • An external dependency that has stopped answering, such as a network share or a child process, holding the procedure open.

The Check To Run

Rank it against everything else with Get Wait Statistics. While it is happening, catch the session in the call:

SELECT
    r.session_id,
    r.wait_type,
    r.wait_time AS wait_ms,
    s.login_name,
    s.program_name,
    t.text AS running_sql
FROM sys.dm_exec_requests AS r
JOIN sys.dm_exec_sessions AS s ON s.session_id = r.session_id
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.wait_type LIKE N'MSQL_XP'
ORDER BY r.wait_time DESC;

To see which extended procedures are registered and which DLL each one lives in, list them from master; a DLL you do not recognise from the SQL Server install is the one to ask about:

SELECT
    o.name AS extended_procedure,
    p.dll_name
FROM master.sys.extended_procedures AS p
JOIN master.sys.all_objects AS o ON o.object_id = p.object_id
ORDER BY p.dll_name, o.name;

The first query needs VIEW SERVER STATE.


What To Do

  1. Find the procedure and the caller from the check, and time the external work it does; a hanging procedure usually traces back to a hanging dependency.
  2. Replace legacy XP use where you can: SQL Agent job steps, PowerShell or application-side services cover most of what they were used for, without loading foreign DLLs into SQL Server.
  3. For a vendor’s procedure, give the vendor the wait times and the calling statement; the fix is in their code.

The EXTERNAL Family

These waits are SQL Server waiting on code or servers outside itself: OLE DB providers, distributed queries and extended stored procedures. The time is spent in the external code. If one is near the top of your waits, read it next to the waits that usually matter.

  • OLEDBOLE DB calls. The duration of calls to the SQL Server OLE DB provider, for linked servers and some DBCC work.Worth a look when it climbs
  • MSQL_DQDistributed queries. Waiting for a distributed query operation to finish.Worth investigating
  • MSQL_XPExtended procedures. Waiting for an extended stored procedure to end.Worth a look when it climbs. This page.

Where To Go Next

If MSQL_XP is sitting near the top of your wait stats, these are the next places to look.

Comments

Leave a Reply

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