首先psql使\c进入到你要创建fdw表的数据库
\c wt4_comp;
然后载入插件,使用什么的fdw换对应的'postgres_fdw'值,我这个做的是PostgreSQL的fdw
CREATE EXTENSION postgres_fdw;
创建你的fdw服务链接,其中my_fdw可以自己定义你自己的名称,括号内参数换成你自己的,如果是本机,不能写host和port
create server my_fdw foreign data wrapper postgres_fdw options(host '192.168.1.156', port '5432', dbname 'hitb_prod');
创建你fdw链接用户,my_fdw是你上面定义的名称,括号内参数换成你自己的
create user mapping for postgres server my_fdw options (user 'postgres', password '123456');
创建你的fdw表,my_fdw是你上面定义的名称,record_test4 是你定义的fdw结果表名称,括号里record是你远程数据库的名称
create foreign table record_test4(表定义) server my_fdw options(table_name 'record');
查询试一下
select * from record_test4 limit 100;