Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Quesion On Space used by a specific Datafile Expand / Collapse
Author
Message
Posted Sunday, October 28, 2012 11:54 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 24, 2014 10:27 PM
Points: 219, Visits: 688
Hi I use the below script to find out the space consumed by a particular DB. It works fine for me.

select A.[Size]/128 AS [FileSize]
,FileProperty (A.[name], 'spaceused') / 128 AS [Consumed]
,A.[max_size]/128 AS [MaxSize]
,A.growth/128 AS [AutoGrowMB]
,CONVERT(VARCHAR(25), A.[Name]) AS [LocicalName]
,A.[physical_name] AS [FileLocation]
from sys.master_files A where A.database_id = DB_ID(DB_NAME())
order by A.type, a.[file_id]

But then when I do sp_Helpdb <DB Name> I see different numbers on the column SIZE.
Can the Consumed size be less than the Initial Size of the file???

Please lighten me with your knowledge
Post #1378110
Posted Monday, October 29, 2012 12:57 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, July 12, 2014 12:11 AM
Points: 81, Visits: 912
Check this query:

select df.name AS LogicalFileName
, isnull(fg.name, 'Log') AS FilegroupName
, df.physical_name AS PhysicalOSName
, (df.size * 8 / 1024) AS SizeMBs
, (fileproperty(df.name, 'SpaceUsed') / 128) AS SpaceUsedMBs
, (df.size * 8 / 1024) - (fileproperty(df.name, 'SpaceUsed') / 128) AS FreeMBs
, case df.max_size
when 0 then 'No Growth'
when -1 then 'Unlimited'
when 268435456 then '2TB'
else cast(df.max_size / 128 AS VARCHAR(10)) + ' MBs'
end AS MaxFileSize
, case df.is_percent_growth
when 0 then cast(df.growth / 128 AS VARCHAR(10)) + ' MBs'
else CAST(df.growth AS VARCHAR(10)) + ' %'
end AS Growth
,cast(cast((fileproperty(df.name, 'SpaceUsed') / 128) as numeric(20,2)) /
cast(df.size / 128 as numeric(20,2))
* 100 as numeric(20,2)) as PercentUsed

from sys.database_files df left outer join sys.filegroups fg ON df.data_space_id = fg.data_space_id
order by df.type
Post #1378124
Posted Monday, October 29, 2012 3:13 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 24, 2014 10:27 PM
Points: 219, Visits: 688
Thanks mahesh.. your query is a little more elaborative than mine.

But my main question is if the Initial size is 70 GB can the consumed be 3 mb? I have seen this case happening with Tempdb last week.

First I used
select A.[Size]/128 AS [FileSize]
,FileProperty (A.[name], 'spaceused') / 128 AS [Consumed]
,A.[max_size]/128 AS [MaxSize]
,A.growth/128 AS [AutoGrowMB]
,CONVERT(VARCHAR(25), A.[Name]) AS [LocicalName]
,A.[physical_name] AS [FileLocation]
from sys.master_files A where A.database_id = DB_ID(DB_NAME())
order by A.type, a.[file_id]


then i see that in sp_helpdb <DB NAme> is giving different numbers for the column 'Size'
Post #1378164
Posted Monday, October 29, 2012 12:32 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, July 25, 2014 8:43 AM
Points: 709, Visits: 1,411
But my main question is if the Initial size is 70 GB can the consumed be 3 mb? I have seen this case happening with Tempdb last week.


You can set a database with an intial size. This is preferred if you have an estimated size your database needs to be than to having a very small data file that has to issue a lot of growth events which can lead to bad fragmentation. The space that is not used is white space in the file that is reserved for future use.

TempDB get objects created and dropped all the time depending on the operations that are going on with different databases. The thing you want to watch out for is to ensure that TempDB does not fill up where it cannot grow if necessary.


Joie Andrew
"Since 1982"
Post #1378405
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse