azure云数据库_Azure SQL数据库地理复制

azure云数据库

In this article, we will review how to set up Geo-Replication on Azure SQL databases. Geo-Replication is an Azure SQL database feature that allows you to create a readable secondary database in the same region or cross-region. We can failover to the secondary database in case of an outage for a long time on the primary database server. We can also use this feature to migrate a database from one server to another server in the same or cross region with minimal downtime. Geo-replication uses the Always-on feature to replicate committed transactions to the secondary database asynchronously.

在本文中,我们将回顾如何在Azure SQL数据库上设置地理复制。 地理复制是Azure SQL数据库功能,允许您在同一区域或跨区域中创建可读的辅助数据库。 如果主数据库服务器上长时间中断,我们可以故障转移到辅助数据库。 我们还可以使用此功能以最少的停机时间将数据库从相同或跨区域的一台服务器迁移到另一台服务器。 地理复制使用始终在线功能将提交的事务异步复制到辅助数据库。

Let us go step by step to configure Geo-Replication on an Azure database. In this demo, I am using Azure single database.

让我们一步一步地在Azure数据库上配置地理复制。 在此演示中,我正在使用Azure单一数据库。

在Azure SQL数据库上配置地理复制 (Configuring the Geo-Replication on Azure SQL database)

Log in to the Azure portal and navigate to SQL databases. Click on the Azure SQL database on which you are going to configure the Geo-Replication.

登录到Azure门户并导航到SQL数据库。 单击您要在其上配置地理复制的Azure SQL数据库。

Azure single SQL database

Click on the Geo-Replication tab in the database details page.

单击数据库详细信息页面中的“ 地理复制”选项卡。

Geo-Replication

Select the target region from the list of target regions shown. In this case, the primary database is located in West India and I selected the target region (secondary database region) as South India.

从显示的目标区域列表中选择目标区域。 在这种情况下,主数据库位于印度西部,我选择了目标区域(辅助数据库区域)作为南印度。

Click on the Target Server. All the available Azure database servers in the target region are shown in the list. Select one if you want to use an existing Azure database server or create a new Azure database server by clicking on Create a new Server. Enter the Azure SQL server name, admin login, and password. Click on Select and Ok.

单击目标服务器 。 目标区域中所有可用的Azure数据库服务器都显示在列表中。 如果要使用现有的Azure数据库服务器或通过单击创建新服务器创建新的Azure数据库服务器,请选择一个 。 输入Azure SQL服务器名称,管理员登录名和密码。 单击选择,然后单击确定

secondary server in geo replication

The Geo-Replication setup is progressing, and you can see it on the map. It shows a dotted line as shown in the below image when the setup is in progress. Once the setup is complete it shows a full line between the source and target regions.

地理复制设置正在进行中,您可以在地图上看到它。 进行设置时,它会显示一条虚线,如下图所示。 设置完成后,它将在源区域和目标区域之间显示一条完整的线。

map representation of geo replication

In the Geo-Replication page under the map, we can see the details of primary and secondary databases and the status of the database.

在地图下方的“地理复制”页面中,我们可以看到主要和辅助数据库的详细信息以及数据库的状态。

primary and secondary database in geo replication

We can also create Geo-Replication using below T-SQL script. The following T-SQL script should be executed on the master database at the Azure SQL primary server. Replace the database name and the secondary server name in the T-SQL script. If the database with the same name already exists on the secondary server, the below T-SQL script throws an error “The destination database name ‘ActiveGeoRepl’ already exists on the server

我们还可以使用下面的T-SQL脚本创建Geo-Replication。 以下T-SQL脚本应在Azure SQL主服务器上的master数据库上执行。 在T-SQL脚本中替换数据库名称和辅助服务器名称。 如果辅助服务器上已经存在具有相同名称的数据库,则以下T-SQL脚本将引发错误“ 服务器上的目标数据库名称'ActiveGeoRepl'已经存在

ALTER DATABASE AzureGeoRepl
ADD SECONDARY ON SERVER rbc2
WITH ( ALLOW_CONNECTIONS = ALL )

We can create up to four secondaries for each primary database. As the transactions are replicated asynchronously to the secondary database may lag the primary database at any point in time.

每个主数据库最多可以创建四个辅助数据库。 由于事务异步复制到辅助数据库,因此在任何时间点都可能落后于主数据库。

