溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么處理SQLServer mirror宕機后error 9004異常

發布時間:2021-11-04 11:46:12 來源:億速云 閱讀:392 作者:iii 欄目:關系型數據庫

本篇內容主要講解“怎么處理SQLServer mirror宕機后error 9004異?!?,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么處理SQLServer mirror宕機后error 9004異?!卑?

異常:

一臺SQLServer 2008SP4 mirror server因為硬件問題宕機,修復重啟后就無法與principal主庫連上同步了

mirror error log中報錯:

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(主庫) error log 中報錯:

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.

處理:

嘗試重啟備庫mirror server后依然無法和主庫同步,只能從log分析,看到principal和mirror端log中都有error 9004報錯估計和這個有關,Resolve the error on the remote server and resume mirroring, or remove mirroring and re-establish the mirror server instance. 錯誤提示中的解決方法說的比較籠統,解決error可恢復mirror或者移除mirror重建。

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

只能在回到error 9004錯誤中找答案,查到官方一篇9004錯誤說明:

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

 

從文檔中看,應該是mirror的DB transaction log損壞導致不一致問題,而tran log的損壞也很可能與這此server硬件宕機有關,再次詳細查找mirror啟動時的error log發現果然是transaction log損壞導致

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損壞如何修復呢?

因為主庫中有設置每個15分鐘把tran log備份出來的job (full recovery mode下以免log過大不能重用的做法),

理論上講通過把主庫備份出來的日志到mirror端恢復應該就可以了,

劇吐操作:

1. 移除主備mirror partner關系,mirror端中執行:

alter database MESDB set partner off

2.copy principal主庫中的異常當天及之后產生的tran log到mirror端

3.通過以下執行結果可批量運用恢復tranlog(如果語法有報錯可以去掉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關系后,principal 和mirror端可以正常同步數據了

此時, mirror error 9004異常處理完成

到此,相信大家對“怎么處理SQLServer mirror宕機后error 9004異?!庇辛烁畹牧私?,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女