溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么處理SQLServer mirror宕機(jī)后error 9004異常

發(fā)布時(shí)間:2021-11-04 11:46:12 來(lái)源:億速云 閱讀:361 作者:iii 欄目:關(guān)系型數(shù)據(jù)庫(kù)

本篇內(nèi)容主要講解“怎么處理SQLServer mirror宕機(jī)后error 9004異?!?,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么處理SQLServer mirror宕機(jī)后error 9004異?!卑?

異常:

一臺(tái)SQLServer 2008SP4 mirror server因?yàn)橛布?wèn)題宕機(jī),修復(fù)重啟后就無(wú)法與principal主庫(kù)連上同步了

mirror error log中報(bào)錯(cuò):

Date  2020/5/2 上午 02:15:20
Log  SQL Server (Archive #3 - 2020/5/4 上午 11:55:00)

Source  spid17s

Message
Database mirroring will be suspended. Server instance 'SMESDBSTY' encountered error 9004, state 2, severity 21 when it was acting as a mirroring partner for database 'MESDB'. The database mirroring partners might try to recover automatically from the error and resume the mirroring session. For more information, view the error log for additional error messages.

Date  2020/5/2 上午 02:15:20
Log  SQL Server (Archive #3 - 2020/5/4 上午 11:55:00)

Source  spid17s

Message
An error occurred while processing the log for database 'MESDB'.  If possible, restore from backup. If a backup is not available, it might be necessary to rebuild the log.

principal(主庫(kù)) error log 中報(bào)錯(cuò):

Date  2020/5/4 下午 02:04:21
Log  SQL Server (Current - 2020/5/4 下午 05:45:00)

Source  spid19s

Message
'TCP://10.209.95.203:5022', the remote mirroring partner for database 'MESDB', encountered error 9004, status 2, severity 21. Database mirroring has been suspended.  Resolve the error on the remote server and resume mirroring, or remove mirroring and re-establish the mirror server instance.

Date  2020/5/4 下午 02:04:21
Log  SQL Server (Current - 2020/5/4 下午 05:45:00)

Source  spid19s

Message
Error: 1453, Severity: 16, State: 1.

處理:

嘗試重啟備庫(kù)mirror server后依然無(wú)法和主庫(kù)同步,只能從log分析,看到principal和mirror端log中都有error 9004報(bào)錯(cuò)估計(jì)和這個(gè)有關(guān),Resolve the error on the remote server and resume mirroring, or remove mirroring and re-establish the mirror server instance. 錯(cuò)誤提示中的解決方法說(shuō)的比較籠統(tǒng),解決error可恢復(fù)mirror或者移除mirror重建。

解決error 9004似乎無(wú)從下手,嘗試移除mirror partner關(guān)系再重新建立mirror關(guān)系還是不行,重新備份恢復(fù)建立的話工作又太大了。。

只能在回到error 9004錯(cuò)誤中找答案,查到官方一篇9004錯(cuò)誤說(shuō)明:

https://support.microsoft.com/en-ca/help/2015753/how-to-troubleshoot-error-9004-in-sql-server

Symptoms


An operation in SQL Server that needs to read or process the transaction log can fail with an error like the following if the transaction log is damaged:

Error: 9004, Severity: 21, State: 1.
An error occurred while processing the log for database 'mydb'.  If possible, restore from backup. If a backup is not available, it might be necessary to rebuild the log.

The State number can vary for this error and indicates what type of damage has occurred with the log. See the More Information section about State numbers.

In most cases, this error is just seen in the ERRORLOG or Windows Application Event Log with EventID = 9004 because the operation processing the log is not based on a direct user command (such as recovery running when the SQL Server Engine starts. In these situations this error is often seen with Error 3414). However, some queries such as ALTER DATABASE could require a processing of the log and therefore will see these errors. Since the error is Severity=21, the user session is disconnected.

Cause


Error 9004 is a general error indicating the contents of the transaction log are damaged. The reason for the log to become inconsistent are similar to any database corruption problem detected by the SQL Server Engine or DBCC CHECKDB. To find the cause for the damage of the log you should follow the similar techniques for database corruption including an analysis of possible hardware, filesystem, and/or I/O problems. See the Cause section of the following article for more information: How to troubleshoot database consistency errors reported by DBCC CHECKDB.

Resolution


You should restore from a known good backup to recover from this problem. It is possible that if the transaction log portion of a database backup or the transaction log backup itself has damaged transaction log contents, you can encounter an Error 9004 on RESTORE. In this situation, the transaction log in the backup is damaged.

If you cannot restore from a backup, you may be able to bring the database online by rebuilding the transaction log. You should carefully understand the ramifications of rebuilding the transaction log including the possible loss of transactional consistency in your database. To read about how to rebuild the transaction log, please see the section titled Resolving Database Errors in Emergency Mode in the SQL Server Books Online under the DBCC CHECKDB command

More Information


The SQL Server Engine performs logical checks on the consistency of the transaction log contents as it reads and processes it. Not all aspects of the log header, log blocks, and log records are checked. The State number provides more information on what type of failure was encountered when processing the transaction log:

  • State 1 = The log file header of the Virtual Log File (VLF) was damaged.  If a damaged log file header is encountered as part of starting up the database on service startup, you may only see Error 9004 in the ERRORLOG. The log file header is the first portion of each VLF in the log file. This is not the same as the file header or the first 8KB of the log file. If the file header of the the log file is damaged you will encounter Msg 5172 as with a database file header page corruption.

  • State 2 and 3 = A log block was invalid when performing recovery during RESTORE

  • State 4 through 12 = These are all various checks on log blocks when processing log records. These including parity, sector, and other logical checks on the consistency of the transaction log

 

從文檔中看,應(yīng)該是mirror的DB transaction log損壞導(dǎo)致不一致問(wèn)題,而tran log的損壞也很可能與這此server硬件宕機(jī)有關(guān),再次詳細(xì)查找mirror啟動(dòng)時(shí)的error log發(fā)現(xiàn)果然是transaction log損壞導(dǎo)致

Date  2020/5/2 上午 02:15:20
Log  SQL Server (Archive #3 - 2020/5/4 上午 11:55:00)

Source  spid17s

Message
An error occurred while processing the log for database 'MESDB'.  If possible, restore from backup. If a backup is not available, it might be necessary to rebuild the log.

tran log損壞如何修復(fù)呢?

因?yàn)橹鲙?kù)中有設(shè)置每個(gè)15分鐘把tran log備份出來(lái)的job (full recovery mode下以免log過(guò)大不能重用的做法),

理論上講通過(guò)把主庫(kù)備份出來(lái)的日志到mirror端恢復(fù)應(yīng)該就可以了,

劇吐操作:

1. 移除主備mirror partner關(guān)系,mirror端中執(zhí)行:

alter database MESDB set partner off

2.copy principal主庫(kù)中的異常當(dāng)天及之后產(chǎn)生的tran log到mirror端

3.通過(guò)以下執(zhí)行結(jié)果可批量運(yùn)用恢復(fù)tranlog(如果語(yǔ)法有報(bào)錯(cuò)可以去掉go再試)

select 'RESTORE LOG [MESDB] FROM  DISK = N'''
 + physical_device_name +''' WITH  FILE = 1,  NORECOVERY,  NOUNLOAD,  STATS = 10 '+char(13)+' go',backup_set_id,a.type,physical_device_name 
 from msdb.dbo.backupset a ,msdb.dbo.backupmediafamily as b 
where a.media_set_id=b.media_set_id 
and a.database_name='MESDB' 
and a.backup_start_date >'2020-05-02 12:00:00'

4.重新建立mirror partner關(guān)系后,principal 和mirror端可以正常同步數(shù)據(jù)了

此時(shí), mirror error 9004異常處理完成

到此,相信大家對(duì)“怎么處理SQLServer mirror宕機(jī)后error 9004異?!庇辛烁畹牧私猓环羴?lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI