Sql server shrink file takes too long




















Need a bit of Powershell? How about this. Who am I? Sometimes this is me but most of the time this is me. Repeated shrink and growth of a database will always lead to bad NTFS file fragmentation. This will give continuing bad performance to your database. Good practice for shrinking a database is do not do it.

The only exception is if you expect a permanent reduction in the database size. If you expect the space gained from a shrink to be reclaimed within a month, then you are causing more problems than you solve by shrinking it. When I give food to the poor they call me a saint. So reclaiming deleted records is going to be a big deal for me. Before anyone suggests storing images as files with names in SQL, I have some configuration problems that are going to make that difficult to do.

It is important to not confuse reclaiming space within the filesystem with reclaiming space within the database. After running one of these commands, your database will remain the same size as before unless the fill factor in the index causes more space to be needed but the free space within the database files will be in fewer fragments.

This can help database performance. However, even without one of these operations, SQL is very good at reusing space released by deleted records. If you want to store images in your database better in the DB than in the file system! It may be worthwhile to store the images in a separate filegroup to the rest of your table data. Space for images is allocated in extents, and released in extents. SQL is very good at reusing free extents when you want to store a new image, so you do not need to worry about reclaiming space.

However, a large image could be fragmented over a number of extents, and you may want to look at some form of maintenance to reduce this fragmentation. Chris Stamey. I am curious as to why you think it is better to store images inside the SQL database. Twitter LinkedIn. Search for: Close. Bad Advice From Experts Bad advice is all over the internet. It turns out it is the cause… Data Files Shrinking the data files mdf, ndf is a bad idea and should be reserved for emergency scenarios.

Transaction Log Files Shrinking the log file only 1 as it is a sequential write should be reserved until after careful consideration. Yes this Applies to tempdb Too Tempdb is sometimes the target of a shrink. Stop Shrinking Your Database Files. There are only a precious few scenarios that I can see a valid argument potentially made for shrinking a database: Cleanup work Some kind of bad data gets in your database by the boatload and you need to remove it.

This is a rare situation. This is also not something that should happen on a regular basis. If you are frequently shrinking a database to handle cleanup then you must know this is a bad practice and should be stopped. You are not treating the disease but rather fueling the symptoms you seek to treat. Archiving data If you have an archive policy where you periodically remove tons of data in the database to archive. That data better never make it back into the database. This is for archival…not just moving data.

Absolute show stopping nightmare. I have consulted for clients who insisted we shrink the database on a regular basis. They would argue that a full disk makes the database unavailable and that we have to shrink the database files to reclaim space. In my Comprehensive Database Performance Health Check , we can work together remotely and resolve your biggest performance troublemakers in less than 4 hours.

Once you learn my business secrets, you will fix the majority of problems in the future. Leave new Jerry Hung. Hi, Pinal I used to read your article always, they are very valubale in several ways.

Can we compress the bak file thorugh sql 2k5? Or if any other way to compress the. Anup Das. Hi Ashutosh, Just thought to reply to this as Pinal will be busy with many activities. Thank You, Anup. You may find out that you cannot shrink the file - because the table still has that space allocated to the large binary column. This will show up as unused space in the database - but still allocated. Or, you could build a brand new table, copy the data from the old table to the new table and drop the old table.

How long for this process for shrinking 80GB to 3 GB? Can 2 hours finish? Any hints we can speed up this shrinking process? Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker. Regards, Basit A. This can be beneficial to other community members reading the thread.



0コメント

  • 1000 / 1000