0

When I run this query

SELECT transaction_id, name, transaction_begin_time, transaction_state 
FROM sys.dm_tran_active_transactions

I always have these 6 rows in the result set

transaction_id name transaction_begin_time transaction_state
496 worktable 29/10/2024 00:11:56 2
499 worktable 29/10/2024 00:11:56 2
501 worktable 29/10/2024 00:11:56 2
503 worktable 29/10/2024 00:11:56 2
506 worktable 29/10/2024 00:11:56 2
509 worktable 29/10/2024 00:11:56 2

Is this normal?
And if not, how can I find where they originate from so I can check out what is going on?

Based on the answer from john, I tried this query

SELECT GETDATE() as now,
       DATEDIFF(SECOND, transaction_begin_time, GETDATE()) as tran_elapsed_time_seconds,
       st.session_id,
       txt.text,
       at.transaction_id,
       at.transaction_begin_time,
       at.transaction_type,
       at.transaction_status
       
FROM   sys.dm_tran_active_transactions at
  left JOIN sys.dm_tran_session_transactions st ON st.transaction_id = at.transaction_id
  LEFT OUTER JOIN sys.dm_exec_sessions sess ON st.session_id = sess.session_id
  LEFT OUTER JOIN sys.dm_exec_connections conn ON conn.session_id = sess.session_id
  OUTER APPLY sys.dm_exec_sql_text(conn.most_recent_sql_handle)  AS txt
  
where at.transaction_id in (496, 499, 501, 503, 506, 509)  
  
ORDER BY
   tran_elapsed_time_seconds DESC

and it gives me this result

now tran_elapsed_time_seconds session_id text transaction_id transaction_begin_time transaction_type transaction_status
26/11/2024 11:01:57 2458201 496 29/10/2024 00:11:56 2 0
26/11/2024 11:01:57 2458201 499 29/10/2024 00:11:56 2 0
26/11/2024 11:01:57 2458201 501 29/10/2024 00:11:56 2 0
26/11/2024 11:01:57 2458201 503 29/10/2024 00:11:56 2 0
26/11/2024 11:01:57 2458201 506 29/10/2024 00:11:56 2 0
26/11/2024 11:01:57 2458201 509 29/10/2024 00:11:56 2 0

When I use an inner join for JOIN sys.dm_tran_session_transactions st I get no rows at all.

I don't know how or what more information I can give about this, does the information in this question makes sense to anyone here ?

Edit
I installed WhoIsActive (as proposed in a comment) but it returns no rows while these transactions are the only ones, so I have no help there either

4
  • 1
    What does sp_WhoIsActive show?
    – J.D.
    Commented Nov 26 at 12:53
  • @J.D. I just installed it, it returns no rows at times, so I guess it cannot find who is doing these transactions
    – GuidoG
    Commented Nov 26 at 15:12
  • Another recent question about these dba.stackexchange.com/q/343854/3690 Commented Nov 27 at 14:19
  • @MartinSmith Thank you, this pushes me some more in the direction of thinking this is normal behaviour
    – GuidoG
    Commented Nov 27 at 14:46

2 Answers 2

1

As per the documentation for sys.dm_tran_active_transactions (Transact-SQL) you might want to run the following statement to determine who is responsible or what might be going on:

 SELECT
   GETDATE() as now,
   DATEDIFF(SECOND, transaction_begin_time, GETDATE()) as tran_elapsed_time_seconds,
   st.session_id,
   txt.text, 
   *
 FROM
   sys.dm_tran_active_transactions at
   INNER JOIN sys.dm_tran_session_transactions st ON st.transaction_id = at.transaction_id
   LEFT OUTER JOIN sys.dm_exec_sessions sess ON st.session_id = sess.session_id
   LEFT OUTER JOIN sys.dm_exec_connections conn ON conn.session_id = sess.session_id
     OUTER APPLY sys.dm_exec_sql_text(conn.most_recent_sql_handle)  AS txt
 ORDER BY
   tran_elapsed_time_seconds DESC;

Without further information your question can probably only be answered with a (well educated) guess.

2
  • I updated my question with your query, but it makes no sense to me. What more information can I give you, and how to obtain it ?
    – GuidoG
    Commented Nov 26 at 10:08
  • You omitted the star from the query. It's hard to find details.
    – John K. N.
    Commented Nov 29 at 21:17
1
SELECT
   at.transaction_id, 
   at.name,
   at.transaction_begin_time,
   at.transaction_state,
   DB_NAME(db.database_id) AS dbName
FROM
   sys.dm_tran_active_transactions at
LEFT JOIN sys.dm_tran_database_transactions db
    ON at.transaction_id = db.transaction_id
WHERE name = 'worktable'

The query above returns the database where the transactions occur. In this case, the database is tempdb, and these transactions are associated with worktables.

This reference gives us some info about worktable: "Worktables are internal tables that are created in the tempdb database and are not visible to users."

I observed the same six transactions in my system: transactions

Based on my understanding, these transactions are likely related to internal processes and should not be a significant concern.

Also, I noticed the transaction begin time was closed to when the instance startup:startup

1
  • Thank you, this makes me a bit more relaxed
    – GuidoG
    Commented Nov 27 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.