--- title: "postgres_fdw を使用する" slug: "clouddbforpostgresql-postgresqlfdw" updated: 2026-10-20T09:03:48Z published: 2026-10-20T09:03:48Z canonical: "guide.ncloud-docs.com/clouddbforpostgresql-postgresqlfdw" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # postgres_fdw を使用する VPC環境で利用できます。 Cloud DB for PostgreSQLで postgres_fdw extensionを提供していますので、以下のご利用ガイドをご参照ください。 ## consoleによる extensionのインストール Cloud DB For PostgreSQLでは superuser権限を提供していないので、consoleを通じて superuser権限が必要な extensionをインストールできます。 詳細は、以下のガイドをご参照ください。 - [Extensionのインストール](https://guide.ncloud-docs.com/docs/ja/clouddbforpostgresql-postgresqlextension#extension-%EC%84%A4%EC%B9%98) ## ACG設定 DBサーバ間の通信のために ACG設定が必要です。 詳細は、以下のガイドをご参照ください。 - [ACG設定ガイド](https://guide.ncloud-docs.com/docs/ja/server-acg-vpc) ## DB user管理およびアクセス制御設定 外部からアクセスしたり、Cloud DB For PostgreSQL間の円滑な通信のために、DB userに対するアクセス制御設定が必要です。 詳細は、以下のガイドをご参照ください。 - [user管理](https://guide.ncloud-docs.com/docs/ja/clouddbforpostgresql-postgresqlserver#db-user-%EA%B4%80%EB%A6%AC) #### Cloud DB For PostgreSQL間の通信 ![postgres_fdw_extension](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/postgres_fdw_extension.png?sv=2026-02-06&spr=https&st=2026-10-26T13%3A31%3A57Z&se=2026-10-26T14%3A31%3A57Z&sr=c&sp=r&sig=ZIqAeARGllt4ooWGIzNF20ft1ioFPCTANsbVzThwYzY%3D) consoleから 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/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/postgres_fdw_db_user.png?sv=2026-02-06&spr=https&st=2026-10-26T13%3A31%3A57Z&se=2026-10-26T14%3A31%3A57Z&sr=c&sp=r&sig=ZIqAeARGllt4ooWGIzNF20ft1ioFPCTANsbVzThwYzY%3D) ## 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サーバにスキーマとテーブルを作成し、データを insertします。 ``` 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; ```