BigQuery에 기존 테이블이 있고 변경 데이터 캡처(CDC)를 사용하여 동일한 BigQuery 테이블에 데이터를 복제해야 합니다.
사용자는 소요 시간이나 제품 제한사항으로 인해 Datastream 백필 기능을 사용하지 않고 기존 BigQuery 테이블에 데이터를 복사해야 합니다.
문제
BigQuery Storage Write API를 사용하여 채워진 BigQuery 테이블은 일반 데이터 조작 언어(DML) 작업을 허용하지 않습니다. 즉, CDC 스트림이 BigQuery 테이블에 쓰기를 시작하면 해당 테이블에 미리 채워지지 않은 이전 데이터를 추가할 방법이 없습니다.
다음 상황을 살펴보세요.
TIMESTAMP 1: 테이블 복사 작업이 시작됩니다.
TIMESTAMP 2: 테이블이 복사되는 동안 소스의 DML 작업으로 인해 데이터가 변경됩니다(행 추가, 업데이트 또는 삭제).
TIMESTAMP 3: CDC가 시작되고 TIMESTAMP 2에서 발생한 변경사항이 캡처되지 않아 데이터 불일치가 발생합니다.
솔루션
CDC 프로세스는 데이터 무결성을 보장하기 위해 BigQuery 테이블에 복사된 마지막 업데이트 직후에 발생한 소스의 모든 변경사항을 캡처해야 합니다.
다음 솔루션을 사용하면 복사 작업이 BigQuery 테이블에 데이터를 쓰지 못하도록 차단하지 않고도 CDC 프로세스에서 TIMESTAMP 2의 모든 변경사항을 캡처할 수 있습니다.
기본 요건
BigQuery의 대상 테이블에는 Datastream에서 테이블을 만들 때와 정확히 동일한 스키마와 구성이 있어야 합니다. 이를 위해 Datastream BigQuery 마이그레이션 툴킷을 사용할 수 있습니다.
MySQL 및 Oracle 소스의 경우 복사 작업이 시작될 때 사용자가 해당 로그 위치를 식별할 수 있어야 합니다.
테이블 복사 프로세스를 완료하려면 데이터베이스에 충분한 스토리지 및 로그 보관 정책이 있어야 합니다.
MySQL 및 Oracle 소스
진행 중인 CDC 복제에 사용할 스트림을 만들지만 시작하지는 않습니다. 스트림은 생성됨 상태여야 합니다.
테이블 복사 작업을 시작할 준비가 되면 데이터베이스의 현재 로그 위치를 식별합니다.
MySQL의 경우 복제 바이너리 로그 좌표를 가져오는 방법을 알아보려면 MySQL 문서를 참조하세요. 로그 위치를 식별한 후 세션을 닫아 데이터베이스에서 모든 잠금을 해제합니다.
Oracle의 경우 SELECT current_scn FROM V$DATABASE 쿼리를 실행합니다.
소스 데이터베이스의 테이블을 BigQuery에 복사합니다.
복사 작업이 완료되면 스트림 관리 페이지에 설명된 단계에 따라 앞서 식별한 로그 위치에서 스트림을 시작합니다.
[[["이해하기 쉬움","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-04(UTC)"],[[["\u003cp\u003eThis guide provides solutions for replicating data from existing tables into BigQuery using change data capture (CDC) without using Datastream's backfill feature.\u003c/p\u003e\n"],["\u003cp\u003eThe primary challenge addressed is ensuring data integrity when using BigQuery's Storage Write API for CDC, which does not allow adding historical data after the CDC stream begins, leading to potential data discrepancies.\u003c/p\u003e\n"],["\u003cp\u003eTo prevent data loss during table copy operations, the CDC process must capture all changes made to the source table from the moment after the last copied update.\u003c/p\u003e\n"],["\u003cp\u003eThe solution involves identifying the log position in MySQL and Oracle sources at the start of the copy operation, and using this position to start the CDC stream after the copy is completed, or using a replication slot for PostgreSQL sources.\u003c/p\u003e\n"],["\u003cp\u003eTarget tables must be using the correct schema, and the database must have the correct storage and log retention policy.\u003c/p\u003e\n"]]],[],null,["# Use Datastream with an existing BigQuery table\n\nThis page describes best practices for use cases where:\n\n- Users have an existing table in BigQuery and need to replicate their data using change data capture (CDC) into the same BigQuery table.\n- Users need to copy data into an existing BigQuery table without using the Datastream backfill capability, either because of the time it would take or because of product limitations.\n\nProblem\n-------\n\nA BigQuery table that's populated using the [BigQuery Storage\nWrite API](/bigquery/docs/change-data-capture) doesn't allow regular data\nmanipulation language (DML) operations. This means that once a CDC stream\nstarts writing to a BigQuery table, there's no way to add historical data\nthat wasn't already pre-populated in the table.\n\nConsider the following scenario:\n\n1. **TIMESTAMP 1**: the table copy operation is initiated.\n2. **TIMESTAMP 2**: while the table is being copied, DML operations at the source result in changes to the data (rows are added, updated or removed).\n3. **TIMESTAMP 3** : CDC is started, changes that happened in **TIMESTAMP 2** aren't captured, resulting in data discrepancy.\n\nSolution\n--------\n\nTo ensure data integrity, the CDC process must capture all the changes in the\nsource that occurred from the moment immediately following the last update made\nthat was copied into the BigQuery table.\n\nThe solution that follows lets you ensure that the CDC process captures all the\nchanges from **TIMESTAMP 2**, without blocking the copy operation from writing data\ninto the BigQuery table.\n\n### Prerequisites\n\n- The target table in BigQuery must have the exact same schema and configuration as if the table was created by Datastream. You can use the [Datastream BigQuery Migration Toolkit](/datastream/docs/best-practices-migration-toolkit) to accomplish this.\n- For MySQL and Oracle sources, the user must be able to identify the log position at the time when the copy operation is initiated.\n- The database must have sufficient storage and log retention policy to allow the table copy process to complete.\n\n### MySQL and Oracle sources\n\n1. Create, but don't start the stream that you intend to use for the ongoing CDC replication. The stream needs to be in the **CREATED** state.\n2. When you're ready to start the table copy operation, identify the database current log position:\n - For MySQL, see the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/replication-howto-masterstatus.html) to learn how to obtain the replication binary log coordinates. Once you've identified the log position, close the session to release any locks on the database.\n - For Oracle, run the following query: `SELECT current_scn FROM V$DATABASE`\n3. Copy the table from the source database into BigQuery.\n4. Once the copy operation is completed, follow the steps described in the [Manage streams](/datastream/docs/manage-streams#startastreamfromspecific) page to start the stream from the log position that you identified earlier.\n\n### PostgreSQL sources\n\n1. When you're ready to start copying the table, create the replication slot. For more information, see [Configure a source PostgreSQL database](/datastream/docs/configure-your-source-postgresql-database).\n2. Copy the table from the source database into BigQuery.\n3. Once the copy operation is completed, create and start the stream."]]