Execute sql without writing on transaction log

  • Hi,

    I need to execute a script which implies many writes on the transaction log. In the truth I don't think I need to keep such information, since the query reorganizes and rebuilds indexes (I'm I wrong thinking it is not useful to register the activity on t-log? I'd schedule the script just after the schedule of backup full of the database).

    The matter is that, scheduling the sql at night time, there is the possibility that the transaction log gets full. Also, I could run a backup of transaction log before and after the query, and configure an appropriate max size for the transaction log file, or is there the possibility to execute the sql without writing only its activity on transaction log (keeping the full option)?

    Thanks in advance for your reply.

    sb

  • Nope, everything is written to the transaction log. Even index rebuilds. This is so if they fail in the middle, they can be rolled back and maintain an intact index.

  • Unless you change the ricovery model and then run your reindex (buts it is not advisable).

    Why is this an issue? Do you not have enough disk space?

    Adam Zacks-------------------------------------------Be Nice, Or Leave

  • Schadenfreude-Mei (1/12/2011)


    Unless you change the ricovery model and then run your reindex (buts it is not advisable).

    It's logged regardless of the recovery model. Minimally logged in recovery models other than full, but still logged.

    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
  • True but from the posters first post it seems they are worried about log filling (and presumably subsiquent growths) during the night.

    Adam Zacks-------------------------------------------Be Nice, Or Leave

  • If it is subsequent actions, you would schedule a few log backups to clean it up. The reindex will be one large logged operation.

  • Schadenfreude-Mei (1/12/2011)


    True but from the posters first post it seems they are worried about log filling (and presumably subsiquent growths) during the night.

    Index rebuilds can and do grow the log in simple recovery.

    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
  • but u can shrink it without getting back up !

    GilaMonster (1/12/2011)


    Schadenfreude-Mei (1/12/2011)


    True but from the posters first post it seems they are worried about log filling (and presumably subsiquent growths) during the night.

    Index rebuilds can and do grow the log in simple recovery.

  • after ur rebuild index/reorganize, you scheduled shrink database log then after take a full database backup

  • naresh.talla (1/13/2011)


    after ur rebuild index/reorganize, you scheduled shrink database log then after take a full database backup

    I have a few question here..

    1. will shrinking always shrink your log file even if it is in use?

    2. Why to run a full backup after the shrinking log process?

    So far i know,You need to take a full\Differential backup only if you Truncate your log file but shrinking never truncates your log file it only tries to reclaim the unused portion of your log file for Os.

    And log file can only be shrunk if it is not is use ..

    use dbcc sqlperf('logspace') command to know how much % of your log file is in use.

  • sachnam (1/13/2011)


    1. will shrinking always shrink your log file even if it is in use?

    No, and repeatedly shrinking logs is not recommended.

    2. Why to run a full backup after the shrinking log process?

    Because too many people think that shrink log breaks the log chain. It does not. Hence no backup is required.

    Hmmm... maybe another blog post topic here...

    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
  • Thanks for replies,

    as Adam says, the only thing I was 'worried' about is the possibility to fill the transaction log during night, and cause disases to users (Hospital databases).

    The test I made yesterday took about 5 Gb of transaction log, for a 4 Gb database. Usually I configure max size of autogrowth to 2 Gb for transaction logs, since during the day more backups are scheduled to keep the files empty.

    I'm analyzing db per db to opportunely plan the job for rebuild and reorganize the indexes. After the first run of the job (which rebuilds if fragmentation > 60%, else reorganizes, if frag >10% and <60%), next executions reguard a less number of indexes, and only reorganizes.

    So, the problem would be only at the first execution, or in particular cases. I can plan it at morning and monitor.

    To reciprocate your replies, I post the sql for managament of indexes, which I found on a blog and seems to be appropriate.

    http://blogs.msdn.com/b/joaol/archive/2008/01/28/script-to-rebuild-and-reorganize-database-indexes-sql-server-2005.aspx

    Best regards, sb

  • First, I'd recommend you use this maintenance script. Lots of expert DBAs have reviewed it and they like it: http://sqlfool.com/2009/06/index-defrag-script-v30/

    Second: This is not necessarily good advice.

    after ur rebuild index/reorganize, you scheduled shrink database log then after take a full database backup

    If you need 5GB of space in the log for an index rebuild, then if you shrink it after the rebuild, what happens to that space? You can use it, but not permanently since you'll then reuse it when you rebuild again. So what's the point of shrinking? The log file needs what it needs for your system, and you should not try to micromanage that to the minimum it needs at any one time. Set it to the level it needs and monitor to see if needs change.

    You want your log to run well, so consider this advice: http://www.sqlskills.com/blogs/kimberly/post/8-Steps-to-better-Transaction-Log-throughput.aspx

    Third, don't schedule log backups to manage the size of the log. Schedule log backups based on your needs for data loss and recovery.

  • Steve Jones - SSC Editor (1/13/2011)


    First, I'd recommend you use this maintenance script. Lots of expert DBAs have reviewed it and they like it: http://sqlfool.com/2009/06/index-defrag-script-v30/

    Steve (and all),

    There's a newer version of that here http://sqlfool.com/2010/04/index-defrag-script-v4-0/

  • Many thank for the scripts and replies.

    Steve you're perfectly right, saying 'Schedule log backups based on your needs for data loss and recovery.'

    I was considering only space aspects while writing, as you say I use to plan backups for data loss needs.

    Regarding the space of transaction log, only the first execution of the sql takes a large amount of space, since once it's regularly schedulded, there would be non more need to rebuild and reorganize as many indexes as the first time.

    all times I read about transaction log managing I have some doubts, can you telle me please the exact difference between truncating log and shrinking? It has happened that a big transaction log, emptied by the backup, didn't reduce its space after shrinking. Was it because the tail contained transactions not jet committed?

    Still thanks, sb

Viewing 15 posts - 1 through 15 (of 17 total)

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