Automatic shrink file

  • Dear All,

    I wanted to create a job in SQL which would automatically shrink a Transactional log file or files when the transactional log backup gets to a particular size please?

    Thank you in advance!

  • tt-615680 (6/24/2014)


    Dear All,

    I wanted to create a job in SQL which would automatically shrink a Transactional log file or files when the transactional log backup gets to a particular size please?

    Thank you in advance!

    Create a job for each 2 hours or so based on your business process and check the trans log size when it grows to particular size the job will run the shrink command based on your size

    something like

    get the @size =(log size )%

    if (@size>90%)

    begin

    Shrink trans log

    End

  • Don't do this. It just wastes resources and causes fragmentation. If your log files are getting large, then back up your transaction log more frequently. Bear in mind that your log file(s) need to have at least enough space for your largest single transaction.

    John

  • I agree with John Mitchell.

  • Don't do that.

    If your log it growing over and over again, you need to determine why it's growing. Deal with that cause. Set the log to an appropriate size. Make sure you have log backups in place. Manage the log space appropriately[/url].

    Don't set up automatic shrinking. It's not the right way to get the job done.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Please don't do that. Horrible practice.

    If you manage the log properly, you won't need to shrink it. Please take a read through http://www.sqlservercentral.com/articles/Administration/64582/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply