5

I have an .mdf file from distribution database which is growing. I know the advantages and disadvantages of shrinking database/files. Is it okay to shrink the .mdf file to some a smaller size. Is there any data loss during this time and does this affect the replication.?

  • 1
    There would not be any data loss. – Shanky Jun 12 at 13:37
  • @Shanky : This is the distribution database i am talking about and does this affect transactional replication i have in place? – user9516827 Jun 12 at 13:44
  • 1
    Shrinking may slow things but would not cause any loss. Do it when load is relatively very less – Shanky Jun 12 at 13:45
3

You need to check WHY the distribution database is growing rather than trying to shrink. If there is no available free space inside the file then you will not be able to shrink it anyway.

Check for the retention period and any other reasons why the distibution database would be growing e.g. Replication is erroring out.Below blog would give some areas you can look into :

Distribution database growth

Answering your question exactly : Yes you can shrink the file ,given it has free space available.

  • I have error in replication monitor in one of publisher/subscriber.The issue is on Distributor to subscriber.So i am trying to figure it out.Meanwhile can i turn off the Distribution agent so that the MSRepl_Commands don't get filled.? – user9516827 Jun 12 at 14:12
  • 1
    If you Stop Distribution agent, the log reader agent will still keep pushing data to for Distribution. You should stop the replication all together and check out for the actual issue. Once found,fix and re-enable. – Ramakant Dadhichi Jun 12 at 14:49
  • I understand what you are saying.I checked and MSRepl_Commands have 422 millions records.If i run the sp EXEC dbo.sp_MSdistribution_cleanup @min_distretention = x, @max_distretention = y and if it removes the commands from the MsRepl_Commands table,then i would loose the changes that needs to be applied to subsciber since i have error in replication.Am i right? – user9516827 Jun 12 at 14:56
  • 1
    sp_MSdistribution_cleanup is more of a retention thing. So it deletes things which have been replicated (distributed) to subscriber. – Ramakant Dadhichi Jun 12 at 15:14
  • One final question: If i disable the replication and enable it after a day ,do i loose all those transactions in between.? – user9516827 Jun 12 at 15:18
3

It is ok to shink the datafile, there WON'T be any data loss.

The "issues" when shrinking could be performance, during the rellocation of data pages. Also if you know that your DF will grow again to the same size, shrink is not recommended. If it was because a one time only operation, or other stuff where the DF won't grow at the same big size again, it is ok to perform your shrink operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.