Use sys.sysprocesses to check for SQL Server blocking and deadlock _mssql

Source: Internet
Author: User
Tags session id rollback
MSDN: Contains information about processes that are running on an instance of SQL Server. These processes can be either client processes or system processes.

Main fields in the view:
1. Spid:sql Servr Session ID
2. Kpid:windows Thread ID
3. Blocked: The session ID that is blocking the plea. If this column is Null, the identity request is not blocked
4. waittype: The waiting resource number for the current connection, indicating whether to wait for the resource, or 0 or null to indicate that no resources need to wait
5. waittime: Current wait time, in milliseconds, 0 indicates no wait
6. DBID: Database ID currently being used by the process
7. UID: The user ID that executes the command
8. Login_time: The time the client process logs on to the server.
9. Last_batch: Time when the stored procedure or EXECUTE statement was last executed. For system processes, the startup time for SQL Server is stored
10.open_tran: Number of open transactions for the process. If there is a nested transaction, it will be greater than 1
11.Status: Process ID status, dormant = The reply is being reset; Running = reply is running one or more batches; Background = reply is running a background task; Rollback = The session is processing a transaction rollback; Pending = reply is waiting for work to become available; Runnable = The tasks in the session are in an executable queue that is waiting to get Scheduler to run; Spinloop = The task in session is waiting for the spin lock to become available; Suspended = Session is waiting for event to complete
12.Hostname: Name of the client workstation on which the link was established
13.program_name: The name of the application, which is the matching application name in the connection string
14.Hostprocess: The process ID number of the connected application in the client workstation
15.CMD: The currently executing command
16.Loginame: Login Name

application Example:

1. Check to see if the database has been blocked

First find out which link blocked field is not 0. The blocked field, such as SPID53, is not 0, but 52. The blocked of the SPID 52 is 0, and we can conclude that there is a blockage at this time and 53 is blocked by 52. If you find that the value of a connected blocked field is equal to its own, it means that the connection is doing disk reading and writing, and it has to wait for its I/O to finish.

2. Find links on that database

Check the dbid. Get dbid, you can run the following query to get the name of the database:
Select Name,dbid from Master.sys.sysdatabases
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.