January 19, 2009 at 5:23 am
I need to shrink database and log files to less than their inital size, thus change the initial size of the dabase file.
How do I do this?
January 19, 2009 at 5:39 am
1. Backup your log file
2. DBCC SHRINKDATABASE(Databasename)
January 19, 2009 at 5:44 am
I need to shrink the database files to less than the current initial size of the database. Shrinkfile, shrinkdatabase and logbackup only shrinks to the initial size of the database files.
Thus, I do not want to shrink, I want to change the initial size of the files.
January 19, 2009 at 5:45 am
Its seems to be an open issue in both sql server 2000 and SQL Server 2005. We cannot shrink the database less than the initial size.
January 19, 2009 at 5:54 am
You would think that if you cannot shrink the file below the initial size they'd at least give us the possibility to be able to decrease the initial size then.... :hehe:
January 19, 2009 at 6:31 am
DBCC SHOINKDATABASE will not allow a shrink below the original size, but DBCC SHRINKFILE will allow you to shrink to any desired size. (provided this size is larger than the currently used space!)
Mike John
January 19, 2009 at 6:50 am
TDP (1/19/2009)
You would think that if you cannot shrink the file below the initial size they'd at least give us the possibility to be able to decrease the initial size then.... :hehe:
Actually shrink file does let you shrink the files so theyโll be smaller then the initial size. Check the script bellow that shows it:
--Create the database. Notice the size of the files
CREATE DATABASE MyDB
ON
( NAME = MyDB_dat,
FILENAME = 'c:\MyDB.mdf',
SIZE = 10MB,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = MyDB_log,
FILENAME = 'c:\MyDB.ldf',
SIZE = 3MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )
go
use MyDB
go
--Get the file's size
select name, size from MyDB.sys.database_files
--Srinking both log and data files
dbcc shrinkfile('MyDB_Dat',1)
go
dbcc shrinkfile('MyDB_log',1)
go
--Compare the new size with the size before the use of dbcc shrinkfile
select name, size from MyDB.sys.database_files
go
--Cleanup the mess:-)
use master
go
drop database MyDB
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
January 19, 2009 at 7:03 am
Thanks guys. Think there might have been open transactions or replication that were not allowing me to shrink the file to less than the initial size. ๐
January 19, 2009 at 8:08 am
You can't shrink below the initial size. Your only option is to back up the database, drop and recreate it with a lower initial size, and then restore. You should only set the initial size when you know you will always need at least that much space.
January 19, 2009 at 9:06 am
Mike John (1/19/2009)
DBCC SHOINKDATABASEMike John
New in SQL 2005???? ๐
-- You can't be late until you show up.
January 19, 2009 at 9:41 am
binary lumberjack (1/19/2009)
You can't shrink below the initial size. Your only option is to back up the database, drop and recreate it with a lower initial size, and then restore. You should only set the initial size when you know you will always need at least that much space.
Again - if you use shrinkdatabase, that might be true, but shrinkfile DOES in fact allow you to make the initial size smaller.....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
March 23, 2009 at 10:44 am
It looks like shrinkfile worked as I can see all the expected size from sys.database_files and sqlperf(logspace). But the actual size of the logfile still keeps the same physical size as the initial size.
March 30, 2011 at 10:58 pm
Make sure the log has been backed up first or set the recovery model to simple.
This will allow the log file to be shrunk to a size smaller than the original file size specified.
April 9, 2012 at 9:42 am
shrinkfile will let you go below the initial size. I shrunk the file and tried to lower the initial size, stopped and restarted the sql service and it went right back to the original initial size. Does that make any sense?
December 27, 2012 at 5:47 pm
From BOL:
You can reduce the default size of an empty file by using DBCC SHRINKFILE target_size. For example, if you create a 5-MB file and then shrink the file to 3 MB while the file is still empty, the default file size is set to 3 MB. This applies only to empty files that have never contained data.
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply