title: "Ingest data from self-hosted SQL Server" description: "How to stream data from self-hosted SQL Server database to Materialize" menu: main:
parent: "sql-server"
name: "Self-hosted SQL Server"
identifier: "sql-server-self-hosted"
aliases:
This page shows you how to stream data from a self-hosted SQL Server database to Materialize using the SQL Server Source.
{{< tip >}} {{< guided-tour-blurb-for-ingest-data >}} {{< /tip >}}
{{% sql-server-direct/before-you-begin %}}
{{< note >}}
To configure SQL Server for data ingestion into Materialize, you must be a user with privileges to enable CDC and create/manage login, users, roles, and privileges.
{{</ note >}}
{{% sql-server-direct/ingesting-data/enable-cdc %}}
{{< note >}} If you are prototyping and your SQL Server instance is publicly accessible, you can skip this step. For production scenarios, we recommend configuring one of the network security options below. {{< /note >}}
There are various ways to configure your database's network to allow Materialize to connect:
Allow Materialize IPs: If your database is publicly accessible, you can configure your database's firewall to allow connections from a set of static Materialize IP addresses.
Use an SSH tunnel: If your database is running in a private network, you can use an SSH tunnel to connect Materialize to the database.
Select the option that works best for you.
{{< tabs >}}
{{< tab "Allow Materialize IPs">}}
In the SQL Shell, or your preferred SQL client connected to Materialize, find the static egress IP addresses for the Materialize region you are running in:
SELECT * FROM mz_egress_ips;
Update your database firewall rules to allow traffic from each IP address from the previous step.
{{< /tab >}}
{{< tab "Use an SSH tunnel">}}
To create an SSH tunnel from Materialize to your database, you launch an VM to serve as an SSH bastion host, configure the bastion host to allow traffic only from Materialize, and then configure your database's private network to allow traffic from the bastion host.
Launch a VM to serve as your SSH bastion host.
Configure the SSH bastion host to allow traffic only from Materialize.
In the SQL Shell, or your preferred SQL client connected to Materialize, get the static egress IP addresses for the Materialize region you are running in:
SELECT * FROM mz_egress_ips;
Update your SSH bastion host's firewall rules to allow traffic from each IP address from the previous step.
Update your database firewall rules to allow traffic from the SSH bastion host.
{{< /tab >}}
{{< /tabs >}}
{{< note >}}
If you are prototyping and already have a cluster to host your SQL Server
source (e.g. quickstart
), you can skip this step. For production
scenarios, we recommend separating your workloads into multiple clusters for
resource isolation.
{{< /note >}}
{{% sql-server-direct/create-a-cluster %}}
Now that you've configured your database network, you can connect Materialize to your SQL Server database and start ingesting data. The exact steps depend on your networking configuration, so start by selecting the relevant option.
{{< tabs >}}
{{< tab "Allow Materialize IPs">}} {{% sql-server-direct/ingesting-data/allow-materialize-ips %}} {{< /tab >}}
{{< tab "Use an SSH tunnel">}} {{% sql-server-direct/ingesting-data/use-ssh-tunnel %}} {{< /tab >}}
{{< /tabs >}}
[//]: # "TODO(morsapaes) Replace these Step 6. and 7. with guidance using the new progress metrics in mz_source_statistics + console monitoring, when available(also for PostgreSQL)."
{{% sql-server-direct/right-size-the-cluster %}}
{{% sql-server-direct/next-steps %}}
{{% include-md file="shared-content/sql-server-considerations.md" %}}