I've got a large db (called Navision4) which currently has 2 log files:

Navision4_Log Navision4_Log3

There was a log called Navision4_Log2, but i managed to remove this.

Navision4_Log is located on the C:\ drive - and is not used. Navision4_Log3 is located on the G:\ drive - but is huge - and this appears to be where all transactions are written.

However, I want to remove one, leaving just one log file.

How should I do this? I tried to remove Navision4_Log - but got:

Error 5020: The primary data or log file cannot be removed from a database

link|improve this question

57% accept rate
feedback

2 Answers

What recovery model is your database using? are you taking regular log backups? If your in full recovery & not taking log backups, then this may explain why Navision4_Log3 is so large. You should fix this by either taking log backups, or switch to simple recovery.

I would move Navision4_Log to the G drive rather then try to remove it. My guess is that Navision4_Log3 exists because the server was running out of space on C: & the admin didn't know how to move it.

To move the log file to G: use the following:

ALTER DATABASE Navision4 SET OFFLINE;
--move log file to G:
ALTER DATABASE Navision4
MODIFY FILE (
NAME='Navision4_Log',
FILENAME='G:\MSSQL\TLOG\Navision4_Log.ldf');
ALTER DATABASE Navision4 SET ONLINE;

EDIT:SQL Server 2000 doesn't support those options, so you'll have to use sp_detachdb & sp_attachdb, you can also detach & attach in the Enterprise Manager GUI. Just make sure you attach the db & specify the owner as sa.

Then you can remove Navision4_Log3 if you wish. What you'll need to do (if your in full recovery) is take a log backup, then shrink the log using DBCC SHRINKFILE('Navision4_Log3', EMPTYFILE) You may need to take several backups & do several shrinks before the file will empty out & then you should be able to remove it.

link|improve this answer
Thanks for this excellent answer... This DB is also a replication publisher - does this affect me detaching / re-attaching? – alex Nov 30 '09 at 11:04
no it shouldn't – Nick Kavadias Nov 30 '09 at 11:26
feedback

Since it is a replicated database, you will have to remove replication before detaching. SQL Server 2000 will not allow you to detach a replicated database.

After that Nick is correct, detach the database and reattach with only the only file you wish to use on the G:

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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