Real-time replication from SQL Server with change tracking #
For real-time replicaiton from SQL Server, you can choose SQL Server Change Tracking as a CDC Extractor. Follow these steps to set up real-time replication using change tracking.
I. Prerequisites #
Required Permissions #
To allow replication, you need to first verify that the necessary permissions are in place on source SQL Server. For more information, see SQL Server User Permissions.
Primary keys on tables #
For full mode replication with change tracking, make sure that all the tables that you need to replicate have primary keys.
II. Set up connection configuration #
Specify the connection details of your SQL Server instance to Replicant in one of the following ways:
Use a connection configuration file #
The connection configuration fild holds the connection details and login credentials.
You can find a sample connection configuration file
sqlserver.yaml in the
$REPLICANT_HOME/conf/conn directory. The following configuration parameters are available:
The connection type representing the database. In this case, it’s
The hostname of your SQL Server system.
The port number to connect to the
The username credential to access the SQL Server system.
The password associated with
The authentication protocol for the connection. The following protocols are supported:
Default authentication protocol is always
NATIVE if you don’t explicitly set the
In case of
NLTM protocol, provide the
DOMAIN\USER format—for example,
The CDC Extractor to use for real-time replication.
To use SQL Server Change Tracking, follow these steps:
- Follow the instructions in Enable change tracking.
Optional parameter. If you’re hosting SQL Server on Azure, you must set this parameter to
The maximum number of connections Replicant uses to load data into the SQL Server system.
The following is a sample connection configuration:
Use a secrets management service #
You can store your connection credentials in a secrets management service and tell Replicant to retrieve the credentials. For more information, see Secrets management.
Use KeyStore for credentials #
Replicant supports consuming login credentials from a credentials store. Instead of specifying username and password in plain text, you can keep them in a KeyStore and provide the KeyStore details in the connection configuration file like below:
Replace the following:
PATH_TO_KEYSTORE_FILE: The path to your KeyStore file.
PREFIX_OF_THE_KEYSTORE_ENTRY: The prefix of your KeyStore entries. You can create entries in the credential store using a prefix that preceeds each credential alias. For example, you can create KeyStore entries with aliases
sqlserver_password. You can then set
KEYSTORE_PASSWORD: The KeyStore password. This parameter is optional. If you don’t want to specify the KeyStore password here, then you must use the UUID from your license file as the KeyStore password. Remember to keep your license file somewhere safe in order to keep the KeyStore password secure.
III. Create the heartbeat table #
full mode replication, you need to create a heartbeat table. For example:
CREATE TABLE "tpcc"."dbo"."replicate_io_cdc_heartbeat"("timestamp" BIGINT NOT NULL, PRIMARY KEY("timestamp"))
IV. Set up Extractor configuration #
To configure real-time replication according to your requirements, specify your configuration in the Extractor configuration file. You can find a sample
sqlserver.yaml in the
All configuration parameters for
realtime mode live under the
realtime section. The following is a sample configuration:
For more information about the configuration parameters in
realtime mode, see Realtime Mode.
Enable change tracking #
To use change tracking, you must enable change tracking in all databases and tables:
Enable change tracking in database:
ALTER DATABASE database_name SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)
database_namewith the name of the database you want to enable change tracking on.
Enable change tracking on table:
ALTER TABLE table_name ENABLE CHANGE_TRACKING
table_namewith the name of the table you want to enable change tracking on.