SQL SERVER的事物日志傳送(log shipping)功能,相信很多人都使用過或正在應用,這是MS SQL提供的一個非常強大的功能,一般需要一個主數據庫服務器(primary/production database server)和輔助數據庫服務器(standby server)來完成這個配置,默認情況下,主數據庫和輔助數據庫的版本應該是一致的,那么如果這兩個數據庫版本不一致,會不會有什么問題?還能做log shipping配置嗎?
那么數據庫版本不一致分兩種情況:
1: 類似於MS SQL 2005 64 bit SP4 與MS SQL 2005 SP3 32 bit這樣的版本差別
2: 完全不同的版本,例如MS SQL SERVER 2005 和 MS SQL SERVER 2008.
可能有人就要吐槽了,為啥要搞成不同的版本呢,這不是自己沒事找事做嗎?出現這種情況,真是一言難盡,歷史的問題.....等等,你叫我怎么吐槽呢?好了,咱們就不糾結這些雞毛蒜皮的事情了,現在回到上面的問題上來。
至於第一種情況,完全可以做log shipping,不存在什么問題,我做了兩個這樣的案例,都配置成功,而且工作的好好的。
案例1的環境:
數據庫服務器 |
版本信息 |
主數據庫服務器 |
Microsoft SQL Server 2005 - 9.00.5000.00 (Intel X86) Dec 10 2010 10:56:29 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2) |
輔助數據庫服務器 |
Microsoft SQL Server 2005 - 9.00.5000.00 (X64) Dec 10 2010 10:38:40 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) |
案例2的環境:
數據庫服務器 |
版本信息 |
主數據庫服務器 |
Microsoft SQL Server 2005 - 9.00.4000.00 (Intel X86) Dec 10 2010 10:56:29 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2) |
輔助數據庫服務器 |
Microsoft SQL Server 2005 - 9.00.5000.00 (X64) Dec 10 2010 10:38:40 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) |
第二種版本不同的情況,也要細分多種不同情況:
1: 主數據庫服務器為SQL SERVER 2008, 輔助數據庫服務器為SQL SERVER 2005, 對於這種情況,這是完全行不通的,因為你在SQL SERVER 2008上的備份,不能在低版本SQL SERVER 2005上還原(當然更低的版本也是如此),以此類推,Primary Server is SQL 2012 Std and Secondary Server is SQL 2008 R2 Std 這種情況也是行不通的。
2:主數據庫服務器為SQL SERVER 2005, 輔助數據庫服務器為SQL SERVER 2008R2,對於這種情況,log shipping部署時,你選擇Standby Mode時,就會報錯:
相關出錯信息:System.Data.SqlClient.SqlError: This backup cannot be restored using WITH STANDBY because a database upgrade is needed. Reissue the RESTORE without WITH STANDBY. (Microsoft.SqlServer.Smo)
所以你只能選擇No Recovery mode選項,至於這個就有點雞肋了。關於上面出錯的原因,下面這段解釋非常清晰,明了(出處請見下面參考資料):
Each version of SQL Server has a database version number; for SQL 2000 it is 8, SQL 2005: 9 and SQL 2008: 10. When a database backup that came from a lower SQL Server version is restored, SQL Server will run an upgrade process to bring that older database version up to the database version supported by the new instance. This process is run automatically as part of SQL Server’s recovery process. The recovery process itself is certain operations that need to happen to ensure the database is in a consistent state for user access (roll-forwards and roll-backs etc).
Placing a database in “Standby/Read Only” mode instructs SQL Server to recover the database after each restore, but also create a special standby file that contains information which will allow this recovery to be undone when it is time to do additional transaction logs restores.
However unfortunately, once a database has been upgraded it cannot be undone. This is why if you try and use the “Standby/Read Only” option when restoring a database of an older version SQL Server fails with
Msg 3180, Level 16, State 1, Line 1
This backup cannot be restored using WITH STANDBY because a database upgrade is needed. Reissue the RESTORE without WITH STANDBY.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
This error message essentially says you cannot bring an older database version online in “Standby/Read Only” mode.
But you can restore transaction logs and log shipping from an older database version to a newer database version when you keep the database offline. This is because the recovery (and upgrade process) for the database is deferred until the point you do actually bring the database online. This means you can log ship from an older version of SQL Server to a newer version until the point you bring that database online for user access.
翻譯如下(水平有限,僅供參考):
每一個版本的SQL Server數據庫都有相應版本號;例如SQL 2000是8,SQL 2005是9,SQL2008:10。當數據庫恢復一個從較低的SQL Server版本的備份時,SQL Server將執行一個升級過程,把那個舊的數據庫版本升級到新實例支持的版本。這個過程是SQL Server的恢復過程中自動運行的一部分。恢復過程本身就需要某些操作發生,以確保數據庫處於一致的狀態向前回滾,向后回滾等)。
把數據庫置於“待機/只讀”模式不僅會指示SQL Server的每次還原后恢復操作,還會創建一個特殊的備用文件,當它做其他事務日志恢復時,包含的恢復撤銷時的信息。
然而不幸的是,一旦數據庫已經升級,它不能被撤消。這就是為什么如果你嘗試使用“待機/只讀”選項時,舊版本的SQL Server數據庫恢復失敗的原因
Msg 3180, Level 16, State 1, Line 1
This backup cannot be restored using WITH STANDBY because a database upgrade is needed. Reissue the RESTORE without WITH STANDBY.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
這個錯誤消息本質上是說,你不能把一個舊的數據庫版本設置為聯機在“待機/只讀”模式下。
但是你可以從一個舊的數據庫版本還原事務日志和日志傳送到一個新的數據庫版本,當你保持數據庫脫機。這是因為,為數據庫的恢復(升級過程中)被推遲,直到點你確實使數據庫聯機。這意味着您可以登錄到一個新的版本,直到從舊版本的SQL Server用戶訪問您帶來的聯機數據庫。
參考資料:
[http://www.askthedbas.com/ask-the-dbas/2010/08/warm-standby-on-sql-server-2008-with-log-shipping-from-sql-server-2005.html]
[http://community.spiceworks.com/topic/316934-mirroring-and-log-shipping-with-different-sql-versions]
[http://technet.microsoft.com/zh-cn/library/bb895393(v=sql.105).aspx]