Avatar of compuzak1
compuzak1 asked on

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?
Microsoft SQL Server

Avatar of undefined
Last Comment
compuzak1

8/22/2022 - Mon
arnold

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.
ASKER
compuzak1

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.
ASKER CERTIFIED SOLUTION
arnold

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Anthony Perkins

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):
ALTER DATABASE YourDatabaseName SET RECOVERY SIMPLE

Once you have done that, then do the following (this should only be done on an emergency basis, never schedule it):
USE YourDatabaseName
GO
CHECKPOINT
Go
DBCC SHRINKFILE(2, 4000)                 -- 4000MB change appropraitely
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
compuzak1

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.