茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1671374 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_00097.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2016/11/12 7:15:32
MSSQL 2016 的 Transaction Log 檔(ldf)爆炸(或爛掉了)怎麼辦!?

1.請先確認你的 mdf 還完整!(冷日作法是馬上 Shutdown SQL Server 把 mdf 檔複製一份出來

2.然後回去對你的 SQL Server 進行修復!步驟如下:
I.進入 Single Mode
Using SQL Server Management Studio
To set a database to single-user mode
In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
Right-click the database to change, and then click Properties.
In the Database Properties dialog box, click the Options page.
From the Restrict Access option, select Single.
If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes.
Using Transact-SQL
To set a database to single-user mode
Connect to the Database Engine.
From the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute. This example sets the database to SINGLE_USER mode to obtain exclusive access. The example then sets the state of the AdventureWorks2012 database to READ_ONLY and returns access to the database to all users.The termination option WITH ROLLBACK IMMEDIATE is specified in the first ALTER DATABASE statement. This will cause all incomplete transactions to be rolled back and any other connections to the AdventureWorks2012 database to be immediately disconnected.
USE master;
GO
ALTER DATABASE {yourDataBaseName}
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO

II.修復你的 ldf 檔
EXEC(‘ALTER DATABASE [{yourDataBaseName}] SET EMERGENCY’);
DBCC checkdb ({yourDataBaseName}, repair_allow_data_loss);

III.恢復正常(Multi)模式
GO
ALTER DATABASE {yourDataBaseName}
SET MULTI_USER;
GO


3.上述步驟如果都順利執行的話,恭喜你,你應該已經救回你的資料庫了!

4.但有時就是沒那麼簡單,依照冷日本次碰上的狀況,是資料庫無法卸載也無法啟動,最多只能『離線』,一整個卡住!!!
所以冷日採取了比較極端的作法:
A.先把 SQL Server 停掉,然後把 mdf 檔搬走
B.重新啟動 SQL Server,因為原本的資料庫檔案本體不存在,所以資料庫會直接顯示錯誤後消失!
C.此時在把 SQL Server 停掉,去到原本資料夾確認所有相關檔案都清空(就是以資料庫名稱命名的檔案都刪掉
D.再回去啟動 SQL Server,此時因為原資料庫已經沒有掛載在上面,應該沒有錯誤訊息順利啟動了!
E.重建一個和原本資料庫同名的資料庫!(這很重要,一定要名稱一模一樣喔
F.把 SQL Server 再次停掉,然後把我們步驟 A 所搬出去的 mdf 檔再複製回來新建立的資料庫檔案位置(Windows 應該會問你是否覆蓋,當然是覆蓋!
G.啟動 SQL Server 並執行下列語法:
USE master;
GO
ALTER DATABASE {yourDataBaseName}
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
EXEC('ALTER DATABASE [{yourDataBaseName}] SET EMERGENCY');
GO
DBCC checkdb ('{yourDataBaseName}', repair_allow_data_loss);
GO
ALTER DATABASE {yourDataBaseName}
SET MULTI_USER;
GO

H.靜待 SQL Server 幫你把 mdf 檔檢查並修復,同時也會把新的 ldf 給搞定,都完成之後,應該就回到慘案之前的狀態了

祝大家順利!

參考資料:
MSDN : Set a Database to Single-user Mode
MSDN : Start SQL Server in Single-User Mode
Manvendra's blog: Error Msg 1813, Level 16, State 2, Line 1, Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|