postgresql追加fdwを使用してデータベースを関連付ける


## 1.ターゲット・データベースにextensionを作成する

CREATE EXTENSION "postgres_fdw";

## 2.ターゲットデータベースに現在ログインしているアカウント権限を与えます.例えばpostgresqlでログインしたデータベース
grant usage on foreign data wrapper postgres_fdw to postgres;

## 3. ソース・データベースへの接続(dbname-ソース・データベース)

CREATE SERVER servers
        FOREIGN DATA WRAPPER postgres_fdw
        OPTIONS (host 'x.x.x.x', port '5432', dbname 'postgres');

## 4.現在ログインしているユーザーにソース・データベース関連optionsを作成するのは、システムのバックドアに相当します.
 create user mapping for postgres server servers options(user 'postgres',password '123456');

## 5.ソース・データベースの下でschemaターゲット・データベースの下でschemaをインポート
import foreign schema "public" from server servers into "public";