10-configure-sql-server.td 1.9 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. #
  10. # It seems that there is a race condition on SQL Server startup that does not allow CDC to be enabled immediately. The following error is returned instead:
  11. # > 'Could not update the metadata that indicates database test is enabled for Change Data Capture.
  12. # > The failure occurred when executing the command 'sp_addrolemember 'db_owner', 'cdc''.
  13. # > The error returned was 1205: 'Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim.
  14. # > Rerun the transaction.'. Use the action and error to determine the cause of the failure and resubmit the request.'
  15. # > on server 67f36c260951 executing sys.sp_cdc_enable_db_internal on line 205 (code: 22830, state: 1, class: 16)
  16. #
  17. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration="10s"
  18. $ sql-server-connect name=sql-server
  19. server=tcp:sql-server,1433;IntegratedSecurity=true;TrustServerCertificate=true;User ID=sa;Password=${arg.sa-password}
  20. $ sql-server-execute name=sql-server
  21. DROP DATABASE IF EXISTS test;
  22. CREATE DATABASE test;
  23. USE test;
  24. EXEC sys.sp_cdc_enable_db;
  25. # I could not get the Debezium signal mechanism to work -- Debezium throws a NullPointerException
  26. # Therefore, we are forced to populate all tables first as we can not add new tables to the replication stream post-factum
  27. # CREATE TABLE debezium_signal (id VARCHAR(42) PRIMARY KEY, type VARCHAR(32) NOT NULL, data VARCHAR(2048) NULL);
  28. # EXEC sys.sp_cdc_enable_table @source_schema = 'dbo', @source_name = 'debezium_signal', @role_name = 'SA', @supports_net_changes = 0