Hi - If I shrink a data file (e.g. mdf) whilst the users are online - is there a risk of : a) user disruption? b) data corruption? thanks
it is not wise to use auto_shrink on for data files. Repeating shrinking and autogrowing the data files will cause file-system level fragmentation, which can slow down performance. plus many disadvantages. Turn AUTO_SHRINK off!! - check: http://blogs.msdn.com/sqlserverstorageengine/archive/2007/03/28/turn-auto-shrink-off.aspx
My answer is it depends on both the cases, as SHRINK operation is intensive and if users are performing large updates to text columns (say for instance) then it will cause blocking and that can lead to corruption as well. http://sqlserver-qa.net/blogs/perftune/archive/2008/04/25/4112.aspx fyi.
Hi - How can blocking lead to corruption? do you mean disk contention blocking rather than database blocking (i.e. table blocking)?Thanks
Ok, I should have been more clear on corruption part which is inconsistency on the data pages where by the DBCC SHRINK operation is trying to remove the page and updates on table (text or non-text columns) will need split the pages, it all depends on the application to database update mechanism. You raised a good point too that disk contention is also much important here, which is will have high I/O on the drives where your data/log files are stored.
Just to add since shrnk operations are resource intensive, make sure you have adequate growth percentage for log file and max size is atleast has 20% more free space o you do not have to perform regular shrink. In SQL 2005 undocumented DBCC LOGINFO command once run you need to check status column to see if there lots of 2 listed, if yes then the log file is eligible for shrinking. -Sat
Hello, If i simply execute DBCC LOGINFO then it lists a lot of files with same file id, better if someone could explain what these rows indicate. Also if someone can post the exact syntax for DBCC LOGINFO, it would be great. Thanks, Mani
How many files exist on transaction log? Say if that transaction log consists 2 files, then the LOGINFO output shows that the transaction log consists of file identifiers found in the sysfiles system table for log files are 2 and 7. The transaction log contains 15 virtual log files (total number of rows in the output) of which 5 contain active transactions -- this is true for VLF's that have 2 in the status column of the output. Note also that virtual log files containing the active transactions are at the bottom of the output. Until the status of these VLF's changes to 0 you cannot shrink the transaction log. The status will change when transactions are saved to the disk. Once the status of a virtual log file changes to 0 you can run DBCC SHRINKFILE against each physical log file (in this case against files 2 and 7) to reduce their size.
Well thats the whole point of not following one of the best practices on SQL databases, http://sqlserver-qa.net/blogs/perftune/archive/2008/03/26/3722.aspx too.
Database shrink is only reduce occupied free space from database. and this also Microsoft In-built Tools. So There Is No Risk To Corruption and lost data. but it will effect on performance on running Transaction.
There is a risk of data corruption!! Say when the backup operation is executing and DBCC SHIRNKFILE operation is running, due to the lock of pages for SHRINK the backup will cause such an issue.