SQL 服务器 AlwaysON 从多个辅助设备读取
SQL Server AlwaysON read from multiple seconderies
我在我的一个环境中配置了永远在线。
SQL1 = Primary
SQL2 = Slave1 (readonly)
SQL3 = Slave2 (readonly)
我的问题:
我希望我的应用程序将从两个从服务器读取数据(例如 SQL2 和 SQL3,如果它们是从服务器而 SQL1 是主服务器)。
是否可行,如果可行,我是怎么做到的
我已经配置了路由表,例如:
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL1' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL1.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL2' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL2.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL3' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL3.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL1' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL2',N'SQL3')))
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL2' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL1',N'SQL3')))
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL3' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL1',N'SQL2')))
GO
10倍
您需要创建一个侦听器。它是一个虚拟网络名称,客户端可以连接到该名称以访问 Always On 可用性组的主要或次要副本中的数据库。
在此处阅读有关 AG 的更多信息 https://msdn.microsoft.com/en-us/library/hh213417.aspx#AGlisteners
I want that my app will read from both slaves servers (for example SQL2 and SQL3 in case that they are the slaves and SQL1 is the master)
这是不可能的,除非你在 SQL2016..
SQL Server 2104 and SQL 2012 read-only routing directed traffic to the first available replica in the routing list, unless it was not accessible, and then it would direct the connection to the next replica in the routing list.
When you have multiple secondary replicas available for read, it is not possible to spread the read load across those replicas.
但在 2016 年,您可以在一组 read-only 个副本中配置 load-balancing。
例如,
ALTER AVAILABILITY GROUP ag
MODIFY REPLICA ON N’SQL16N1′
WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=((‘SQL16N3’, ‘SQL16N2’), ‘SQL16N1’)));
在上面的路由列表中
The first incoming read-only connection will be routed to SQL16N3, the second read-only connection will be routed to SQL16N2, the third read-only connection will be routed to SQL16N3, the fourth read-only connection will be routed to SQL16N2, and so on
我在我的一个环境中配置了永远在线。
SQL1 = Primary
SQL2 = Slave1 (readonly)
SQL3 = Slave2 (readonly)
我的问题:
我希望我的应用程序将从两个从服务器读取数据(例如 SQL2 和 SQL3,如果它们是从服务器而 SQL1 是主服务器)。
是否可行,如果可行,我是怎么做到的
我已经配置了路由表,例如:
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL1' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL1.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL2' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL2.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL3' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://SQL3.aws.ir:1433'));
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL1' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL2',N'SQL3')))
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL2' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL1',N'SQL3')))
GO
ALTER AVAILABILITY GROUP [AG1]
MODIFY REPLICA ON N'SQL3' WITH
(PRIMARY_ROLE(READ_ONLY_ROUTING_LIST = (N'SQL1',N'SQL2')))
GO
10倍
您需要创建一个侦听器。它是一个虚拟网络名称,客户端可以连接到该名称以访问 Always On 可用性组的主要或次要副本中的数据库。
在此处阅读有关 AG 的更多信息 https://msdn.microsoft.com/en-us/library/hh213417.aspx#AGlisteners
I want that my app will read from both slaves servers (for example SQL2 and SQL3 in case that they are the slaves and SQL1 is the master)
这是不可能的,除非你在 SQL2016..
SQL Server 2104 and SQL 2012 read-only routing directed traffic to the first available replica in the routing list, unless it was not accessible, and then it would direct the connection to the next replica in the routing list.
When you have multiple secondary replicas available for read, it is not possible to spread the read load across those replicas.
但在 2016 年,您可以在一组 read-only 个副本中配置 load-balancing。
例如,
ALTER AVAILABILITY GROUP ag
MODIFY REPLICA ON N’SQL16N1′
WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=((‘SQL16N3’, ‘SQL16N2’), ‘SQL16N1’)));
在上面的路由列表中
The first incoming read-only connection will be routed to SQL16N3, the second read-only connection will be routed to SQL16N2, the third read-only connection will be routed to SQL16N3, the fourth read-only connection will be routed to SQL16N2, and so on