Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the size of the Transaction Log in SQL 2005 programmatically?

Tags:

We're working with a fixed transaction log size on our databases, and I'd like to put together an application to monitor the log sizes so we can see when things are getting too tight and we need to grow the fixed trn log.

Is there any TSQL command that I can run which will tell me the current size of the transaction log, and the fixed limit of the transaction log?

like image 926
Adam Ness Avatar asked Oct 13 '08 17:10

Adam Ness


People also ask

How do I find the transaction log size in SQL Server?

Monitor log space use by using sys. dm_db_log_space_usage. This DMV returns information about the amount of log space currently used, and indicates when the transaction log needs truncation.

How do I find the size of a SQL query?

If you need to check a single database, you can quickly find the SQL Server database sizein SQL Server Management Studio (SSMS): Right-click the database and then click Reports -> Standard Reports -> Disk Usage. Alternatively, you can use stored procedures like exec sp_spaceused to get database size.


1 Answers

I used your code but, there was an error converting to an int. "Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to data type int." So wherever there was an "*8" I changed it to *8.0 and the code works perfectly.

SELECT (size * 8.0)/1024.0 AS size_in_mb      , CASE   WHEN max_size                                 = -1    THEN 9999999                  -- Unlimited growth, so handle this how you want   ELSE (max_size * 8.0)/1024.0                  END AS max_size_in_mb   FROM YOURDBNAMEHERE.sys.database_files  WHERE data_space_id                            = 0            
like image 59
Myles Yamada Avatar answered Sep 18 '22 18:09

Myles Yamada