Quantcast
Viewing all articles
Browse latest Browse all 9

How can I find the space used by a SQL Transaction Log? [ANSWERED]

How can I find the space used by a SQL Transaction Log?

Asked By: Sean Earp
Originally Asked On: 2009-06-24 03:05:58
Asked Via: serverfault

The SQL Server sp_spaceused stored procedure is useful for finding out a database size, unallocated space, etc. However (as far as I can tell), it does not report that information for the transaction log (and looking at database properties within SQL Server Management Studio also does not provide that information for transaction logs).

While I can easily find the physical space used by a transaction log by looking at the .ldf file, how can I find out how much of the log file is used and how much is unused?

He received 5 answers
eventually accepting:

Sean Earp’s answer to

How can I find the space used by a SQL Transaction Log?

Found the answer just after I submitted the question Image may be NSFW.
Clik here to view.
:)

It looks like dbcc sqlperf(logspace) and dbcc loginfo are my friend.

http://www.mssqltips.com/tip.asp?tip=1225

The answer with the highest score with 2 points was:

Praveen Sagar Velpula’s answer to

How can I find the space used by a SQL Transaction Log?

create table #dbsize 
(Dbname varchar(30),dbstatus varchar(20),Recovery_Model varchar(10) default ('NA'), file_Size_MB decimal(20,2)default (0),Space_Used_MB decimal(20,2)default (0),Free_Space_MB decimal(20,2) default (0)) 
go 

insert into #dbsize(Dbname,dbstatus,Recovery_Model,file_Size_MB,Space_Used_MB,Free_Space_MB) 
exec sp_msforeachdb 
'use [?]; 
  select DB_NAME() AS DbName, 
    CONVERT(varchar(20),DatabasePropertyEx(''?'',''Status'')) ,  
    CONVERT(varchar(20),DatabasePropertyEx(''?'',''Recovery'')),  
sum(size)/128.0 AS File_Size_MB, 
sum(CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT))/128.0 as Space_Used_MB, 
SUM( size)/128.0 - sum(CAST(FILEPROPERTY(name,''SpaceUsed'') AS INT))/128.0 AS Free_Space_MB  
from sys.database_files  where type=0 group by type' 





go 
select * from #dbsize 

If the selected answer did not help you out, the other answers might!

All Answers For: How can I find the space used by a SQL Transaction Log?

Sean Earp’s answer to

How can I find the space used by a SQL Transaction Log?

Found the answer just after I submitted the question Image may be NSFW.
Clik here to view.
:)

It looks like dbcc sqlperf(logspace) and dbcc loginfo are my friend.

http://www.mssqltips.com/tip.asp?tip=1225

Richard’s answer to

How can I find the space used by a SQL Transaction Log?

For a more GUI approach SQL Management studio can create a disk space (amongst others) report for a database (right click on the database node in the object explorer, select reports).

This report will also show information on recent file resizes.

Bogdan_Ch’s answer to

How can I find the space used by a SQL Transaction Log?

Another way – perform in MS SQL Management Studio the following command:

  • Right click on the database
  • Tasks
  • Shrink
  • Files

and select File Type = Log you will not only see the file size and % of available free space.

SuperCoolMoss’s answer to

How can I find the space used by a SQL Transaction Log?

Another way – fire up perfmon and check out the following counters:

  • SQLServer:Databases Log File(s)
    Size(KB)
  • SQLServer:Databases Log File(s) Used
    Size(KB)
  • SQLServer:Percent Log Used

These values update in real-time.

Praveen Sagar Velpula’s answer to

How can I find the space used by a SQL Transaction Log?

create table #dbsize 
(Dbname varchar(30),dbstatus varchar(20),Recovery_Model varchar(10) default ('NA'), file_Size_MB decimal(20,2)default (0),Space_Used_MB decimal(20,2)default (0),Free_Space_MB decimal(20,2) default (0)) 
go 

insert into #dbsize(Dbname,dbstatus,Recovery_Model,file_Size_MB,Space_Used_MB,Free_Space_MB) 
exec sp_msforeachdb 
'use [?]; 
  select DB_NAME() AS DbName, 
    CONVERT(varchar(20),DatabasePropertyEx(''?'',''Status'')) ,  
    CONVERT(varchar(20),DatabasePropertyEx(''?'',''Recovery'')),  
sum(size)/128.0 AS File_Size_MB, 
sum(CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT))/128.0 as Space_Used_MB, 
SUM( size)/128.0 - sum(CAST(FILEPROPERTY(name,''SpaceUsed'') AS INT))/128.0 AS Free_Space_MB  
from sys.database_files  where type=0 group by type' 





go 
select * from #dbsize 

Of course, you should really check out the original question.

The post How can I find the space used by a SQL Transaction Log? [ANSWERED] appeared first on Tech ABC to XYZ.


Viewing all articles
Browse latest Browse all 9

Trending Articles