Home
%3CLINGO-SUB%20id%3D%22lingo-sub-368817%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%237%3A%20Monitoring%20the%20transaction%20log%20space%20of%20my%20database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-368817%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Oct%2031%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3EIn%20many%20support%20cases%2C%20our%20customers%20want%20to%20monitor%20the%20available%20space%20for%20the%20transaction%20log%20space%20for%20their%20database%20or%20to%20know%20what%20caused%26nbsp%3Ban%20error%20when%20the%20transaction%20is%20full.%20%3CBR%20%2F%3E%3CBR%20%2F%3EUnfortunately%2C%20there%20is%20not%20supported%26nbsp%3Bto%20use%26nbsp%3BDBCC%20SQLPERF(LOGSPACE)%26nbsp%3Bnowdays.%20For%20this%20reason%2C%20I%20would%20like%20to%20share%20with%20you%20another%20view%20where%20you%20could%20find%20out%20these%20results.%20%3CBR%20%2F%3E%3CBR%20%2F%3ERunning%20the%20below%20query%26nbsp%3Byou%20could%20find%20all%26nbsp%3Btransactions%20active%2C%20the%26nbsp%3Busers%20that%20are%20executing%20them%20%2C%20TSQL%20statement%2C%20etc..%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESELECT%20TranSession.%5Bsession_id%5D%2C%20SessionS.%5Blogin_name%5D%20AS%20%5BLogin%20Name%5D%2C%20TranDB.%5Bdatabase_transaction_begin_time%5D%20AS%20%5BStart_Time%5D%2C%0ACASE%20TranActive.transaction_type%0AWHEN%201%20THEN%20'Read%2Fwrite%20transaction'%0AWHEN%202%20THEN%20'Read-only%20transaction'%0AWHEN%203%20THEN%20'System%20transaction'%0AEND%20AS%20%5BTransaction_Type%5D%2C%0ACASE%20TranActive.transaction_state%0AWHEN%201%20THEN%20'The%20transaction%20has%20not%20been%20initialized'%0AWHEN%202%20THEN%20'The%20transaction%20is%20active'%0AWHEN%203%20THEN%20'The%20transaction%20has%20ended.%20This%20is%20used%20for%20read-only%20transactions'%0AWHEN%205%20THEN%20'The%20transaction%20is%20in%20a%20prepared%20state%20and%20waiting%20resolution.'%0AWHEN%206%20THEN%20'The%20transaction%20has%20been%20committed'%0AWHEN%207%20THEN%20'The%20transaction%20is%20being%20rolled%20back'%0AWHEN%208%20THEN%20'The%20transaction%20has%20been%20rolled%20back'%0AEND%20AS%20%5BTransaction_State%5D%2C%0ATranDB.%5Bdatabase_transaction_log_record_count%5D%20AS%20%5BLog_Records%5D%2C%0ATranDB.%5Bdatabase_transaction_log_bytes_used%5D%20AS%20%5BLog_Bytes_Used%5D%2C%0ASQlText.text%20%20AS%20%5BLast_Transaction_Text%5D%2C%0ASQLQP.%5Bquery_plan%5D%20AS%20%5BLast_Query_Plan%5D%0AFROM%20sys.dm_tran_database_transactions%20TranDB%0AINNER%20JOIN%20sys.dm_tran_session_transactions%20TranSession%0AON%20TranSession.%5Btransaction_id%5D%20%3D%20TranDB.%5Btransaction_id%5D%0AINNER%20JOIN%20sys.dm_tran_active_transactions%20TranActive%0AON%20TranSession.%5Btransaction_id%5D%20%3D%20TranActive.%5Btransaction_id%5D%0AINNER%20JOIN%20sys.dm_exec_sessions%20SessionS%0AON%20SessionS.%5Bsession_id%5D%20%3D%20TranSession.%5Bsession_id%5D%0AINNER%20JOIN%20sys.dm_exec_connections%20Connections%0AON%20Connections.%5Bsession_id%5D%20%3D%20TranSession.%5Bsession_id%5D%0ALEFT%20JOIN%20sys.dm_exec_requests%20Request%0AON%20Request.%5Bsession_id%5D%20%3D%20TranSession.%5Bsession_id%5D%0ACROSS%20APPLY%20sys.dm_exec_sql_text%20(Connections.%5Bmost_recent_sql_handle%5D)%20AS%20SQlText%0AOUTER%20APPLY%20sys.dm_exec_query_plan%20(Request.%5Bplan_handle%5D)%20AS%20SQLQP%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-368817%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Oct%2031%2C%202016%20In%20many%20support%20cases%2C%20our%20customers%20want%20to%20monitor%20the%20available%20space%20for%20the%20transaction%20log%20space%20for%20their%20database%20or%20to%20know%20what%20caused%26nbsp%3Ban%20error%20when%20the%20transaction%20is%20full.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-368817%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMonitoring%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Etransaction%20log%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

First published on MSDN on Oct 31, 2016
In many support cases, our customers want to monitor the available space for the transaction log space for their database or to know what caused an error when the transaction is full.

Unfortunately, there is not supported to use DBCC SQLPERF(LOGSPACE) nowdays. For this reason, I would like to share with you another view where you could find out these results.

Running the below query you could find all transactions active, the users that are executing them , TSQL statement, etc..

 

SELECT TranSession.[session_id], SessionS.[login_name] AS [Login Name], TranDB.[database_transaction_begin_time] AS [Start_Time],
CASE TranActive.transaction_type
WHEN 1 THEN 'Read/write transaction'
WHEN 2 THEN 'Read-only transaction'
WHEN 3 THEN 'System transaction'
END AS [Transaction_Type],
CASE TranActive.transaction_state
WHEN 1 THEN 'The transaction has not been initialized'
WHEN 2 THEN 'The transaction is active'
WHEN 3 THEN 'The transaction has ended. This is used for read-only transactions'
WHEN 5 THEN 'The transaction is in a prepared state and waiting resolution.'
WHEN 6 THEN 'The transaction has been committed'
WHEN 7 THEN 'The transaction is being rolled back'
WHEN 8 THEN 'The transaction has been rolled back'
END AS [Transaction_State],
TranDB.[database_transaction_log_record_count] AS [Log_Records],
TranDB.[database_transaction_log_bytes_used] AS [Log_Bytes_Used],
SQlText.text  AS [Last_Transaction_Text],
SQLQP.[query_plan] AS [Last_Query_Plan]
FROM sys.dm_tran_database_transactions TranDB
INNER JOIN sys.dm_tran_session_transactions TranSession
ON TranSession.[transaction_id] = TranDB.[transaction_id]
INNER JOIN sys.dm_tran_active_transactions TranActive
ON TranSession.[transaction_id] = TranActive.[transaction_id]
INNER JOIN sys.dm_exec_sessions SessionS
ON SessionS.[session_id] = TranSession.[session_id]
INNER JOIN sys.dm_exec_connections Connections
ON Connections.[session_id] = TranSession.[session_id]
LEFT JOIN sys.dm_exec_requests Request
ON Request.[session_id] = TranSession.[session_id]
CROSS APPLY sys.dm_exec_sql_text (Connections.[most_recent_sql_handle]) AS SQlText
OUTER APPLY sys.dm_exec_query_plan (Request.[plan_handle]) AS SQLQP