You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 3. Enable CDC for the tables you want to capture
75
92
76
-
1. In the template, replace the table name in the USE statement with the name of
77
-
the table you want to capture. For example, if your table was called `MyTable`
78
-
then the template would look like the following:
93
+
1. You must also enable CDC on the tables you want Debezium to capture using the
94
+
following commands (again, you need administrator privileges for this):
79
95
80
96
```sql
81
97
USE MyDB
@@ -85,38 +101,34 @@ following steps (again, you need administrator privileges for this):
85
101
@source_schema = N'dbo',
86
102
@source_name = N'MyTable',
87
103
@role_name = N'MyRole',
88
-
@filegroup_name = N'MyDB_CT',
89
104
@supports_net_changes = 0
90
105
GO
91
106
```
107
+
108
+
Repeat this for every table you want to capture.
109
+
110
+
{{< note >}}The value for `@role_name` can’t be a fixed database role, such as`db_datareader`.
111
+
Specifying a new name will create a corresponding database role that has full access to the
112
+
captured change data.
113
+
{{</note >}}
92
114
93
-
1. Run the stored procedure `sys.sp_cdc_enable_table` to enable CDC for
94
-
the table.
115
+
1. Add the Debezium user to the CDC role:
95
116
96
-
1. Repeat steps 1 to 3 for every table you want to capture.
117
+
```sql
118
+
USE MyDB
119
+
GO
120
+
EXEC sp_addrolemember N'MyRole', N'MyUser'
121
+
GO
122
+
```
97
123
98
-
## 3. Check that you have access to the CDC table
124
+
## 4. Check that you have access to the CDC table
99
125
100
126
You can use another stored procedure `sys.sp_cdc_help_change_data_capture`
101
127
to query the CDC information for the database andcheck you have enabled
102
-
it correctly. Before doing this, check that:
103
-
104
-
* You have `SELECT` permission on all of the captured columns of the capture instance.
105
-
If you are a member of the `db_owner` database role then you can view information for
106
-
all of the defined capture instances.
107
-
* You are a member of any gating roles that are defined for the table that the query includes.
108
-
109
-
Follow the steps below to run `sys.sp_cdc_help_change_data_capture`:
110
-
111
-
1. From the **View** menu in SQL Server Management Studio, click **Object Explorer**.
112
-
113
-
1. From the Object Explorer, expand **Databases**, and then expand your database
114
-
object, for example, `MyDB`.
115
-
116
-
1. Expand **Programmability > Stored Procedures > System Stored Procedures**.
128
+
it correctly. To do this, connect as the Debezium user you created previously (`MyUser`).
117
129
118
130
1. Run the `sys.sp_cdc_help_change_data_capture` stored procedure to query
119
-
the table. For example, if your database was called `MyDB` then you would
131
+
the CDC configuration. For example, if your database was called `MyDB` then you would
120
132
run the following:
121
133
122
134
```sql
@@ -131,14 +143,31 @@ Follow the steps below to run `sys.sp_cdc_help_change_data_capture`:
131
143
access. If the result is empty then you should check that you have privileges
132
144
to access both the capture instance and the CDC tables.
133
145
134
-
## SQL Server on Azure
146
+
### Troubleshooting
135
147
136
-
You can also use the Debezium SQL Server connector with SQL Server on Azure.
137
-
See Microsoft's guide to
138
-
[configuring SQL Server on Azure for CDC with Debezium](https://learn.microsoft.com/en-us/samples/azure-samples/azure-sql-db-change-stream-debezium/azure-sql%2D%2Dsql-server-change-stream-with-debezium/)
139
-
for more information.
148
+
If no CDC is happening then it might mean that SQL Server Agent is down. You can check for this using the SQL query shown below:
149
+
150
+
```sql
151
+
IF EXISTS (SELECT 1
152
+
FROM master.dbo.sysprocesses
153
+
WHERE program_name = N'SQLAgent - Generic Refresher')
154
+
BEGIN
155
+
SELECT @@SERVERNAME AS 'InstanceName', 1 AS 'SQLServerAgentRunning'
156
+
END
157
+
ELSE
158
+
BEGIN
159
+
SELECT @@SERVERNAME AS 'InstanceName', 0 AS 'SQLServerAgentRunning'
160
+
END
161
+
```
162
+
163
+
If the query returns a result of 0, you need to need to start SQL Server Agent using the following commands:
140
164
141
-
### SQL Server capture job agent configuration parameters
## SQL Server capture job agent configuration parameters
142
171
143
172
In SQL Server, the parameters that control the behavior of the capture job agent
144
173
are defined in the SQL Server table `msdb.dbo.cdc_jobs`. If you experience performance
@@ -169,6 +198,13 @@ of the Debezium SQL Server connector:
169
198
170
199
See the SQL Server documentation for more information about capture agent parameters.
171
200
201
+
## SQL Server on Azure
202
+
203
+
You can also use the Debezium SQL Server connector with SQL Server on Azure.
204
+
See Microsoft's guide to
205
+
[configuring SQL Server on Azure for CDC with Debezium](https://learn.microsoft.com/en-us/samples/azure-samples/azure-sql-db-change-stream-debezium/azure-sql%2D%2Dsql-server-change-stream-with-debezium/)
206
+
for more information.
207
+
172
208
## Handling changes to the schema
173
209
174
210
RDI can't adapt automatically when you change the schema of a CDC table in SQL Server. For example,
@@ -186,19 +222,28 @@ documentation for further details.
186
222
187
223
1. Create a new capture table for the updated source table by running the `sys.sp_cdc_enable_table` stored
188
224
procedure with a new, unique value for the parameter `@capture_instance`. For example, if the old value
189
-
was `dbo_customers`, you could replace it with `dbo_customers_v2`:
225
+
was `dbo_MyTable`, you could replace it with `dbo_MyTable_v2` (you can see the existing values by running
0 commit comments