Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a database which had mdf size of 350 MB and ldf size 4.9 GB 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. The recovery model is set to FULL.

Then i followed some steps:

When I run

dbcc SQLPerf(logspace) 

i found that logsize is 4932 MB and Log space used is 98.76% So large amount of (98%) of log is using now. Then I tried this command

use <databasename>  dbcc loginfo

Now almost all VLF has status 2 which means all are in use. then I tried to take log backup. After log backup also shrinking didnt reduce the size. Then i changed recovery model to simple and then tried shrinking.But this also didn't help. Also I checked for open transaction

dbcc opentran (database)

and found that no transaction is open now. So what is making the database which does not allow me to shrink the log size.How can i solve this?

share|improve this question
add comment

5 Answers

Read How to Shrink SQL Server log for an explanation how the circular nature of the log may prevent shrink after truncation. Is possible that you log's last LSN point into a VLF that is at the tail of the LDF. Counter intuitively you must advance the log, by generating log writes, to allow it to shrink.

share|improve this answer
    
But problem i encountered is different.Please see my answer below –  Navaneet Apr 30 '13 at 14:33
add comment

Steps for shrinking the log are going to be

Backup transaction log through either SSMS or T-SQL and then perform a shrink

commands for SSMS are under the tasks if you right click the database name

BACKUP LOG <Databasename> TO DISK N'<path\database_log.ldf';
GO

DBCC SHRINKFILE (<FileName>, <TargetSize>) WITH NO_INFOMSGS

You will probably have to do this multiple times

If there is a transaction or job blocking the action, use Activity monitor to identify the process and kill it, or use the SQL Agent job activity monitor to end the job.

source: http://support.microsoft.com/kb/907511

share|improve this answer
    
But problem i encountered is different.Please see my answer below –  Navaneet Apr 30 '13 at 14:33
    
Glad to hear you got it figured out, thanks for the update! –  Cougar9000 Apr 30 '13 at 14:51
add comment
up vote 3 down vote accepted

Here is answer for my own question. Run the below query to get information about log files.

select log_reuse_wait_desc from sys.databases where name = 'DBName' 

It will give output if there is any. I got following output.

og_reuse_wait_desc
REPLICATION

There was some replication related objects remaining the database even after removing the repliaction.

To remove the replication from the database "sp_removedbreplication " can be used.But it didn't work for us as replication was not active now and actually replication was removed long back.

The solution is import the database content to another database by using import option of sql server.

share|improve this answer
add comment

You need to create a backup first, dependent on the backup model that is set up for the database before you can shrink the database.

You can try running this:

USE <databasename>
GO

BACKUP DATABASE <databasename> TO DISK '<absolute path goes here>\<databasename>.bak';
GO

Or you can do that from SSMS and use the graphical tools available (see here for details: http://msdn.microsoft.com/en-us/library/ms187510.aspx)

Once you've backed up your database you can compress it. However, shrinking the database is not a good idea since heavy index fragmentation will occour and searching for data will become slow.

Hope this helps.

share|improve this answer
    
I know how to do backup and truncate the log and reduce log file size. But for this database i am having problem.I just ran query select log_reuse_wait_desc from sys.databases where name = 'dbname' and found that replication is causing the problem .But i dont have replication set on it. So how to remove the repliaction from this db which is shown in log reuse wait_desc? –  Navaneet Apr 30 '13 at 12:44
    
Which SQL Server version are you using? –  Toni Kostelac Apr 30 '13 at 12:58
    
Replication might be set as a Job, so open up the SQL Server Agent folder, and Expand the Jobs folder, check to see if there is a replication job set up and if so turn it off by right-clicking and selecting Stop job –  Toni Kostelac Apr 30 '13 at 13:01
    
If you are using SQL Server 2005 and up then sp_removedbreplication 'DB_NAME' will remove replication. For sql server 2000 .. refer to blogs.msdn.com/b/repltalk/archive/2010/11/17/… –  Kin Apr 30 '13 at 13:14
    
But problem i encountered is different.Please see my answer –  Navaneet Apr 30 '13 at 14:34
add comment

I have found that I have to perform 2 or 3 backups of both the database and the transaction log to get the transaction log to actually reduce in size. I have a database that was created with Full recovery model. Every night it performs backups of the database and the transaction log but inevitably the transaction log seems to continually grow over 2-3 weeks. When the remaining disk space gets to 1GB I will see that the transaction log is about 30GB. I followed the steps recommended by Microsoft and after the 4th or 5th iteration of backing up both the database and the transaction log the transaction log will finally release its extra space and shrink. Then I go back and delete the multiple backups I have created.

share|improve this answer
    
I think you are doing something wrong. If you take backup of log properly then unused log should be truncated. The commands given in my question may help you to solve the problem. –  Navaneet Jan 7 at 6:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.