Recently one of my clients contacted me to provide them assistance in finding and fixing the cause of a huge transaction log file. There are many caused to get error 9002 in SQL Server ERRORLOG. In this blog, I would explain the cause and fix of error: The transaction tog for database ‘SQLAuthority’ is full due to ‘REPLICATION’.
I joined a call with them and ran a few queries to know the state of the database. I always start with the below query.
SELECT name, log_reuse_wait_desc FROM sys.databases where name = 'Database_Name'
Here is the complete list as of today from books online. Here are the various values which can be seen in log_reuse_wait_desc in sys.databases catalog view.
- NOTHING
- CHECKPOINT
- LOG_BACKUP
- ACTIVE_BACKUP_OR_RESTORE
- ACTIVE_TRANSACTION
- DATABASE_MIRRORING
- REPLICATION
- DATABASE_SNAPSHOT_CREATION
- LOG_SCAN
- AVAILABILITY_REPLICA
- OLDEST_PAGE
In my client’s case, I was seeing “REPLICATION”.
When I queried sys.databases to know about replication using the following query:
SELECT [is_published] ,[is_subscribed] ,[is_cdc_enabled] FROM sys.databases WHERE name = 'Database_Name'
I saw this
That was weird! Based on my discussion with them at some point they did try to do a replication. They created a publication but no subscription. When I checked, I found that the log reader job was not running. That explains the cause of the full transaction log.
Fundamentally, SQL Server would keep the data in the transaction log and won’t allow truncation until data is replicated or picked by Log Reader Agent. You may run into the same issue as there are errors encountered by the log reader agent job.
WORKAROUND/SOLUTION – Full Due to Replication
Since there was no subscriber configured, they were confident enough that we should remove it and it won’t break anything. We attempted to use SQL Server Management Studio to drop the publication, but it was taking a long time. Finally, it got removed but we were still seeing REPLICATION wait. I also used sp_removedbreplication to clean it up. After that, I took transaction log backup and checked log_reuse_wait_desc and it was NOTHING.
After that, I was able to shrink the log file. Here is one of my earlier posts which has a script to shrink the log file of all databases.
DECLARE @ScriptToExecute VARCHAR(MAX); SET @ScriptToExecute = ''; SELECT @ScriptToExecute = @ScriptToExecute + 'USE ['+ d.name +']; CHECKPOINT; DBCC SHRINKFILE ('+f.name+');' FROM sys.master_files f INNER JOIN sys.databases d ON d.database_id = f.database_id WHERE f.type = 1 AND d.database_id > 4 -- AND d.name = 'NameofDB' SELECT @ScriptToExecute ScriptToExecute EXEC (@ScriptToExecute)
Well, this is how we fixed the Error 9002: The Transaction Log for Database ‘SQLAuthority’ is Full Due to ‘REPLICATION’.
Have you seen such an unexplained situation with SQL Server? Please comment and let me know.
Reference: Pinal Dave (https://blog.sqlauthority.com)
First appeared on SQL SERVER – Error 9002: The Transaction Log for Database ‘SQLAuthority’ is Full Due to ‘REPLICATION’