背景:今天檢查一個伺服器上執行個體中鏡像資料庫的狀態,發現主庫這邊所有被鏡像的資料庫的狀態均為:Principal/Disconnected,而從庫那邊除了鏡像資料庫Tfs_TFS2005Collection 之外,其他鏡像資料庫的狀態為Mirror/Recovering/Pending.
處理方法:第一步:首先檢查兩邊資料庫伺服器是否可以相互Ping---確認OK第二步:相互telnet 資料庫監聽連接埠(我們這裡使用1433)----確認OK第三步:相互telnet資料庫鏡像端點的連接埠(我們這裡使用5022)-----確認OK第四步:在主執行個體和鏡像執行個體上重啟資料庫鏡像所使用的端點:
use master
GO
alter endpoint Endpoint_Name state = stopped;
GO
alter endpoint Endpoint_Name state = started;
GO
之後除開A資料庫之外,其他資料庫鏡像恢複正常.
之後開始解決Tfs_TFS2005Collection 資料庫鏡像的問題.Tfs_TFS2005Collection 鏡像資料庫之前的狀態不是Mirror/Recovering/Pending,而是類似於正常資料庫那種(後面不包含任何狀態),但是當我們訪問這個資料庫的時候,提示該資料庫不能被訪問.
執行select * from sys.databases中該資料庫的state_desc為Recovery_Pending.也就是說該資料庫的Recovering被阻擋.
查看鏡像資料庫中的資料庫日誌:
Unable to open the physical file "D:\DATA\Tfs_TFS2005Collection\LOG\TfsVersionControl.LDF". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
A file activation error occurred. The physical file name 'D:\DATA\Tfs_TFS2005Collection\LOG\TfsVersionControl.LDF' may be incorrect. Diagnose and correct additional errors, and retry the operation.
之後嘗試了以下的方法:
另外,已經嘗試了的方法有如下:
1:alter database Tfs_TFS2005Collection set partner resume------無效
2:
alter endpoint endponitname state=stopped
alter endpoint endponitname state=started -----無效
3:ALTER DATABASE Tfs_TFS2005Collection SET PARTNER='TCP://Principal:5022'---無效
並且報錯
Msg 945, Level 14, State 2, Line 1
Database 'Tfs_TFS2005Collection' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.我們發現Tfs_TFS2005Collection資料庫的資料檔案和記錄檔居然可以被複製,在正常情況下,移動一個online資料庫的資料檔案和記錄檔是會報錯的(提示該檔案被佔用,不能被複製或者移動).後來採用ProcessExplorer來檢查是什麼程式在佔用Tfs_TFS2005Collection資料庫的資料或者記錄檔,也沒有任何返回結果.最後只得重啟鏡像執行個體的伺服器,啟動之後,檢查資料庫Tfs_TFS2005Collection的鏡像恢複正常.奇異的事件.懷疑是OS由於某種不得而知的原因不能訪問到Tfs_TFS2005Collection資料庫的資料和記錄檔,然後導致鏡像失敗.