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
Avatar of arnold
arnold
Flag of United States of America image

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.
Avatar of compuzak1
compuzak1

ASKER

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
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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
Avatar of compuzak1
compuzak1

ASKER

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

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo