Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Quesion On Space used by a specific Datafile


Quesion On Space used by a specific Datafile

Author
Message
Mac1986
Mac1986
SSC Veteran
SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)

Group: General Forum Members
Points: 278 Visits: 787
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
mahesh.dasoni
mahesh.dasoni
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 1025
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
Mac1986
Mac1986
SSC Veteran
SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)

Group: General Forum Members
Points: 278 Visits: 787
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'
Joie Andrew
Joie Andrew
SSC Eights!
SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)

Group: General Forum Members
Points: 969 Visits: 1904
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"
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search