---
title: "postgres_fdw 사용"
slug: "cloud-db-for-postgresql-postgres-fdw-use"
updated: 2026-07-23T09:02:37Z
published: 2026-07-23T09:02:37Z
canonical: "guide-fin.ncloud-docs.com/cloud-db-for-postgresql-postgres-fdw-use"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://guide-fin.ncloud-docs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# postgres_fdw 사용

Cloud DB for PostgreSQL에서 postgres_fdw extension을 제공하며 아래 사용 가이드를 참고 부탁드립니다.

## console을 통한 extension 설치

Cloud DB For PostgreSQL에서는 superuser 권한을 제공하지 않으므로 console을 통해 superuser 권한이 필요한 extension을 설치할 수 있습니다. 자세한 내용은 아래 가이드를 참고해 주십시오.

- [Extension 설치](/docs/clouddbforpostgresql-extension)

## ACG 설정

DB 서버 간 통신을 위해 ACG 설정이 필요합니다. 자세한 내용은 아래 가이드를 참고해 주십시오.

- [ACG 설정 가이드](/docs/server-acg-vpc)

## DB user 관리 및 접근제어 설정

외부에서 접근하거나 Cloud DB For PostgreSQL 간 원활한 통신을 위해 DB user에 대한 접근 제어 설정이 필요합니다. 자세한 내용은 아래 가이드를 참고해 주십시오.

- [DB User 관리](/docs/clouddbforpostgresql-postgresqlserver)

#### Cloud DB For PostgreSQL 간 통신

![postgres_fdw_extension](https://cdn.document360.io/0406ed95-101f-4cde-8dd8-308d03444a94/Images/Documentation/postgres_fdw_extension_fin.png)

네이버 클라우드 플랫폼 콘솔에서 **Menu** > **All Services** > **Database** > **Cloud DB for PostgreSQL** > **DB Server** 메뉴를 차례대로 클릭한 후 클러스터를 선택해 주십시오. 확인되는 private domain을 nslookup을 수행하거나 사설 ip를 확인합니다.

```
nslookup {private domain}

Non-authoritative answer:
이름:    {private domain}
Address:  xxx.xxx.xxx.xxx
```

확인된 private ip를 이용해 접근제어를 설정합니다.

![postgres_fdw_db_user](https://cdn.document360.io/0406ed95-101f-4cde-8dd8-308d03444a94/Images/Documentation/postgres_fdw_db_user.png)

## postgres_fdw 사용 예시

위의 절차를 모두 진행했다고 가정합니다.

#### source DB 정보 예시

- DB명 : testdb
- DB owner : testappo
- private IP : 10.0.0.6
- DB 포트 : 5432

#### target DB 정보 예시

- DB명 : testdb
- DB owner : testappo

#### source DB에서 스키마 및 데이터 생성

데이터를 조회할 remote 서버로 스키마 및 테이블을 생성한 후, 데이터를 삽입합니다.

```
create schema test;

create table test.test_table(aa int , bb text);

insert into test.test_table(aa,bb) values(1,'a');

insert into test.test_table(aa,bb) values(2,'b');

insert into test.test_table(aa,bb) values(3,'c');

insert into test.test_table(aa,bb) values(4,'d');
```

#### target DB에서 postgres_fdw 설정 및 조회

source DB에 있는 테이블을 조회하기 위해 postgres_fdw 설정을 진행합니다. 아래 예시의 OPTIONS에는 source DB에 대한 정보를 입력합니다.

```
#### 스키마를 생성합니다.
create schema test;

#### postgres_fdw가 설치된 DB에 DB owner로 접속 후 "postgres_server"라는 이름으로 FOREIGN DATA WRAPPER를 생성합니다.
CREATE SERVER postgres_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '10.0.0.6', port '5432', dbname 'testdb');

#### 생성된 FDW 확인
select * from pg_foreign_data_wrapper;

#### db user(role)에 대한 user mapping 설정
-- target DB에 생성된 role : testappo
-- source DB에 생성된 role : testappo
CREATE USER MAPPING FOR testappo SERVER postgres_server OPTIONS (user 'testappo', password '******');

#### user 맵핑 생성확인
select * from pg_user_mappings

#### foreigin tabler 생성
CREATE FOREIGN TABLE test.test_table_fw
(
    aa int,
   bb text
) SERVER postgres_server OPTIONS ( schema_name 'test', table_name 'test_table');

#### foreign table 확인
select * from pg_foreign_table;
SELECT *  FROM information_schema.foreign_tables;

#### 설정한 FDW를 이용해 조회
select * from test.test_table_fw;
```
