Home  >  Article  >  Database  >  配置postgres9.3间的fdw实现不同postgres数据库间的互访问

配置postgres9.3间的fdw实现不同postgres数据库间的互访问

WBOY
WBOYOriginal
2016-06-07 15:54:081395browse

下面是安装、配置、使用fdw实现postgres数据库间互访问的方法,转载注明出处: 1、源码安装fdw支持(要求数据库源码安装) cd /usr/local/postgresql-9.3.2/contrib/postgres_fdw make su make install 2、创建fdw extension(以超级用户登录数据库) \c postg

下面是安装、配置、使用fdw实现postgres数据库间互访问的方法,转载注明出处:

1、源码安装fdw支持(要求数据库源码安装)

cd /usr/local/postgresql-9.3.2/contrib/postgres_fdw
make
su
make install
2、创建fdw extension(以超级用户登录数据库)
\c postgres postgres
create extension postgres_fdw;


3、授权(将模块使用权授予用户test)
GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw to test;


4、创建服务器(以普通用户登录数据库,创建server,连接目标数据库地址:192.168.109.10,数据库:d_test,端口:1921)
\c d_test test
create server srv_test foreign data wrapper postgres_fdw options (host '192.168.109.10',dbname 'd_test',port '1921');


5、创建用户映射(将远端数据库用户test及密码映射给创建的server)
create user mapping FOR test server srv_test options (user 'test',password 'test');


6、创建远程表(创建当地表,指向远程数据库,可以指定远端表的schema:test1)
create foreign table l_t3(c1 int,c2 varchar(10)) server srv_test options (schema_name 'test1',table_name 't3');

7、测试
select * from l_t3;
insert into l_t3 values(2.2222,2);


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn