刪除外部表及外部服務器
-- 刪除外部表
drop foreign table tablename;
-- 刪除用戶映射
drop user mapping for username server servername_fdw;
-- 刪除外部服務器
drop server servername_fdw;
創(chuàng)建外部服務器
create server servername_fdw
foreign data wrapper postgres_fdw options (host 'localhost'
, port 'portnum'
, dbname 'db_name'
)
;
創(chuàng)建用戶映射
create user mapping for local_user
server servername_fdw options (user '遠程服務器用戶名'
, password '遠程服務器用戶密碼'
);
創(chuàng)建外部表
create foreign table table_name (
id bigint options (column_name 'id') not null,
field1 integer options (column_name 'field1') not null,
field2 varchar(100) options (column_name 'field2'),
field3 varchar(100) options (column_name 'field3')
)
server servername_fdw
options (schema_name '外部服務器上schema', table_name '外部表名');