Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 doubt about dbccshrinkfile command

Author  Topic 

anoop_mig25
Starting Member

20 Posts

Posted - 2013-08-22 : 03:36:05
Hi friends i wanted to know about behaviour of command

dbcc shrinkfile(2,10)

now 2 denotes that i want to shrink log file

but what i wanted to know about is size to which it decrease.It know size is in 10 mb.

But what i wanted to know is whether size would reduce by 10 mb or reduce to 10 mb.

for eg suppose log file size is 100 mb.

then after executing above command would log file new size would be 10 mb or 90 mb

Thanks and Regards
Anoop

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-22 : 03:46:43
DBCC SHRINKFILE( File_id, target_size)
Target_size:
Is the size for the file in megabytes, expressed as an integer. If not specified, DBCC SHRINKFILE reduces the size to the default file size. The default size is the size specified when the file was created.

Note:
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.

If target_size is specified, DBCC SHRINKFILE tries to shrink the file to the specified size. Used pages in the part of the file to be freed are relocated to available free space in the part of the file retained. For example, if there is a 10-MB data file, a DBCC SHRINKFILE operations with a target_size of 8 causes all used pages in the last 2 MB of the file to be reallocated into any unallocated pages in the first 8 MB of the file. DBCC SHRINKFILE does not shrink a file past the size needed to store the data in the file. For example, if 7 MB of a 10-MB data file is used, a DBCC SHRINKFILE statement with a target_size of 6 shrinks the file to only 7 MB, not 6 MB.

Refer this link
http://technet.microsoft.com/en-us/library/ms189493.aspx

--
Chandu
Go to Top of Page

anoop_mig25
Starting Member

20 Posts

Posted - 2013-08-23 : 01:44:28
quote:
Originally posted by bandi

DBCC SHRINKFILE( File_id, target_size)
Target_size:
Is the size for the file in megabytes, expressed as an integer. If not specified, DBCC SHRINKFILE reduces the size to the default file size. The default size is the size specified when the file was created.

Note:
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.

If target_size is specified, DBCC SHRINKFILE tries to shrink the file to the specified size. Used pages in the part of the file to be freed are relocated to available free space in the part of the file retained. For example, if there is a 10-MB data file, a DBCC SHRINKFILE operations with a target_size of 8 causes all used pages in the last 2 MB of the file to be reallocated into any unallocated pages in the first 8 MB of the file. DBCC SHRINKFILE does not shrink a file past the size needed to store the data in the file. For example, if 7 MB of a 10-MB data file is used, a DBCC SHRINKFILE statement with a target_size of 6 shrinks the file to only 7 MB, not 6 MB.

Refer this link
http://technet.microsoft.com/en-us/library/ms189493.aspx

--
Chandu



What you said i allredy know it and had read it , but i had doubt so i asked straight for ward question.

please tell what would post log size after shrinkfile operation.

Would it would be 10MB or 90MB provided there is data of size less then 10mb in log file
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-23 : 03:42:41
In your case after executing DBCC command the log file size would be 90 mb.... and free space available in log file is 10 MB
For log files, SQL Server uses target_size to calculate the target size for the entire log; therefore, target_size is the amount of free space in the log after the shrink operation.

http://www.sqlteam.com/Forums/pop_printer_friendly.asp?TOPIC_ID=15157

--
Chandu
Go to Top of Page
   

- Advertisement -