Replicating data from SQL Server to BigQuery

This tutorial shows you how to create and deploy a pipeline that continuously replicates changed data from a Microsoft SQL Server database to a BigQuery table.

Objectives

In this tutorial, you:

  1. Enable Change Data Capture (CDC) in your SQL Server database.
  2. Create and run a Cloud Data Fusion Replication job.
  3. View the results in BigQuery.

Costs

This tutorial uses the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator. New Google Cloud users might be eligible for a free trial.

When Replication runs, you're charged for the Dataproc cluster and you incur processing costs for BigQuery. To optimize these costs, we strongly recommend that you use BigQuery flat rate pricing.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. Enable the Cloud Data Fusion, BigQuery, and Cloud Storage APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  7. Enable the Cloud Data Fusion, BigQuery, and Cloud Storage APIs.

    Enable the APIs

  8. Create a SQL Server instance.
  9. Download the AdventureWorks2017 database and load the data into your SQL Server instance.
  10. Create a private Cloud Data Fusion instance in version 6.3.0 or later. When you set up the instance:
  11. If your SQL Server is always on, see Troubleshooting for additional steps.

If you use an existing instance, or if you don't see Replication in the Cloud Data Fusion menu , see Upgrade to enable Replication.

For more information about networking, see Using HAProxy with Cloud Data Fusionto Navigate Complex Network Topologies.

Enable CDC in your SQL Server database

Enable Change Data Capture (CDC) in your SQL Server instance.

Create and run a Cloud Data Fusion Replication job

Upload the JDBC driver

  1. Download the SQL Server JDBC driver to your local machine.

  2. In the Cloud Data Fusion UI, upload the JDBC driver. Use these values to configure the JDBC driver:

    • In the Name field, enter sqlserver.
    • In the Version field, keep the default.
    • In the Class Name field, enter com.microsoft.sqlserver.jdbc.SQLServerDriver.

Create the pipeline

  1. In the Cloud Data Fusion UI, click Menu > Replication.

  2. On the Create new replication job page, specify a Replication job Name.

  3. Click Next.

  4. Configure the source:

    1. Select Microsoft SQL Server as the source.
    2. For Host, enter the hostname of the SQL Server to read from.
    3. For Port, enter the port to use to connect to the SQL Server: 1433.
    4. For JDBC Plugin Name, select sqlserver (or the name you specified when you configured the JDBC driver).
    5. For Database name, enter AdventureWorks2017.
    6. In the Credentials section, enter your username and password to access the SQL Server.
  5. Click Next.

  6. If the connection is successful, a list of AdventureWorks2017 tables is displayed. For this tutorial, select all of the tables and events, such as Insert, Update, and Delete events.

  7. Click Next.

  8. Configure the target:

    1. Select the BigQuery target.
    2. The Project ID and Service Account Key are automatically detected. Keep the default values.
    3. Optional: In the Advanced section, you can configure the Cloud Storage bucket's name and location, the load interval, the staging table prefix, and the behavior when tables or databases are dropped.
  9. Click Next.

  10. Optional: Configure the advanced properties. For this tutorial, you can accept the default settings.

  11. Click Next.

  12. On the Review assessment page, click View mappings by any of the tables to get an assessment of schema issues, missing features, or connectivity issues that might occur during replication. If any issues occur, they must be resolved before you can proceed. For this tutorial, if any of the tables have issues, go back to the step where you selected tables and select a table or event without issues.

  13. Click Back.

  14. Click Next.

  15. Review the summary Replication job details, and then click Deploy Replication job.

Start the pipeline

From the Replication job details page:

Click Start.

The Replication job transitions from Provisioning to Starting to Running state. In the running state, the Replication job loads an initial snapshot of the table data that you selected (for example, the People table) into BigQuery. In this state, the state of the People table is listed as Snapshotting. After the initial snapshot is loaded into BigQuery, any changes made to the People table are replicated to BigQuery, and the state of the table is listed as Replicating.

Monitor the pipeline

You can start and stop the Replication job, review its configuration and logs, and monitor your Replication job.

You can monitor Replication job activities from the Replication job details page.

  1. From the Replication page, click the desired Replication job Name.

  2. Click Monitoring.

View the results in BigQuery

The Replication job creates a replicated dataset and table in BigQuery, with names inherited from the corresponding SQL Server database and table names.

  1. Open BigQuery in the console.

  2. In the left panel, click the project name to expand a list of datasets.

  3. Select the adventureworks2017 dataset, and then select a table to view.

For more information, see the BigQuery documentation.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.

After you've finished the tutorial, delete the resources you created on Google Cloud.

Delete the VM instance

  1. In the console, go to the VM instances page.

    Go to VM instances

  2. Select the checkbox for the instance that you want to delete.
  3. To delete the instance, click More actions, click Delete, and then follow the instructions.

Delete the Cloud Data Fusion instance

Follow the instructions to delete your Cloud Data Fusion instance.

Delete the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

  1. In the console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next