+-
postgresql fdw 安装使用
首页 专栏 postgresql 文章详情
0

postgresql fdw 安装使用

黑暗森林 发布于 4 月 22 日

本地编译安装fdw插件

cd contrib/postgres_fdw USE_PGX=1 make install

本地安装extension

postgres=# create extension if not exists postgres_fdw; CREATE EXTENSION postgres=# \dx List of installed extensions Name | Version | Schema | Description --------------+---------+------------+---------------------------------------------------- plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers (2 rows)

本地配置server

postgres=# create server postgres_fdwtest FOREIGN data wrapper postgres_fdw OPTIONS(host '127.0.0.1', port '5432', dbname 'postgres'); CREATE SERVER postgres=# create user mapping for postgres server postgres_fdwtest options(user 'postgres',password 'postgres'); CREATE USER MAPPING

本地建外表

postgres=# create foreign table pg_fdw_test(id int,name text) server postgres_fdwtest options (table_name 'pg_fdw_test'); CREATE FOREIGN TABLE

远端建表

postgres=# create table pg_fdw_test(id int,name text); CREATE TABLE

本地更新,查询外表

postgres=# insert into pg_fdw_test values(1,'test'); INSERT 0 1 postgres=# select * from pg_fdw_test; id | name ----+------ 1 | test (1 rows)

远端查询

postgres=# select * from pg_fdw_test; id | name ----+------ 1 | test (1 row) postgres=# drop foreign table pg_fdw_test; DROP FOREIGN TABLE drop server postgres_fdwtest CASCADE;
postgresql
阅读 64 发布于 4 月 22 日
举报
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
postgresql内核分析
关注专栏
avatar
黑暗森林

弱小和无知不是生存的障碍,傲慢才是!

1 声望
1 粉丝
关注作者
0 条评论
得票数 最新
提交评论
avatar
黑暗森林

弱小和无知不是生存的障碍,傲慢才是!

1 声望
1 粉丝
关注作者
宣传栏
目录

本地编译安装fdw插件

cd contrib/postgres_fdw USE_PGX=1 make install

本地安装extension

postgres=# create extension if not exists postgres_fdw; CREATE EXTENSION postgres=# \dx List of installed extensions Name | Version | Schema | Description --------------+---------+------------+---------------------------------------------------- plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers (2 rows)

本地配置server

postgres=# create server postgres_fdwtest FOREIGN data wrapper postgres_fdw OPTIONS(host '127.0.0.1', port '5432', dbname 'postgres'); CREATE SERVER postgres=# create user mapping for postgres server postgres_fdwtest options(user 'postgres',password 'postgres'); CREATE USER MAPPING

本地建外表

postgres=# create foreign table pg_fdw_test(id int,name text) server postgres_fdwtest options (table_name 'pg_fdw_test'); CREATE FOREIGN TABLE

远端建表

postgres=# create table pg_fdw_test(id int,name text); CREATE TABLE

本地更新,查询外表

postgres=# insert into pg_fdw_test values(1,'test'); INSERT 0 1 postgres=# select * from pg_fdw_test; id | name ----+------ 1 | test (1 rows)

远端查询

postgres=# select * from pg_fdw_test; id | name ----+------ 1 | test (1 row) postgres=# drop foreign table pg_fdw_test; DROP FOREIGN TABLE drop server postgres_fdwtest CASCADE;