Replication, Change Tracking, Change Data Capture, and AlwaysOn Availability Groups
Replication, Change Tracking, Change Data Capture, and AlwaysOn Availability Groups
SQL Server Replication, change data capture (CDC), and change tracking (CT) are supported on
AlwaysOn Availability Groups. AlwaysOn Availability Groups helps provide high availability and
additional database recovery capabilities.
In this Topic:
Overview of Replication on AlwaysOn Availability Groups
o Publisher Redirection
o Changes to Replication Agents to Support AlwaysOn Availability Groups
o Stored Procedures Supporting AlwaysOn
o Change Data Capture
o Change Tracking
Prerequisites, Restrictions, and Considerations for Using Replication with AlwaysOn Availability
Groups
Related Tasks
Note
You should create the jobs at all of the possible failover targets before failover, and mark them as
disabled until the availability replica at a host becomes the new primary replica. The CDC jobs running
at the old primary database should be also disabled when the local database becomes a secondary
database. To disable and enable jobs, use the @enabled option of sp_update_job (Transact-SQL). For
more information about creating CDC jobs, see sys.sp_cdc_add_job (Transact-SQL).
Adding CDC Roles to an AlwaysOn Primary Database Replica
When a table is enabled for CDC, it is possible to associate a database role with the capture instance.
If a role is specified, the user wishing to use the CDC table-valued functions to access changes for the
table must not only have select access to the tracked table columns, but must also be a member of
the named role. If the specified role does not already exist, the role will be created. When database
roles are automatically added to an AlwaysOn primary database, the roles are also propagated to the
secondary databases of the availability group.
Client Applications Accessing CDC Change Data and Always On
Client applications that use the table-valued functions (TVFs) or linked servers to access change table
data also need the ability to locate an appropriate CDC host after failover. The availability group
listener name is the mechanism provided by AlwaysOn Availability Groups to transparently allow a
connection to be retargeted to a different host. Once an availability group listener name is associated
with an availability group, it is available to be used in TCP connection strings. Two different
connection scenarios are supported through the availability group listener name.
o One insures that connection requests are always directed to the current primary replica.
o One insures that connection requests are directed to a read-only secondary replica.
If used to locate a read-only secondary replica, a read-only routing list must also be defined for the
availability group. For more information about routing access to readable secondaries, see Availability
Group Listeners, Client Connectivity, and Application Failover (SQL Server).
Note
There is some propagation delay associated with the creation of an availability group listener name
and its use by client applications to access an availability group database replica.
Use the following query to determine whether an availability group listener name has been defined
for the availability group hosting a CDC database. The query will return the availability group listener
name if one has been created.
Copy
SELECT dns_name
FROM sys.availability_group_listeners AS l
INNER JOIN sys.availability_databases_cluster AS d
ON l.group_id = d.group_id
WHERE d.database_name = N'MyCDCDB';
P2P No No No
1 Does not include support for bi-directional and reciprocal transactional replication.
2 Failover to the replica database is a manual procedure. Automatic failover is not provided.
3 The Distributor database is not supported for use with AlwaysOn Availability Groups or database
mirroring.
(top)
Considerations
The distribution database is not supported for use with AlwaysOn Availability Groups or
database mirroring. Replication configuration is coupled to the SQL Server instance where the
Distributor is configured; therefore the distribution database cannot be mirrored or replicated. To
provide high availability for the Distributor, use a SQL Server failover cluster. For more information,
see AlwaysOn Failover Cluster Instances (SQL Server).
Subscriber failover to a secondary database, while supported, is a relatively complex manual
procedure. The procedure is essentially identical to the method used to fail over a mirrored subscriber
database. Subscribers must be running SQL Server 2012 or later to participate in an availability group.
Metadata and objects that exist outside the database are not propagated to the secondary
replicas, including logins, jobs, linked servers. If you require the metadata and objects at the new
primary database after failover, you must copy them manually. For more information, see
Management of Logins and Jobs for the Databases of an Availability Group (SQL Server).
https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2012/hh403414(v=sql.110)