Skip to content

The transaction log for database is full. To find out why space in the log cannot be reused see the log_reuse_wait_desc column in sys.databases

October 27, 2011

We replicate our production database every morning for reporting and testing purposes. Every once in a while, replication eats away at our transaction log file. I haven’t figured out the reason, and I haven’t done much research either, but I fix it with the code below.

--Step 1 - Check if database is in 'Replication' state
SELECT name, log_reuse_wait_desc
FROM sys.databases
WHERE name = 'database name here'

--Step 2 - Disable Replication
exec msdb..sp_update_job @job_name = 'name of job here' , @enabled = 0

--Step 3 - Stop Replication
exec sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1

--Step 4 - Set database to Simple Recovery mode
ALTER DATABASE [database name here]
SET RECOVERY SIMPLE

--Step 5 - Shrink log file to 1 GB
DBCC SHRINKFILE('log file name here', 1024)

--Step 6 - Set database back to Full Recovery mode
ALTER DATABASE [database name here]
SET RECOVERY FULL

Advertisement
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.