• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

Purge the log file of a SQL 2012 database

I have a database with 100MB of data and 76GB of log transactions.  How do I reduce the log file to a reasonable size?
  • 2
  • 2
1 Solution
Run a backup on the database. Make sure you have a regular transaction log backups..
Backup the transaction log.
Use shrink to reduce,

Use dbcc opentran(databasename)

To see if there is an active transaction that is preventing the shrinking of the file.

You can use dbcc shrinkfile, with trunk.
Change the database mode to simple and shrink the file. Then reset.
compuzak1Author Commented:
Is there a clean way to reduce the size of the log through the Sql Server Management Studio?  I don't need the logs or the log data, so I don't need to back it up unless the backup also does a purge.

Ideally, I would like to keep about a month of transactions and have it automatically purge.
The backup closes all completed transactions freeing up space within the log binary file.
Using ssms right clck on the DB, tasks, shrink files, switch to the log and it will tell you how much is in use and that is the minimum account to which the transaction log can be shrunk.

After shrinking, make sure you limit the size of the transaction log. If you do not need to recover the transactions for the recovery/restore, change he recovery model to simple from full.
Anthony PerkinsCommented:
I don't need the logs or the log data, so I don't need to back it up unless the backup also does a purge.
Perhaps you are not aware, but the transaction log in an integral part of the database, so saying you "don't need the logs or the log data" is like saying you don't care about your data.

If you are unwilling or unable to make frequent transaction log backups, then change the database Recovery Model to Simple (you will lose the possibility of point-in-restores):

Once you have done that, then do the following (this should only be done on an emergency basis, never schedule it):
USE YourDatabaseName
DBCC SHRINKFILE(2, 4000)                 -- 4000MB change appropraitely
compuzak1Author Commented:
Thanks for the assistance, we setup an automated backup and data mainteance plan and now the log file is very small and will maintain that size as we are backing up each night.  Previously we were backing up the entire server and not using the SQL database backup and maintenance features, which are obviously a much better solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now