Feb
11
2013

The log cannot be rebuilt because the database was not clearly shutdown (Microsoft SQL Server, Error: 945)

Today found that soemone has delete log file of one of database and database was inaccessible, when tried to take it offline and then bring online received following error while bringing it online,

 

“Database cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details”

 

“The log cannot be rebuilt because the database was not clearly shutdown (Microsoft SQL Server, Error: 945)”

 


 

 

As we didn’t have any recent full backup of database as it is dev server hence we don’t have option to restore, only solution left is to rebuild log anyhow, to rebuild log found several solutions over forums, but best one is below as you need not to take bounce database server for it to work, use this only if you are fine if data loss occurs or you are sure that log file doesn’t has any uncommitted transactions,

 

— First run following alter command to rebuild log file,

 

ALTER
DATABASE [<db name>] REBUILD
LOG
ON (NAME=<db name>,FILENAME=‘<Full path with file name>’)

Go

 

–You will see following warning on completion of above command,

 

Warning: The log for database ‘KCMTest’ has been rebuilt. Transactional consistency has been lost. The RESTORE chain was broken, and the server no longer has context on the previous log files, so you will need to know what they were. You should run DBCC CHECKDB to validate physical consistency. The database has been put in dbo-only mode. When you are ready to make the database available for use, you will need to reset database options and delete any extra log files.

 

–Now you need to check the consistency of your database as if in case any uncommitted transactions were there in log then you might have data consistency issues, run following commands to first take database in emergency mode, then in single user mode and then execute DBCC command to repair the database with data loss,

 

ALTER
DATABASE KCMTest SET
EMERGENCY;

ALTER
DATABASE KCMTest SET
SINGLE_USER;

DBCC CHECKDB
(KCMTest, REPAIR_ALLOW_DATA_LOSS) WITH

NO_INFOMSGS, ALL_ERRORMSGS;

 

–Verify any error message above reports, if everything looks fine then run following to bring database in multi user mode,

 

ALTER
DATABASE KCMTest SET
MULTI_USER;

 

Now verify if everything looks fine.

 

Other useful references to fix such issues,

http://dba.stackexchange.com/questions/854/rebuilding-the-transaction-log (solution reference described above)

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76785 (if above doesn’t work then one solution is available on this forum)

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76613

http://www.dreamincode.net/forums/topic/58785-rebuilding-ms-sql-server-log-file/

http://www.sqlservercentral.com/Forums/Topic306817-146-1.aspx

Download PDF

About the Author: Nitin G

Indian born, trekker, biker, photographer, lover of monsoons. I've been working full time with SQL Server since year 2005 and blogs to post the content aquired during my research on new topics or fixing issues faced by me as a DBA while working in different kind of projects, hope some of my posts may helps others in SQLDBA community. Everything you read on my blog is my own personal opinion and any code is provided "AS-IS" with no warranties!

Leave a comment

Subscribe to this blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 260 other subscribers

Translate this blog!

EnglishFrenchGermanItalianPortugueseRussianSpanish

Calender

September 2020
M T W T F S S
« Nov    
 123456
78910111213
14151617181920
21222324252627
282930  

View Post by Categories

%d bloggers like this: