Overview
Materialize can ingest data from SQL Server databases using Change Data Capture (CDC). This allows you to replicate tables from SQL Server into Materialize in real-time, capturing all inserts, updates, and deletes.Materialize supports SQL Server 2016 and later versions. SQL Server CDC must be enabled on the source database.
Prerequisites
Before connecting SQL Server to Materialize, you need to:- Enable Change Data Capture (CDC) on your SQL Server database
- Enable SNAPSHOT isolation for consistent reads during initial synchronization
- Create a dedicated user with appropriate permissions
- Configure network access to allow Materialize to connect
Enable CDC on SQL Server
Create a Replication User
Create a dedicated SQL Server user for Materialize:Network Security
- AWS PrivateLink
- SSH Tunnel
- IP Allowlist
For SQL Server on AWS RDS:
- Create a VPC endpoint service for your RDS instance
- Configure Materialize connection with the PrivateLink endpoint
- Update RDS security groups to allow traffic from Materialize
Creating a Connection
Create a connection to your SQL Server database:Connection Options
The SQL Server hostname or IP address
The SQL Server port number
The database name to connect to
The username for authentication
The password, stored as a secret
Optional SSH tunnel connection for secure access
Creating a Source
Replicate All Tables
Ingest all tables with CDC enabled in your SQL Server database:Replicate Specific Tables
Replicate only specific tables:Handle Schema Collisions
If you have tables with the same name in different schemas, use aliases:Viewing Subsources
After creating a source, view the created subsources:Monitoring Ingestion Progress
Monitor replication progress using the progress subsource:lsn (Log Sequence Number) indicates how far replication has progressed. This value should increase as new changes are captured.
Check Replication Lag
Query the system catalog to monitor replication health:Schema Changes
Compatible Changes
Materialize automatically handles these schema changes:- Adding new columns (nullable or with defaults)
- Adding new tables with CDC enabled
- Changing column data types (compatible changes)
Incompatible Changes
These changes require recreating the source:- Dropping columns
- Renaming columns
- Changing column types (incompatible changes)
- Dropping tables
Troubleshooting
CDC Not Enabled
Error:Change Data Capture is not enabled on database 'YourDatabase'
Solution: Enable CDC on the database and tables:
Permission Denied
Error:The user does not have permission to read CDC tables
Solution: Grant the necessary permissions:
Connection Timeout
Error:Connection timeout while connecting to SQL Server
Solution:
- Verify network connectivity
- Check firewall rules
- Ensure SQL Server is accepting TCP/IP connections
High Replication Lag
If replication is lagging behind:- Check SQL Server CDC cleanup: Ensure CDC cleanup isn’t too aggressive
- Verify cluster size: Consider scaling up your Materialize cluster
- Monitor SQL Server load: High load can slow CDC processing
Best Practices
Use Dedicated Cluster
Create a dedicated cluster for SQL Server ingestion to isolate resource usage
Monitor CDC Cleanup
Configure CDC cleanup retention to balance storage and recovery needs
Enable for Key Tables First
Start with critical tables, then expand to additional tables
Test Schema Changes
Test schema change handling in a non-production environment
Related Resources
CREATE SOURCE: SQL Server
SQL syntax reference
Network Security
Configure secure connections
Monitoring Sources
Monitor source health and performance
SQL Server CDC Documentation
Microsoft’s CDC documentation