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

Leave a comment
Subscribe to this blog via Email
Old Posts
- November 2017 (3)
- October 2017 (4)
- September 2017 (2)
- May 2017 (1)
- April 2017 (1)
- July 2016 (3)
- May 2016 (1)
- April 2016 (1)
- February 2016 (2)
- January 2016 (1)
- October 2015 (1)
- September 2015 (1)
- August 2015 (1)
- July 2015 (2)
- June 2015 (3)
- April 2015 (1)
- March 2015 (1)
- December 2014 (1)
- September 2014 (2)
- April 2014 (1)
- January 2014 (3)
- October 2013 (2)
- September 2013 (2)
- August 2013 (4)
- July 2013 (1)
- June 2013 (2)
- May 2013 (5)
- April 2013 (3)
- March 2013 (1)
- February 2013 (9)
- January 2013 (11)
- December 2012 (14)
- November 2012 (3)
- October 2012 (4)
- July 2012 (2)
- June 2012 (3)
- May 2012 (2)
- April 2012 (8)
- March 2012 (6)
- February 2012 (3)
- January 2012 (1)
- December 2011 (5)
- November 2011 (8)
- October 2011 (5)
- September 2011 (3)
- August 2011 (3)
- July 2011 (3)
- May 2011 (1)
- November 2010 (1)
Tags
Calender
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
« Nov | ||||||
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
View Post by Categories
Recent Articles
- Setting up Always ON Availability Group in Multi Subnet Cluster – Recommendations
- Configuring Replication with Always ON Availability Group
- Login failed for user ‘DOMAIN\COMPUTER$’. Reason: Could not find a login matching the name provided. [CLIENT: ]
- Modern Servicing Model (Service Pack and Cumulative Updates) for SQL Server 2017 and onwards
- Fix: SSMS 2012 opening Debug window when pressing F5