This page describes how to configure change data capture (CDC) to stream data from an Amazon RDS SQL Server database to a supported destination, such as BigQuery or Cloud Storage.
Enable change data capture (CDC) for your source database. To enable CDC for your source database, connect to the database and run the following command at a SQL prompt, in a terminal, or using the Amazon RDS dashboard:
EXEC msdb.dbo.rds_cdc_enable_db 'DATABASE_NAME'Replace
DATABASE_NAMEwith the name of your source database.Enable CDC on each table for which you need to capture changes:
USE [DATABASE_NAME] EXEC sys.sp_cdc_enable_table @source_schema = N'SCHEMA_NAME', @source_name = N'TABLE_NAME', @role_name = NULL GOReplace the following:
DATABASE_NAME: the name of your source databaseSCHEMA_NAME: the name of the schema to which the tables belongTABLE_NAME: the name of the table for which you want to enable CDC
Start the SQL Server Agent and make sure it's running at all times. If the SQL Server Agent remains down for an extended period, the logs might get truncated, leading to a permanent loss of the change data that wasn't read by Datastream.
For information about running the SQL Server Agent, see Start, stop, or restart an instance of the SQL Server Agent.
Enable snapshot isolation.
When you backfill data from your SQL Server database, it's important to ensure consistent snapshots. If you don't apply the settings described in this section, changes made to the database during the backfill process might lead to duplicates or incorrect results. Applying snapshot isolation settings is required if your stream includes tables without primary keys.
Enabling snapshot isolation creates a temporary view of your database at the start of the backfill process. This ensures that the data being copied remains consistent, even if other users are making changes to the live tables at the same time. Enabling snapshot isolation might have a slight performance impact, but it's essential for reliable data extraction.
To enable snapshot isolation:
- Connect to your database using a SQL Server client.
- Run the following command:
ALTER DATABASE DATABASE_NAME SET ALLOW_SNAPSHOT_ISOLATION ON;Replace DATABASE_NAME with the name of you database.
Create a Datastream user:
Connect to the source database and enter the following command:
USE DATABASE_NAME;Create a login to use while setting up the connection profile in Datastream.
CREATE LOGIN YOUR_LOGIN WITH PASSWORD = 'PASSWORD';