> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> PostgreSQL 테이블의 초기 데이터 덤프를 사용해 ClickHouse 테이블을 생성하고 복제 프로세스를 시작합니다.

# MaterializedPostgreSQL 테이블 엔진

export const CloudNotSupportedBadge = () => {
  return <div className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            Not supported in ClickHouse Cloud
        </div>;
};

export const ExperimentalBadge = () => {
  return <div className="experimentalBadge">
            <div className="experimentalIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.25" d="M5.5 2H10.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M9.50015 2V6.19625L13.4283 12.7425C13.4738 12.8183 13.4985 12.9049 13.4996 12.9934C13.5008 13.0818 13.4785 13.169 13.435 13.246C13.3914 13.323 13.3283 13.3871 13.2519 13.4317C13.1755 13.4764 13.0886 13.4999 13.0002 13.5H3.00015C2.91164 13.5 2.8247 13.4766 2.74822 13.432C2.67174 13.3874 2.60847 13.3233 2.56487 13.2463C2.52126 13.1693 2.49889 13.082 2.50004 12.9935C2.50119 12.905 2.52582 12.8184 2.5714 12.7425L6.50015 6.19625V2" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M4.47656 9.56754C5.30344 9.41254 6.47656 9.47942 7.99969 10.25C10.0153 11.2707 11.4216 11.0569 12.2184 10.7282" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            Experimental feature. <u><a href="/docs/beta-and-experimental-features#experimental-features">Learn more.</a></u>
        </div>;
};

<Note>
  ClickHouse Cloud 사용자에게는 PostgreSQL을 ClickHouse로 복제할 때 [ClickPipes](/ko/integrations/clickpipes/home)를 사용할 것을 권장합니다. ClickPipes는 PostgreSQL용 고성능 Change Data Capture (CDC)를 네이티브로 지원합니다.
</Note>

PostgreSQL 테이블의 초기 데이터 덤프를 사용해 ClickHouse 테이블을 생성하고 복제 프로세스를 시작합니다. 즉, 원격 PostgreSQL 데이터베이스의 PostgreSQL 테이블에서 새 변경 사항이 발생할 때마다 이를 적용하는 백그라운드 작업을 실행합니다.

<Note>
  이 테이블 엔진은 실험적 기능입니다. 사용하려면 설정 파일에서 또는 `SET` 명령을 사용해 `allow_experimental_materialized_postgresql_table`을 1로 설정하십시오:

  ```sql theme={null}
  SET allow_experimental_materialized_postgresql_table=1
  ```
</Note>

둘 이상의 테이블이 필요한 경우에는 테이블 엔진 대신 [MaterializedPostgreSQL](/ko/reference/engines/database-engines/materialized-postgresql) 데이터베이스 엔진을 사용하고, 복제할 테이블을 지정하는 `materialized_postgresql_tables_list` 설정을 사용할 것을 강력히 권장합니다(데이터베이스 `schema`도 추가할 수 있게 될 예정입니다). 이 방식이 CPU 사용량, 연결 수, 원격 PostgreSQL 데이터베이스 내부의 replication slot 수 측면에서 훨씬 더 효율적입니다.

<div id="creating-a-table">
  ## 테이블 생성
</div>

```sql theme={null}
CREATE TABLE postgresql_db.postgresql_replica (key UInt64, value UInt64)
ENGINE = MaterializedPostgreSQL('postgres1:5432', 'postgres_database', 'postgresql_table', 'postgres_user', 'postgres_password')
PRIMARY KEY key;
```

**엔진 매개변수**

* `host:port` — PostgreSQL 서버 주소.
* `database` — 원격 데이터베이스 이름.
* `table` — 원격 테이블 이름.
* `user` — PostgreSQL 사용자 이름.
* `password` — 사용자 비밀번호.

<div id="requirements">
  ## 요구 사항
</div>

1. PostgreSQL 구성 파일에서 [wal\_level](https://www.postgresql.org/docs/current/runtime-config-wal.html) 설정 값은 `logical`이어야 하며, `max_replication_slots` 매개변수 값은 최소 `2` 이상이어야 합니다.

2. `MaterializedPostgreSQL` 엔진을 사용하는 테이블에는 PostgreSQL 테이블의 replica identity 인덱스(기본값: 기본 키(primary key))와 동일한 기본 키(primary key)가 있어야 합니다([replica identity 인덱스에 대한 자세한 내용](/ko/reference/engines/database-engines/materialized-postgresql#requirements) 참조).

3. [Atomic](https://en.wikipedia.org/wiki/Atomicity_\(database_systems\)) 데이터베이스만 사용할 수 있습니다.

4. `MaterializedPostgreSQL` 테이블 엔진은 구현에 PostgreSQL 함수 [pg\_replication\_slot\_advance](https://pgpedia.info/p/pg_replication_slot_advance.html)가 필요하므로 PostgreSQL 버전 11 이상에서만 작동합니다.

<div id="virtual-columns">
  ## 가상 컬럼
</div>

* `_version` — 트랜잭션 카운터입니다. 유형: [UInt64](/ko/reference/data-types/int-uint).

* `_sign` — 삭제 표시입니다. 유형: [Int8](/ko/reference/data-types/int-uint). 가능한 값:
  * `1` — 행이 삭제되지 않음,
  * `-1` — 행이 삭제됨.

이 컬럼들은 테이블 생성 시 추가할 필요가 없습니다. `SELECT` 쿼리에서 항상 사용할 수 있습니다.
`_version` 컬럼은 `WAL`의 `LSN` 위치와 같으므로, 복제가 얼마나 최신 상태인지 확인하는 데 사용할 수 있습니다.

```sql theme={null}
CREATE TABLE postgresql_db.postgresql_replica (key UInt64, value UInt64)
ENGINE = MaterializedPostgreSQL('postgres1:5432', 'postgres_database', 'postgresql_replica', 'postgres_user', 'postgres_password')
PRIMARY KEY key;

SELECT key, value, _version FROM postgresql_db.postgresql_replica;
```

<Note>
  [**TOAST**](https://www.postgresql.org/docs/9.5/storage-toast.html) 값의 복제는 지원되지 않습니다. 대신 해당 데이터 타입의 기본값이 사용됩니다.
</Note>
