AlloyDB 기본 인스턴스에 대해 논리적 디코딩을 사용 설정합니다. Google Cloud에서 alloydb.logical_decoding 플래그 값을 ON으로 설정합니다. 데이터베이스 플래그를 업데이트하는 방법에 대한 자세한 내용은 인스턴스의 데이터베이스 플래그 구성을 참조하세요.
동일한 VPC의 모든 VM에서 다음 명령어를 실행하여 TCP 프록시 IP 주소를 사용해 AlloyDB 인스턴스에 연결합니다.
psql-hPROXY_IP\-UDB_USER\-dDB_NAME
다음을 바꿉니다.
PROXY_IP: TCP 프록시의 IP 주소입니다.
DB_USER: AlloyDB 데이터베이스의 사용자 이름입니다.
DB_NAME: AlloyDB 데이터베이스 이름입니다.
다음 명령어를 실행하여 데이터베이스 사용자에게 복제 권한을 부여합니다.
ALTER USER DB_USER WITH REPLICATION;
게시 만들기. 복제할 테이블에 대해서만 게시를 만드는 것이 좋습니다. 이렇게 하면 Datastream이 관련 데이터만 읽을 수 있고 데이터베이스와 Datastream의 부하가 줄어듭니다.
CREATE PUBLICATION PUBLICATION_NAME
FOR TABLE SCHEMA1.TABLE1, SCHEMA2.TABLE2;
다음을 바꿉니다.
PUBLICATION_NAME: 게시의 이름입니다. Datastream 스트림 만들기 마법사에서 스트림을 만들 때 이 이름을 제공해야 합니다.
SCHEMA: 테이블이 포함된 스키마의 이름입니다.
TABLE: 복제할 테이블의 이름입니다.
스키마의 모든 테이블에 대한 게시를 만들 수 있습니다. 이 방식을 사용하면 이후에 만들 테이블을 포함하여 지정된 스키마 목록에 있는 테이블의 변경사항을 복제할 수 있습니다.
CREATE PUBLICATION PUBLICATION_NAME
FOR TABLES IN SCHEMA1, SCHEMA2;
데이터베이스의 모든 테이블에 대한 게시를 만들 수도 있습니다. 이 경우 소스 데이터베이스와 Datastream의 부하가 증가합니다.
CREATE PUBLICATION PUBLICATION_NAME FOR ALL TABLES;
REPLICATION_SLOT_NAME: 복제 슬롯 이름입니다.
Datastream 스트림 만들기 마법사에서 스트림을 만들 때 이 이름을 제공해야 합니다.
Datastream 사용자 만들기
Datastream 사용자를 만들려면 다음 PostgreSQL 명령어를 입력합니다.
CREATE USER USER_NAME WITH REPLICATION LOGIN PASSWORD 'USER_PASSWORD';
다음을 바꿉니다.
USER_NAME: 만들려는 Datastream 사용자의 이름입니다.
USER_PASSWORD: 만들려는 Datastream 사용자의 로그인 비밀번호입니다.
자신이 만든 사용자에게 다음 권한을 부여합니다.
GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_NAME TO USER_NAME;
GRANT USAGE ON SCHEMA SCHEMA_NAME TO USER_NAME;
ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_NAME GRANT SELECT ON TABLES TO USER_NAME;
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-03(UTC)"],[[["\u003cp\u003eThis guide explains how to configure an AlloyDB for PostgreSQL database to work with Datastream, beginning with setting up a TCP proxy for connectivity.\u003c/p\u003e\n"],["\u003cp\u003eTo enable Datastream's connection to the AlloyDB instance, a TCP proxy must be launched in the consumer project using a provided script, replacing placeholders with appropriate values.\u003c/p\u003e\n"],["\u003cp\u003eLogical decoding must be enabled on the AlloyDB primary instance, along with granting replication privileges to a designated database user via the provided command, and creating a publication for tables to be replicated.\u003c/p\u003e\n"],["\u003cp\u003eA dedicated Datastream user must be created with specific privileges, including replication login and select permissions on tables and schemas, using the provided commands.\u003c/p\u003e\n"],["\u003cp\u003eAfter completing the setup, you can use the TCP proxy IP address for the connection profile, and create a stream in the Datastream stream creation wizard using the publication and replication slot names.\u003c/p\u003e\n"]]],[],null,["# Configure an AlloyDB for PostgreSQL database\n\nThe following sections cover how to configure an AlloyDB for PostgreSQL database.\n\nSet up connectivity between Datastream and AlloyDB\n--------------------------------------------------\n\nTo enable Datastream to connect to the AlloyDB instance, you need to set up a TCP proxy in the consumer project. The [TCP proxy image](http://gcr.io/dms-images/tcp-proxy) is publicly available to all customers.\n\n1. Launch the proxy container:\n\n 1. Activate Cloud Shell in the consumer project.\n 2. Run the following script to create the TCP proxy and disable bridge networking to avoid connectivity issues:\n\n gcloud compute instances create-with-container \\\n --zone=\u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n --container-image gcr.io/dms-images/tcp-proxy \\\n --tags=dms-tcp-proxy \\\n --container-env=SOURCE_CONFIG=\u003cvar translate=\"no\"\u003eALLOYDB_IP\u003c/var\u003e:\u003cvar translate=\"no\"\u003eALLOYDB_PORT\u003c/var\u003e \\\n --can-ip-forward \\\n --network=\u003cvar translate=\"no\"\u003eSOURCE_AND_DEST_VPC\u003c/var\u003e \\\n --machine-type=\u003cvar translate=\"no\"\u003eVM_TIER\u003c/var\u003e \\\n --metadata=startup-script='#! /bin/bash\n mkdir -p /etc/docker\n cat \u003c\u003cEOF \u003e /etc/docker/daemon.json\n {\"bridge\":\"none\"}\n EOF\n systemctl restart docker'\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e: The region in which you want to create the TCP proxy.\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: The name of the virtual machine.\n - \u003cvar translate=\"no\"\u003eALLOYDB_IP\u003c/var\u003e: The IP address of the AlloyDB for PostgreSQL instance.\n - \u003cvar translate=\"no\"\u003eALLOYDB_PORT\u003c/var\u003e: The port number of the AlloyDB for PostgreSQL instance.\n - \u003cvar translate=\"no\"\u003eSOURCE_AND_DEST_VPC\u003c/var\u003e: The VPC network to which the source and destination are connected.\n - \u003cvar translate=\"no\"\u003eVM_TIER\u003c/var\u003e: The type of your virtual machine.\n\n An example command with updated parameters: \n\n gcloud compute instances create-with-container \\\n --zone=us-central1-c ds-tcp-proxy \\\n --container-image gcr.io/dms-images/tcp-proxy \\\n --tags=ds-tcp-proxy \\\n --container-env=SOURCE_CONFIG=10.16.0.5:5432 \\\n --can-ip-forward \\\n --network=default \\\n --machine-type=e2-micro\n --metadata=startup-script='#! /bin/bash\n mkdir -p /etc/docker\n cat \u003c\u003cEOF \u003e /etc/docker/daemon.json\n {\"bridge\":\"none\"}\n EOF\n systemctl restart docker'\n\n | You may receive a prompt to authorize Cloud Shell. Click **AUTHORIZE**.\n2. Run the script to print the IP address of the TCP Proxy with the following inputs:\n\n gcloud compute instances describe \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n --format=\"yaml(networkInterfaces[].networkIP)\" \\\n --zone=\u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: The name of your virtual machine.\n - \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e: The region in which you created the TCP proxy.\n\n | Use this IP address in the Datastream [connection profile](/datastream/docs/create-connection-profiles#cp4postgresdb) configuration.\n3. (Optional) Create a firewall rule to limit ingress traffic to the TCP proxy:\n\n gcloud compute firewall-rules create \u003cvar translate=\"no\"\u003eFIREWALL_RULE_NAME\u003c/var\u003e \\\n --direction=INGRESS \\\n --priority=1000 \\\n --target-tags=dms-tcp-proxy \\\n --network=\u003cvar translate=\"no\"\u003eSOURCE_VPC\u003c/var\u003e \\\n --action=ALLOW \\\n --rules=tcp:\u003cvar translate=\"no\"\u003eALLOYDB_PORT\u003c/var\u003e \\\n --source-ranges=\u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eFIREWALL_RULE_NAME\u003c/var\u003e: The name of your firewall rule.\n - \u003cvar translate=\"no\"\u003eSOURCE_VPC\u003c/var\u003e: The VPC network to which your source is connected.\n - \u003cvar translate=\"no\"\u003eALLOYDB_PORT\u003c/var\u003e: The port number of the AlloyDB for PostgreSQL instance.\n - \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e: The IP address range to which you want to limit ingress traffic.\n\n An example command to allow ingress traffic from all IP addresses: \n\n gcloud compute firewall-rules create ds-proxy1 \\\n --direction=INGRESS \\\n --priority=1000 \\\n --target-tags=ds-tcp-proxy \\\n --network=default \\\n --action=ALLOW \\\n --rules=tcp:5432\n\nConfigure AlloyDB for replication\n---------------------------------\n\n1. Enable logical decoding for the AlloyDB primary instance. In Google Cloud, set\n the value for the `alloydb.logical_decoding` flag to **ON** . For information about\n updating the database flags, see [Configure an instance's database flags](/alloydb/docs/instance-configure-database-flags).\n\n | **Note:** Updating the `alloydb.logical_decoding` flag restarts the instance.\n2. Connect to the AlloyDB instance using the TCP proxy IP address by running the\n following command from any VM on the same VPC:\n\n psql -h \u003cvar translate=\"no\"\u003ePROXY_IP\u003c/var\u003e \\\n -U \u003cvar translate=\"no\"\u003eDB_USER\u003c/var\u003e \\\n -d \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROXY_IP\u003c/var\u003e: The IP address of the TCP proxy.\n - \u003cvar translate=\"no\"\u003eDB_USER\u003c/var\u003e: The username for the AlloyDB database.\n - \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e: The AlloyDB database name.\n3. Run the following command to grant replication privileges to your database user:\n\n ```\n ALTER USER DB_USER WITH REPLICATION;\n ```\n4. Create a publication. We recommend that you create a publication only for the\n tables that you want to replicate. This allows Datastream to read-only\n the relevant data, and lowers the load on the database and Datastream:\n\n ```\n CREATE PUBLICATION PUBLICATION_NAME\n FOR TABLE SCHEMA1.TABLE1, SCHEMA2.TABLE2;\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePUBLICATION_NAME\u003c/var\u003e: The name of your publication. You'll need to provide this name when you create a stream in the Datastream stream creation wizard.\n - \u003cvar translate=\"no\"\u003eSCHEMA\u003c/var\u003e: The name of the schema that contains the table.\n - \u003cvar translate=\"no\"\u003eTABLE\u003c/var\u003e: The name of the table that you want to replicate.\n\n You can also create a publication for all tables in your database. Note that\n this approach increases the load on both the source database and Datastream: \n\n ```\n CREATE PUBLICATION PUBLICATION_NAME FOR ALL TABLES;\n ```\n | For PostgreSQL 15 and later, you can create a publication for all tables in a schema. This approach lets you replicate changes for tables in the specified list of schemas, including tables that you create in the future: \n |\n | ```\n | CREATE PUBLICATION PUBLICATION_NAME\n | FOR TABLES IN SCHEMA SCHEMA1, SCHEMA2;\n | ```\n5. Create a replication slot by executing the following command.\n\n ```\n SELECT PG_CREATE_LOGICAL_REPLICATION_SLOT('REPLICATION_SLOT_NAME', 'pgoutput');\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eREPLICATION_SLOT_NAME\u003c/var\u003e: The name of your replication slot. You'll need to provide this name when you create a stream in the Datastream stream creation wizard.\n\nCreate a Datastream user\n------------------------\n\n1. To create a Datastream user, enter the following PostgreSQL command:\n\n ```\n CREATE USER USER_NAME WITH REPLICATION LOGIN PASSWORD 'USER_PASSWORD';\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eUSER_NAME\u003c/var\u003e: The name of the Datastream user that you want to create.\n - \u003cvar translate=\"no\"\u003eUSER_PASSWORD\u003c/var\u003e: The login password for the Datastream user that you want to create.\n2. Grant the following privileges to the user you created:\n\n ```\n GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_NAME TO USER_NAME;\n GRANT USAGE ON SCHEMA SCHEMA_NAME TO USER_NAME;\n ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_NAME GRANT SELECT ON TABLES TO USER_NAME;\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSCHEMA_NAME\u003c/var\u003e: The name of the schema to which you want to grant the privileges.\n - \u003cvar translate=\"no\"\u003eUSER_NAME\u003c/var\u003e: The user to whom you want to grant the privileges.\n\n | The first command might display warnings, however it is safe to ignore them.\n\nWhat's next\n-----------\n\n- Learn more about how Datastream works with [PostgreSQL sources](/datastream/docs/sources-postgresql)."]]