今天鏡像中的主伺服器進行維護重啟,重啟後發現鏡像Disconnect,使用xp_readerrorlog 0, 1檢查錯誤記錄檔發現下列資訊:
Database mirroring connection error 5 'Connection handshake failed. The certificate used by this endpoint was not found: Certificate expired. Use DBCC CHECKDB in master database to verify the metadata integrity of the endpoints. State 85.'
前先以為是重啟導致了認證損壞,所以檢查了下主機和備機的認證是否存在:
select name, start_date, expiry_date
from sys.certificates
where name not like '##%'
檢查後發現主機的認證expiry_date時間是2011-01-01,而現在已經是13號了,可以得到一個結論,認證雖然到期但是如果鏡像沒有斷開的話認證還是可以持續使用,直到鏡像斷開。
於是認證替換,主機,重新建立新認證、修改endpoint並備份給備機:
use master
go
--principal_cert_new如果不進行endpoint刪除的話這裡需要新的認證名稱
create certificate principal_cert_new with subject = 'mirror',start_date='2012-01-01', expiry_date='2099-06-01'; --為N年後更換認證選個日子(6.1已過)
go
alter endpoint endpoint_mirroring
for database_mirroring (authentication = certificate principal_cert_new)
go
drop certificate principal_cert
go
backup certificate principal_cert to file = 'd:\certificate\principal_cert.cer';
備機,還原主機的認證並回複鏡像:
use master
go
create certificate principal_cert_new AUTHORIZATION mirror_user from file = 'D:\certificate\principal_cert.cer';
go
alter database mydb set partner resume