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?
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.
Ideally, I would like to keep about a month of transactions and have it automatically purge.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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.
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.