Showing posts with label amount. Show all posts
Showing posts with label amount. Show all posts

Sunday, March 25, 2012

Database files free space (SQL Server 2005)

Dear friends

I need to report the amount of free space in each datafile of a database.

I have tried sys.dm_db_file_space_usage , but the documentation says that it only works for the TempDB.

Please help.

Regards

Parviz

Take a look at the sp_spaceused text. You should be able to derive from there.

exec sp_helptext 'sp_spaceused'|||

Thanks for the fast reply, but please note that sp_spaceused returns the free space for the whole database files including the LOG file. I need the info fo each file in a database seperately.

If you have a look at summary reports for a database (SQL 2005 SSMS),you would see a table and a pie chart showng the status for each file.

Thanks again.

Parviz

|||Yup. sp_spacedused can be used to get the data file usage. You can then use 'dbcc sqlperf(logspace)' to get the log usage.|||

Here's some code, cribbed from a sqldbatips report designed to mimic the taskpad in SSMS. (http://sqlblogcasts.com/blogs/sqldbatips/archive/2006/11/21/custom-ssms-reports-in-sp2-enterprise-manager-taskpad-view.aspx). All I did was add some code to show the amount free. Seems to work well. Posting here because this was one of the top results in Google when I went looking for code myself.

create table #data(Fileid int NOT NULL,

[FileGroup] int NOT NULL,

TotalExtents int NOT NULL,

UsedExtents int NOT NULL,

[Name] sysname NOT NULL,

[FileName] varchar(300) NOT NULL)

create table #log(dbname sysname NOT NULL,

LogSize numeric(15,7) NOT NULL,

LogUsed numeric(9,5) NOT NULL,

Status int NOT NULL)

insert #data exec('DBCC showfilestats with no_infomsgs')

insert #log exec('dbcc sqlperf(logspace) with no_infomsgs')

select [type], [name], totalmb, usedmb, totalmb - usedmb as EmptySpace from

(

select 'DATA' as [Type],[Name],(TotalExtents*64)/1024.0 as [TotalMB],(UsedExtents*64)/1024.0 as [UsedMB]

from #data

union all

select 'LOG',db_name()+' LOG',LogSize,((LogUsed/100)*LogSize) from #log where dbname = db_name()

--order by [Type],[Name]

)a

order by [Type],[Name]

drop table #data

drop table #log

|||

This will work for you:

-- Individual File Size query

SELECT name AS 'File Name' , physical_name AS 'Physical Name', size/128 AS 'Total Size in MB',

size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', *

FROM sys.database_files;

Database files free space (SQL Server 2005)

Dear friends

I need to report the amount of free space in each datafile of a database.

I have tried sys.dm_db_file_space_usage , but the documentation says that it only works for the TempDB.

Please help.

Regards

Parviz

Take a look at the sp_spaceused text. You should be able to derive from there.

exec sp_helptext 'sp_spaceused'|||

Thanks for the fast reply, but please note that sp_spaceused returns the free space for the whole database files including the LOG file. I need the info fo each file in a database seperately.

If you have a look at summary reports for a database (SQL 2005 SSMS),you would see a table and a pie chart showng the status for each file.

Thanks again.

Parviz

|||Yup. sp_spacedused can be used to get the data file usage. You can then use 'dbcc sqlperf(logspace)' to get the log usage.|||

Here's some code, cribbed from a sqldbatips report designed to mimic the taskpad in SSMS. (http://sqlblogcasts.com/blogs/sqldbatips/archive/2006/11/21/custom-ssms-reports-in-sp2-enterprise-manager-taskpad-view.aspx). All I did was add some code to show the amount free. Seems to work well. Posting here because this was one of the top results in Google when I went looking for code myself.

create table #data(Fileid int NOT NULL,

[FileGroup] int NOT NULL,

TotalExtents int NOT NULL,

UsedExtents int NOT NULL,

[Name] sysname NOT NULL,

[FileName] varchar(300) NOT NULL)

create table #log(dbname sysname NOT NULL,

LogSize numeric(15,7) NOT NULL,

LogUsed numeric(9,5) NOT NULL,

Status int NOT NULL)

insert #data exec('DBCC showfilestats with no_infomsgs')

insert #log exec('dbcc sqlperf(logspace) with no_infomsgs')

select [type], [name], totalmb, usedmb, totalmb - usedmb as EmptySpace from

(

select 'DATA' as [Type],[Name],(TotalExtents*64)/1024.0 as [TotalMB],(UsedExtents*64)/1024.0 as [UsedMB]

from #data

union all

select 'LOG',db_name()+' LOG',LogSize,((LogUsed/100)*LogSize) from #log where dbname = db_name()

--order by [Type],[Name]

)a

order by [Type],[Name]

drop table #data

drop table #log

|||

This will work for you:

-- Individual File Size query

SELECT name AS 'File Name' , physical_name AS 'Physical Name', size/128 AS 'Total Size in MB',

size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', *

FROM sys.database_files;

Monday, March 19, 2012

Database Driven Website using SAN

We want to develop database driven website. because of enormous amount
of data (300GB)
customers's tech advisor is insisting on using SAN instead of direct
attached storage method.
I want to know what issues need to be considered while using SAN in
web solutions.? Which database
server/ product is best suited for such kind of job ? Can anyone
suggests
good informative articles on this subject , available on web.
Thanks in advance
ssp2000"ssp2000" <ssp2000@.hotmail.com> wrote in message
news:78a9f1a5.0309290535.322076fb@.posting.google.com...
> We want to develop database driven website. because of enormous amount
> of data (300GB)
> customers's tech advisor is insisting on using SAN instead of direct
> attached storage method.
> I want to know what issues need to be considered while using SAN in
> web solutions.? Which database
> server/ product is best suited for such kind of job ? Can anyone
> suggests
> good informative articles on this subject , available on web.
Basically any full featured RDBMS product like Oracle or MS SQL Server will
be fine. As far as using a SAN with those, you'll need to follow-up in the
appropriate RDBMS forums ...
--
Tom Kaminski IIS MVP
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://mvp.support.microsoft.com/
http://www.microsoft.com/windowsserver2003/community/centers/iis/|||In addition to what Tom posted, there should be no issues in a web solution,
or any other application, directly related to using a SAN. The SAN
basically handles IO and storage transparently. Most SAN products are
designed to support IO-intensive environments and have features (sometimes
additional $) for managing large volumes of data, particularly
backup/restore and disaster recovery.
--
Bob
Microsoft Consulting Services
--
This posting is provided AS IS with no warranties, and confers no rights.|||In addition to what Tom and Bob's comments, I just want to add that, 300GB
isn't really that large these days. However, you also need to consider its
backups, and most likely you would need a Dev/QA environment as well.
Perhaps, tomorrow you'll be asked to support a reporting server. Very
quickly and easily, you can find yourself having to deal with near or over
one terabyte of data.
SAN gives you more flexibility in handling these varying factors in disk
storage requirements.
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"ssp2000" <ssp2000@.hotmail.com> wrote in message
news:78a9f1a5.0309290535.322076fb@.posting.google.com...
> We want to develop database driven website. because of enormous amount
> of data (300GB)
> customers's tech advisor is insisting on using SAN instead of direct
> attached storage method.
> I want to know what issues need to be considered while using SAN in
> web solutions.? Which database
> server/ product is best suited for such kind of job ? Can anyone
> suggests
> good informative articles on this subject , available on web.
> Thanks in advance
> ssp2000