本文主要含有一些AlwaysOn 配置方法及连接。
本想展开详细写一下 无奈隔壁在年会排练节目,那歌唱得我只想赶紧回家!!!!!!!!!!!!!!!
http://www.cnblogs.com/double-K/
------------------------------只读配置---------------
只读访问三点注意:
1.applicationintent = readonly
2.登录选择组中的数据库
3.设置只读路由:
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012_1‘ WITH
(SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL));
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012_1‘ WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N‘TCP://VPC2012_1.vwy.com:1433‘));
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012-2‘ WITH
(SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL));
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012-2‘ WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N‘TCP://VPC2012-2.vwy.com:1433‘));
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012_1‘ WITH
(PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=(‘VPC2012-2‘,‘VPC2012_1‘)));
ALTER AVAILABILITY GROUP [TN]
MODIFY REPLICA ON
N‘VPC2012-2‘ WITH
(PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=(‘VPC2012_1‘,‘VPC2012-2‘)));
---------------always on 与发布订阅 实现故障转移后的发布订阅切换--------------------------------
发布
https://msdn.microsoft.com/zh-CN/library/hh710046(v=sql.120).aspx
图形化:
1.分发服务器中 添加发布服务器(每个always on 节点)
2.主节点配置发布
3.辅助节点配置发布
代码实现:
4.添加链接服务器(always on 节点添加分发服务器)
5.重定向publisher 到VTN (所有节点)
----查看状态
USE distribution;
GO
DECLARE @redirected_publisher sysname;
EXEC sys.sp_validate_replica_hosts_as_publishers
@original_publisher = ‘VPC2012-2‘,
@publisher_db = ‘tt‘,
@redirected_publisher = @redirected_publisher output;
------重定向publisher 到VTN
USE distribution;
GO
EXEC sys.sp_redirect_publisher
@original_publisher = ‘VPC2012-2‘,
@publisher_db = ‘TT‘,
@redirected_publisher = ‘VTN‘;
EXEC sp_addlinkedserver
@server= ‘WIN‘,--被訪問的服務器別名
@srvproduct= ‘‘,
@provider= ‘SQLOLEDB‘,
@datasrc= CQEH\SQL2014‘ --要訪問的服務器 ---多实例需指定实例名称
EXEC sp_addlinkedsrvlogin
‘WIN‘, --被訪問的服務器別名
‘false ‘,
NULL,
‘sa‘, --帳號
‘sa_123456‘ --密碼
订阅
https://msdn.microsoft.com/zh-CN/library/hh882436%28v=sql.120%29.aspx
---------------always on节点添加VTN
EXEC sp_addlinkedserver
@server= ‘VTN‘,--被訪問的服務器別名
@srvproduct= ‘‘,
@provider= ‘SQLOLEDB‘,
@datasrc= ‘VTN‘ --要訪問的服務器 ---多实例需指定实例名称
EXEC sp_addlinkedsrvlogin
‘VTN‘, --被訪問的服務器別名
‘false ‘,
NULL,
‘sa‘, --帳號
‘sa_123456‘ --密碼
-- commands to execute at the publisher, in the publisher database:
use [testDB]
EXEC sp_addsubscription @publication = N‘ppppppppppppppp‘,
@subscriber = N‘VTN‘,
@destination_db = N‘tt‘,
@subscription_type = N‘Push‘,
@sync_type = N‘automatic‘, @article = N‘all‘, @update_mode = N‘read only‘, @subscriber_type = 0;
GO
EXEC sp_addpushsubscription_agent @publication = N‘ppppppppppppppp‘,
@subscriber = N‘VTN‘,
@subscriber_db = N‘tt‘,
@subscriber_login = ‘sa‘,
@subscriber_password = ‘sa_123456‘,
@job_login = NULL, @job_password = null, @subscriber_security_mode = 0; --0 SQL login --1 windows login
-------------------------------------------------alwayson限制--------------------------------
https://msdn.microsoft.com/zh-cn/library/ff878487(v=sql.120).aspx
--------------------------------------------alwayson 备份------------
https://msdn.microsoft.com/zh-cn/library/hh710053(v=sql.120).aspx
辅助节点备份 只能采用copy-only
---1 为可备份 0为不可备份
SELECT [master].sys.fn_hadr_backup_is_preferred_replica(‘nn‘) 测试中2014状态不准
------------------------------server 2012 仲裁------------------
https://technet.microsoft.com/zh-cn/library/jj612870
--------------------------------alwayson节点状态-----------
select * from [master].sys.dm_hadr_availability_replica_states
https://msdn.microsoft.com/zh-cn/library/ff878537(v=sql.120).aspx
role --0 正在解析 1 主副本 2 辅助副本
role_desc --RESOLVINGPRIMARY SECONDARY
operational_state --
0 = 挂起故障转移
1 = 等待批准
2 = 联机
3 = 脱机
4 = 失败
5 = 失败,无仲裁
NULL = 副本不在本地。
operational_state_desc --
PENDING_FAILOVER
PENDING
ONLINE
OFFLINE
FAILED
FAILED_NO_QUORUM
NULL
----------------------------------alwayson迁移---------------------
http://www.cnblogs.com/stswordman/p/3936584.html
---------------------------------alwayson 性能计数器------------
SQLServer:Database Replica
https://msdn.microsoft.com/zh-cn/library/ff878356(v=sql.120).aspx
SQLServer:Availability Replica
https://msdn.microsoft.com/zh-cn/library/ff878472(v=sql.120).aspx