--- title: "Ingest data from AlloyDB" description: "How to stream data from AlloyDB to Materialize" aliases: - /ingest-data/postgres-alloydb/ menu: main: parent: "postgresql" name: "AlloyDB" identifier: "pg-alloydb" --- This page shows you how to stream data from [AlloyDB for PostgreSQL](https://cloud.google.com/alloydb) to Materialize using the [PostgreSQL source](/sql/create-source/postgres/). {{< tip >}} {{< guided-tour-blurb-for-ingest-data >}} {{< /tip >}} ## Before you begin {{% postgres-direct/before-you-begin %}} If you don't already have an AlloyDB instance, creating one involves several steps, including configuring your cluster and setting up network connections. For detailed instructions, refer to the [AlloyDB documentation](https://cloud.google.com/alloydb/docs). ## A. Configure AlloyDB ### 1. Enable logical replication Materialize uses PostgreSQL's [logical replication](https://www.postgresql.org/docs/current/logical-replication.html) protocol to track changes in your database and propagate them to Materialize. To enable logical replication in AlloyDB, see the [AlloyDB documentation](https://cloud.google.com/datastream/docs/configure-your-source-postgresql-database#configure_alloydb_for_replication). ### 2. Create a publication and a replication user {{% postgres-direct/create-a-publication-other %}} ## B. (Optional) Configure network security {{< note >}} If you are prototyping and your AlloyDB instance is publicly accessible, **you can skip this step**. For production scenarios, we recommend configuring one of the network security options below. {{}} To establish authorized and secure connections to an AlloyDB instance, an authentication proxy is necessary. Google Cloud Platform provides [a guide](https://cloud.google.com/alloydb/docs/auth-proxy/connect) to assist you in setting up this proxy and generating a connection string that can be utilized with Materialize. Further down, we will provide you with a tailored approach specific to integrating Materialize. Next, choose the best network configuration for your setup to connect Materialize with AlloyDB: - **Allow Materialize IPs:** If your AlloyDB instance is publicly accessible, configure your firewall to allow connections from Materialize IP addresses. - **Use an SSH tunnel:** For private networks, use an SSH tunnel to connect Materialize to AlloyDB. {{< tabs >}} {{< tab "Allow Materialize IPs">}} 1. In the [Materialize console's SQL Shell](https://console.materialize.com/), or your preferred SQL client connected to Materialize, find the static egress IP addresses for the Materialize region you are running in: ```mzsql SELECT * FROM mz_egress_ips; ``` 1. Update your Google Cloud firewall rules to allow traffic to your AlloyDB auth proxy instance 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 instance 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. 1. [Launch a GCE instance](https://cloud.google.com/compute/docs/instances/create-start-instance) to serve as your SSH bastion host. - Make sure the instance is publicly accessible and in the same VPC as your database. - Add a key pair and note the username. You'll use this username when connecting Materialize to your bastion host. - Make sure the VM has a [static public IP address](https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address). You'll use this IP address when connecting Materialize to your bastion host. 1. Configure the SSH bastion host to allow traffic only from Materialize. 1. In the [Materialize console's SQL Shell](https://console.materialize.com/), or your preferred SQL client connected to Materialize, get the static egress IP addresses for the Materialize region you are running in: ```mzsql SELECT * FROM mz_egress_ips; ``` 1. Update your SSH bastion host's firewall rules to allow traffic from each IP address from the previous step. 1. Update your Google Cloud firewall rules to allow traffic to your AlloyDB auth proxy instance from the SSH bastion host. {{< /tab >}} {{< /tabs >}} ## C. Ingest data in Materialize ### 1. (Optional) Create a cluster {{< note >}} If you are prototyping and already have a cluster to host your PostgreSQL source (e.g. `quickstart`), **you can skip this step**. For production scenarios, we recommend separating your workloads into multiple clusters for [resource isolation](/sql/create-cluster/#resource-isolation). {{< /note >}} {{% postgres-direct/create-a-cluster %}} ### 2. Start ingesting data With the network configured and an ingestion pipeline in place, connect Materialize to your AlloyDB instance and begin the data ingestion process. {{< tabs >}} {{< tab "Allow Materialize IPs">}} {{% postgres-direct/ingesting-data/allow-materialize-ips %}} {{< /tab >}} {{< tab "Use an SSH tunnel">}} {{% postgres-direct/ingesting-data/use-ssh-tunnel %}} {{< /tab >}} {{< /tabs >}} ### 3. Monitor the ingestion status {{% postgres-direct/check-the-ingestion-status %}} ### 4. Right-size the cluster {{% postgres-direct/right-size-the-cluster %}} ## D. Explore your data {{% postgres-direct/next-steps %}} ## Considerations {{< include-md file="shared-content/postgres-considerations.md" >}}