SQL SERVER – Identify Oldest Active Transaction with DBCC OPENTRAN

DBCC OPENTRAN is the quickest way to find the oldest active transaction in a database. I recently received a question on my Facebook page-

SQL SERVER - Identify Oldest Active Transaction with DBCC OPENTRAN

“Pinal,

How do I know if there is any open transaction in my database? I recently wanted to restart my server, but my manager asked me to first check if there is any open transaction in database before I restart the system.”

Very interesting question. The answer is very simple.

You can execute the following script to see if there is any open transaction. First run following script on any of your development server.

BEGIN TRAN
UPDATE Person.Address
SET AddressLine2 = ''
WHERE AddressID = 112

Now open another connection in MySQL and execute following script.

DBCC OPENTRAN

Above DBCC will return following output where it will return the details for the oldest active transaction. For example, here is the sample output in my system.

Transaction information for database 'AdventureWorks2012'.
Oldest active transaction:
 SPID (server process ID): 57
 UID (user ID) : -1
 Name : user_transaction
 LSN : (163:324:1)
 Start time : Jan 16 2014 4:34:58:813PM
 SID : 0x0105000000000005150000001650720d0cca921474e68766e8030000
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

If you are looking for a script where you can get details for all the transactions with text and plan, here is the excellent script from SQLskills team, I use it all the time when I have to work with Active Transactions.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL Transactions
Previous Post
Personal Technology – Inserting Image in PDF File with Adobe Acrobat X Pro
Next Post
Checking Data Type Mapping After a Database Migration

Related Posts

5 Comments. Leave new

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.