Pergunta

I have to shrink a database of approx. 1TB down to around 700GB (which is leaving 200+ Gb for growth without expansion). I have a script that will loop and shrink the database by a set increment (1GB, for example). This is very helpful in case you had to abort at any time, because progress is not lost, the total shrink operation may run for 4-5 days. The question is, will the shrinking of the database file in incremenets vs. one shot (one dbcc shrinkfile executed) result in more fragmentation or not? Thanks!!

Foi útil?

Solução

(This is based on MS SQL Server. Your mileage may vary with other RDBMSes.)

If all else were equal, I suspect that you would not incur greater fragmentation by, err, fragmenting your shrinking process. When files are shrunk, SQL may have to move data about internally, from pages that will be removed to empty pages that will not be removed. It seems likely that if blocks A, B, and C would be moved to X, Y, and Z and then expunged from the database file, then doing it in three steps would generate as much fragmentation as doing it in three steps.

The problem I see happening is, what if you first "shrunk out" block A, and before you started work on block B, more data got loaded, causing the database to store data in block D -- a section that was previously empty and targeted for eventual shrinkage? Worse, what if the addition of new data required the recreationg of block A, which you'd then have to shrink all over again?

This is a high-level attempt to describe something I only know the look-and-feel of. I suspect that multiple shrinkings could generate more fragmentation, if only because of additions to the database between the shrink sessions. The fewer sessions you have, the better off you probably are.

Outras dicas

Please refer to below links for more detailed insight on " Why you should NOT SHRINK your database or Dont press the shrink button "

http://www.sqlskills.com/BLOGS/PAUL/post/Why-you-should-not-shrink-your-data-files.aspx http://sqlinthewild.co.za/index.php/2007/09/08/shrinking-databases/

HTH, \K

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top