HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Shrinking the log file does not reduce size

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
filethelogsizereducedoesshrinkingnot

Problem

I have a database which has a 350 MB data file (.mdf) and a 4.9 GB log file (.ldf). The recovery model is set to FULL.

When I try to shrink the log file, it's not shrinking.

I know shrinking a database is not good and it should not be done. But still i am trying to do it for shrinking the log file.

When I ran

DBCC SQLPerf(logspace)


I found that the log size is 4932 MB and Log space used is 98.76%!

Then I tried this command

USE ;
DBCC loginfo;


Now almost all VLFs are "status 2" which means all are in use.

I tried to take a log backup and then shrink the log file. Shrinking didn't reduce the size.

I changed the recovery model to SIMPLE and tried shrinking again, but this also didn't help.

I checked for open transactions

DBCC opentran (database);


and found that no transaction is open now.

What is stopping me from shrinking the log file? How can I solve this?

Solution

Here is the answer to my own question.

Run the below query to get information about the log file's reuse wait:

SELECT log_reuse_wait_desc
FROM sys.databases
WHERE name = 'DBName'


I got the following output:

log_reuse_wait_desc
-------------------
REPLICATION


There were some replication-related objects remaining in the database, even after removing the replication.

To remove the replication from the database, sp_removedbreplication can be used. But it didn't work for us as replication was not active at the time and actually replication had been removed long before.

The solution was to import the database contents to another database using the import option of SQL Server.

Code Snippets

SELECT log_reuse_wait_desc
FROM sys.databases
WHERE name = 'DBName'

Context

StackExchange Database Administrators Q#41215, answer score: 19

Revisions (0)

No revisions yet.