欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MS SQL 事物日志传送能否跨数据库版本吗?

程序员文章站 2022-05-20 12:25:43
...

SQL SERVER的事物日志传送(log shipping)功能,相信很多人都使用过或正在应用,这是MS SQL提供的一个非常强大的功能,一般需要一个主数据库服务器(primary/production database server)和辅助数据库服务器(standby server)来完成这个配置,默认情况下,主

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时,就会报错:

MS SQL 事物日志传送能否跨数据库版本吗?

相关出错信息: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.

翻译如下(水平有限,仅供参考):