December 2, 2008 at 10:27 pm
hi,
is there any script to get the actual datafile size, logfile size
thank you
December 2, 2008 at 10:57 pm
Is this what you want?
--===== Declare local files
--Jeff Moden
DECLARE @DBID INT
DECLARE @DBName VARCHAR(30)
DECLARE @Text NVARCHAR(300)
--===== Get the first database ID
SELECT @DBID = MIN(DBID) FROM Master.dbo.SysDataBases
--===== Loop until we run out of database ID's
WHILE @DBID IS NOT NULL
BEGIN
--===== Get the database name for the current DBID
SELECT @DBName = NAME FROM Master.dbo.SysDataBases WHERE DBID = @DBID
--===== Set the dynamic SQL to use the database name and get the info
SET @Text = N'USE '+ @DBName + N' EXEC sp_HelpFile'
--===== Exec the dynamic SQL
EXEC dbo.sp_ExecuteSql @Text
--===== Get the next larger DBID
SELECT @DBID = MIN(DBID) FROM Master..SysDataBases WHERE DBID > @DBID
END
--Jeff Moden
Change is inevitable... Change for the better is not.
December 2, 2008 at 11:21 pm
thanks Jeff,
This script is giving the mdf and ndf file. But I would like to get the actual space allocated for datafile and the available space inorder to monitor .Based on the output of the script, increase the data file size when ever the available space comes to a low value to aviod the application hanging situations when the datafile size increasing which is set to autogrow(which is usaully resource intensive process). and also the size should be in MB.
Thanks in advance
December 3, 2008 at 12:12 am
This might be what you are looking for, even if it is not; it does give you a pretty good idea of how to start working on it 🙂
http://www.sqlservercentral.com/scripts/Miscellaneous/30031/
Regards,
December 3, 2008 at 7:29 pm
madhu.arda (12/2/2008)
thanks Jeff,This script is giving the mdf and ndf file. But I would like to get the actual space allocated for datafile and the available space inorder to monitor .Based on the output of the script, increase the data file size when ever the available space comes to a low value to aviod the application hanging situations when the datafile size increasing which is set to autogrow(which is usaully resource intensive process). and also the size should be in MB.
Thanks in advance
I'm thinking you can probably handle the math to chang KB to MB. Lemme look and see what I've got in my goodie-locker for the rest.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 3, 2008 at 10:54 pm
For Data File Space run
USE [DatabaseName]
DBCC SHOWFILESTATS
Result Computation
DB Size - (totalextents*64)/1024
DB Used - (usedextents*64)/1024
DB Space - (DB Size) - (DB Used)
For Log File Space run
DBCC SQLPERF(LOGSPACE)
"-=Still Learning=-"
Lester Policarpio
December 5, 2008 at 10:07 am
Hi,
here is the script to find the datafile size and logfile size.But it is giving for the database in which we run it.
Could you plz make it work for all the databases in an instance.
select Name,
(convert(float,size)) * (8192.0/1048576) File_Size,
(convert(float,fileproperty(name,'SpaceUsed'))) * (8192.0/1048576) MB_Used,
((convert(float,size)) * (8192.0/1048576) - (convert(float,fileproperty(name,'SpaceUsed'))) * (8192.0/1048576)) MB_Free
from sysfiles
order by
fileproperty(name,'IsLogFile')
Thanks
December 5, 2008 at 3:53 pm
This should work:
sp_msforeachdb 'USE ?
select Name,
(convert(float,size)) * (8192.0/1048576) File_Size,
(convert(float,fileproperty(name,''SpaceUsed''))) * (8192.0/1048576) MB_Used,
((convert(float,size)) * (8192.0/1048576) - (convert(float,fileproperty(name,''SpaceUsed''))) * (8192.0/1048576)) MB_Free
from sysfiles
order by
fileproperty(name,''IsLogFile'')'
December 5, 2008 at 6:33 pm
Thanks Edogg....
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply