Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL: How do I get the size of the transaction log?

How do I get the current size of the transaction log? How do I get the size limit?

I'd like to monitor this so I can determine how often I need to backup the transaction log.

I usually have a problem with the transaction log when I perform large operations.

like image 587
Niels Bosma Avatar asked Dec 16 '09 08:12

Niels Bosma


People also ask

What is the size of transaction log file?

Log files 64 MB.

How do I determine SQL size?

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.

How do you know the total transaction count in SQL?

SQL Server COUNT() FunctionThe COUNT() function returns the number of records returned by a select query. Note: NULL values are not counted.


2 Answers

Based on SQL Server 2005, try this

SELECT (size * 8)/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) / 1024.0
        END AS max_size_in_mb
FROM <YourDB>.sys.database_files
WHERE data_space_id = 0   -- Log file

Change YourDB to your database name

For an overall of all database sizes try DBCC SQLPERF

DBCC SQLPERF (LOGSPACE)

This should work in SQL 2000/2005/2008

like image 175
kevchadders Avatar answered Oct 16 '22 17:10

kevchadders


If you want to monitor it in real time, try Performance Monitor (perfmon) while you are doing those large operations.

Perfmon can be used in many different scenarios.

Find out more from Technet.

like image 35
Guge Avatar answered Oct 16 '22 16:10

Guge