Who’s making your log file grow in SQL Server?


Determining what T-SQL query or SQL Server client application is the source of log file growth is an often asked question.

“Old” SQL DBAs would sometimes refer you to KB 317375 which unfortunately is no longer hosted as a Microsoft KB Article, but sadly infinitely loops on one new Docs @ Microsoft page. Note also that the way the support page at Microsoft was built creates also issue for the WayBack Machine to display.

In order to keep a trace on how to proceed in such a case, let’s store in this article a few points on how to tackle this.

  • Since SQL Server 2005, the answer is somewhere in the Dynamic Management Views. The goal is to roughly know which DMVs may be helpful here. Only objection granted to the reader: since SQL Server 2008, may be some Extended Event may also help you.
  • In our case, the answer will be stored somewhere in the row of the sys.dm_tran_database_transactions DMV. Fields of interest start with database_transaction_log_bytes_*
  • Unfortunately this view is not enough as the transaction in the database contains just an ID and not the query itself.
  • To get the query we have to join the database transactions view on the session transactions view. From there, the session id of the session transactions view will allow us to get the T-SQL text in the dynamic management function sql_text by joining on the requests view.
  • Notice that the sqltext field doesn’t give you the precise statement you’re hunting, but may give you the full text of a stored procedure if this statement is a part of such an object. You must use statement_start_offset and statement_end_offset to calculate the true “sub-statement” if it exists.

All those directions were more or less explained in the original article but the ready-to-use in-case-of-emergency full T-SQL solution was not part of this article nor it is part of the newer docs page. The ready to use statement is as follows:

This snippet is part of the repository of various tools I store in a SQL Server related Github repository.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.