Geo-Replication supports only manual failover and the end-point connection must be changed in the application after the failover. The secondary must have the same firewall rules and the logins to run applications successfully without any discrepancies after the failover to the Azure SQL secondary database.

Geo-Replication仅支持手动故障转移,并且在故障转移后必须在应用程序中更改端点连接。 辅助节点必须具有相同的防火墙规则和登录名,才能在故障转移到Azure SQL辅助数据库后成功运行应用程序,而不会出现任何差异。

故障转移
(Failover
)

Execute the following T-SQL script for a planned failover which makes the secondary database online without data loss. This T-SQL script should be executed at the secondary server on the master database.

对计划的故障转移执行以下T-SQL脚本,该脚本可使辅助数据库联机而不会丢失数据。 此T-SQL脚本应在master数据库上的辅助服务器上执行。

ALTER DATABASE AzureGeoRepl FAILOVER

Once the above command is executed on the secondary server, it stops all the connections to the existing primary database, replicate all the transactions to the secondary database and make the secondary database online.

在辅助服务器上执行上述命令后,它将停止与现有主数据库的所有连接,将所有事务复制到辅助数据库,并使辅助数据库联机。

强制故障转移 (Forced Failover )

For a forced failover, click on the secondary database to which you want failover and click on Forced Failover. This will make your secondary database immediately online and start accepting connections. Forced failover may result in data loss.

要进行强制故障转移,请单击要故障转移到的辅助数据库,然后单击“ 强制故障转移” 。 这将使您的辅助数据库立即联机并开始接受连接。 强制故障转移可能会导致数据丢失。

Azure SQL Geo-Replication forced failover

Alternatively, we can use the following T-SQL script on the master database at the secondary server for a forced failover which immediately brings the secondary database online.

或者,我们可以在辅助服务器上的master数据库上使用以下T-SQL脚本进行强制故障转移,从而立即使辅助数据库联机。

ALTER DATABASE AzureGeoRepl FORCE_FAILOVER_ALLOW_DATA_LOSS

删除地理复制 (Removing Geo-Replication)

To remove Geo-replication on an Azure database, navigate to the database details page and click on Geo-Replication. Just under the map locate the secondary server and click on Stop Replication. Please refer to the below image.

若要删除Azure数据库上的地理复制,请导航到数据库详细信息页面,然后单击“地理复制”。 在地图下方,找到辅助服务器,然后单击“停止复制”。 请参考下图。

remove geo replication

Alternatively, you can also use the following T-SQL script to remove Geo-Replication between primary and secondary databases. This T-SQL script should be executed on the master database at the primary server.

或者,您也可以使用以下T-SQL脚本删除主数据库和辅助数据库之间的地理复制。 此T-SQL脚本应在主服务器上的master数据库上执行。

Replace the database and the secondary Azure SQL server name with yours.

用您的数据库和辅助Azure SQL服务器名称替换。

ALTER DATABASE AzureGeoRepl
REMOVE SECONDARY ON SERVER rbc

辅助数据库上的地理复制。 (Geo-Replication on a secondary database.)

In case we want to have more than four secondary databases for a given primary database, configure the Geo-Replication on a secondary database so that the secondary database itself will have another secondary database. Execute the following T-SQL script on the master database at the secondary server to create a Geo-Replication from a secondary database to another secondary database.

如果给定的主数据库要有四个以上的辅助数据库,请在辅助数据库上配置地理复制,以便该辅助数据库本身将具有另一个辅助数据库。 在辅助服务器上的master数据库上执行以下T-SQL脚本,以创建从辅助数据库到另一个辅助数据库的地理复制。

ALTER DATABASE ActiveGeoRepl
ADD SECONDARY ON SERVER rbc3
WITH ( ALLOW_CONNECTIONS = ALL )

结论 (Conclusion)

In this article, we explored how to create Geo-Replication on an Azure SQL database, how to manually do a planned failover without data loss and forced failover which may have a data loss. In case you have any questions, please feel free to ask in the comment section below.

在本文中,我们探讨了如何在Azure SQL数据库上创建地理复制,如何在没有数据丢失的情况下手动执行计划的故障转移以及可能会丢失数据的强制故障转移。 如果您有任何疑问,请随时在下面的评论部分中提问。

翻译自: https://www.sqlshack.com/azure-sql-database-geo-replication/

azure云数据库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值